Class ProxySettings
- java.lang.Object
-
- NeoVisionaries.WebSockets.ProxySettings
-
public class ProxySettings extends java.lang.Object
Proxy settings.
Read included Apache License 2.0:HERE
AllNeoVisionaries.WebSockets.*
Code Obtained From:GitHub 'NV' (Takahiko Kawasaki)
Public Archive.
If a proxy server's host name is set (= if
getHost()
returns a non-null value), a socket factory that creates a socket to communicate with the proxy server is selected based on the settings of thisProxySettings
instance. The following is the concrete flow to select a socket factory.-
If
isSecure()
returnstrue
,-
If an
SSLContext
instance has been set bysetSSLContext(SSLContext)
, the value returned fromSSLContext.getSocketFactory()
method of the instance is used. -
Otherwise, if an
SSLSocketFactory
instance has been set bysetSSLSocketFactory(SSLSocketFactory)
, the instance is used. -
Otherwise, the value returned from
SSLSocketFactory.getDefault()
is used.
-
If an
-
Otherwise (=
isSecure()
returnsfalse
),-
If a
SocketFactory
instance has been set bysetSocketFactory(SocketFactory)
, the instance is used. -
Otherwise, the value returned from
SocketFactory.getDefault()
is used.
-
If a
Note that the current implementation supports only Basic Authentication for authentication at the proxy server.
- Since:
- 1.3
- See Also:
WebSocketFactory.getProxySettings()
Hi-Lited Source-Code:- View Here: NeoVisionaries/WebSockets/ProxySettings.java
- Open New Browser-Tab: NeoVisionaries/WebSockets/ProxySettings.java
File Size: 19,730 Bytes Line Count: 809 '\n' Characters Found
-
If
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ProxySettings
addHeader(String name, String value)
Add an additional HTTP header passed to the proxy server.Map<String,List<String>>
getHeaders()
Get additional HTTP headers passed to the proxy server.String
getHost()
Get the host name of the proxy server.String
getId()
Get the ID for authentication at the proxy server.String
getPassword()
Get the password for authentication at the proxy server.int
getPort()
Get the port number of the proxy server.String[]
getServerNames()
Get server names for SNI (Server Name Indication).javax.net.SocketFactory
getSocketFactory()
Get the socket factory that has been set bysetSocketFactory(SocketFactory)
.javax.net.ssl.SSLContext
getSSLContext()
Get the SSL context that has been set bysetSSLContext(SSLContext)
.javax.net.ssl.SSLSocketFactory
getSSLSocketFactory()
Get the SSL socket factory that has been set bysetSSLSocketFactory(SSLSocketFactory)
.WebSocketFactory
getWebSocketFactory()
Get the associatedWebSocketFactory
instance.boolean
isSecure()
Check whether use of TLS is enabled or disabled.ProxySettings
reset()
Reset the proxy settings.ProxySettings
setCredentials(String id, String password)
Set credentials for authentication at the proxy server.ProxySettings
setHost(String host)
Set the host name of the proxy server.ProxySettings
setId(String id)
Set the ID for authentication at the proxy server.ProxySettings
setPassword(String password)
Set the password for authentication at the proxy server.ProxySettings
setPort(int port)
Set the port number of the proxy server.ProxySettings
setSecure(boolean secure)
Enable or disable use of TLS.ProxySettings
setServer(String uri)
Set the proxy server by a URI.ProxySettings
setServer(URI uri)
Set the proxy server by a URI.ProxySettings
setServer(URL url)
Set the proxy server by a URL.ProxySettings
setServerName(String serverName)
Set a server name for SNI (Server Name Indication).ProxySettings
setServerNames(String[] serverNames)
Set server names for SNI (Server Name Indication).ProxySettings
setSocketFactory(javax.net.SocketFactory factory)
Set a socket factory.ProxySettings
setSSLContext(javax.net.ssl.SSLContext context)
Set an SSL context to get a socket factory.ProxySettings
setSSLSocketFactory(javax.net.ssl.SSLSocketFactory factory)
Set an SSL socket factory.
-
-
-
Method Detail
-
getWebSocketFactory
public WebSocketFactory getWebSocketFactory()
Get the associatedWebSocketFactory
instance.
-
reset
public ProxySettings reset()
Reset the proxy settings. To be concrete, parameter values are set as shown below.Name Value Description Secure false
Use TLS to connect to the proxy server or not. Host null
The host name of the proxy server. Port -1
The port number of the proxy server. ID null
The ID for authentication at the proxy server. Password null
The password for authentication at the proxy server. Headers Cleared Additional HTTP headers passed to the proxy server. Server Names null
Server names for SNI (Server Name Indication). - Returns:
this
object.- Code:
- Exact Method Body:
mSecure = false; mHost = null; mPort = -1; mId = null; mPassword = null; mHeaders.clear(); mServerNames = null; return this;
-
isSecure
public boolean isSecure()
Check whether use of TLS is enabled or disabled.- Returns:
true
if TLS is used in the communication with the proxy server.- Code:
- Exact Method Body:
return mSecure;
-
setSecure
public ProxySettings setSecure(boolean secure)
Enable or disable use of TLS.- Parameters:
secure
-true
to use TLS in the communication with the proxy server.- Returns:
this
object.- Code:
- Exact Method Body:
mSecure = secure; return this;
-
getHost
public java.lang.String getHost()
Get the host name of the proxy server.The default value is
null
. If this method returns a non-null value, it is used as the proxy server.- Returns:
- The host name of the proxy server.
- Code:
- Exact Method Body:
return mHost;
-
setHost
public ProxySettings setHost(java.lang.String host)
Set the host name of the proxy server.If a non-null value is set, it is used as the proxy server.
- Parameters:
host
- The host name of the proxy server.- Returns:
this
object.- Code:
- Exact Method Body:
mHost = host; return this;
-
getPort
public int getPort()
Get the port number of the proxy server.The default value is
-1
.-1
means that the default port number (80
for non-secure connections and443
for secure connections) should be used.- Returns:
- The port number of the proxy server.
- Code:
- Exact Method Body:
return mPort;
-
setPort
public ProxySettings setPort(int port)
Set the port number of the proxy server.If
-1
is set, the default port number (80
for non-secure connections and443
for secure connections) is used.- Parameters:
port
- The port number of the proxy server.- Returns:
this
object.- Code:
- Exact Method Body:
mPort = port; return this;
-
getId
public java.lang.String getId()
Get the ID for authentication at the proxy server.The default value is
null
. If this method returns a non-null value, it is used as the ID for authentication at the proxy server. To be concrete, the value is used to generate the value ofProxy-Authorization
header.- Returns:
- The ID for authentication at the proxy server.
- Code:
- Exact Method Body:
return mId;
-
setId
public ProxySettings setId(java.lang.String id)
Set the ID for authentication at the proxy server.If a non-null value is set, it is used as the ID for authentication at the proxy server. To be concrete, the value is used to generate the value of
Proxy-Authorization
header.- Parameters:
id
- The ID for authentication at the proxy server.- Returns:
this
object.- Code:
- Exact Method Body:
mId = id; return this;
-
getPassword
public java.lang.String getPassword()
Get the password for authentication at the proxy server.- Returns:
- The password for authentication at the proxy server.
- Code:
- Exact Method Body:
return mPassword;
-
setPassword
public ProxySettings setPassword(java.lang.String password)
Set the password for authentication at the proxy server.- Parameters:
password
- The password for authentication at the proxy server.- Returns:
this
object.- Code:
- Exact Method Body:
mPassword = password; return this;
-
setCredentials
public ProxySettings setCredentials(java.lang.String id, java.lang.String password)
Set credentials for authentication at the proxy server. This method is an alias ofsetId
(id).
setPassword
(password)
.- Parameters:
id
- The ID.password
- The password.- Returns:
this
object.- Code:
- Exact Method Body:
return setId(id).setPassword(password);
-
setServer
public ProxySettings setServer(java.lang.String uri)
Set the proxy server by a URI. See the description ofsetServer(URI)
about how the parameters are updated.- Parameters:
uri
- The URI of the proxy server. Ifnull
is given, none of the parameters are updated.- Returns:
this
object.- Throws:
java.lang.IllegalArgumentException
- Failed to convert the given string to aURI
instance.- Code:
- Exact Method Body:
if (uri == null) { return this; } return setServer(URI.create(uri));
-
setServer
public ProxySettings setServer(java.net.URL url)
Set the proxy server by a URL. See the description ofsetServer(URI)
about how the parameters are updated.- Parameters:
url
- The URL of the proxy server. Ifnull
is given, none of the parameters are updated.- Returns:
this
object.- Throws:
java.lang.IllegalArgumentException
- Failed to convert the given URL to aURI
instance.- Code:
- Exact Method Body:
if (url == null) { return this; } try { return setServer(url.toURI()); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); }
-
setServer
public ProxySettings setServer(java.net.URI uri)
Set the proxy server by a URI. The parameters are updated as described below.- Secure
If the URI contains the scheme part and its value is either
"http"
or"https"
(case-insensitive), thesecure
parameter is updated tofalse
or totrue
accordingly. In other cases, the parameter is not updated.- ID & Password
If the URI contains the userinfo part and the ID embedded in the userinfo part is not an empty string, the
id
parameter and thepassword
parameter are updated accordingly. In other cases, the parameters are not updated.- Host
The
host
parameter is always updated by the given URI.- Port
The
port
parameter is always updated by the given URI.
- Parameters:
uri
- The URI of the proxy server. Ifnull
is given, none of the parameters is updated.- Returns:
this
object.- Code:
- Exact Method Body:
if (uri == null) { return this; } String scheme = uri.getScheme(); String userInfo = uri.getUserInfo(); String host = uri.getHost(); int port = uri.getPort(); return setServer(scheme, userInfo, host, port);
-
getHeaders
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaders ()
Get additional HTTP headers passed to the proxy server.- Returns:
- Additional HTTP headers passed to the proxy server.
The comparator of the returned map is
String.CASE_INSENSITIVE_ORDER
. - Code:
- Exact Method Body:
return mHeaders;
-
addHeader
public ProxySettings addHeader(java.lang.String name, java.lang.String value)
Add an additional HTTP header passed to the proxy server.- Parameters:
name
- The name of an HTTP header (case-insensitive). Ifnull
or an empty string is given, nothing is added.value
- The value of the HTTP header.- Returns:
this
object.- Code:
- Exact Method Body:
if (name == null || name.length() == 0) { return this; } List<String> list = mHeaders.get(name); if (list == null) { list = new ArrayList<String>(); mHeaders.put(name, list); } list.add(value); return this;
-
getSocketFactory
public javax.net.SocketFactory getSocketFactory()
Get the socket factory that has been set bysetSocketFactory(SocketFactory)
.- Returns:
- The socket factory.
- Code:
- Exact Method Body:
return mSocketFactorySettings.getSocketFactory();
-
setSocketFactory
public ProxySettings setSocketFactory(javax.net.SocketFactory factory)
Set a socket factory.- Parameters:
factory
- A socket factory.- Returns:
this
instance.- Code:
- Exact Method Body:
mSocketFactorySettings.setSocketFactory(factory); return this;
-
getSSLSocketFactory
public javax.net.ssl.SSLSocketFactory getSSLSocketFactory()
Get the SSL socket factory that has been set bysetSSLSocketFactory(SSLSocketFactory)
.- Returns:
- The SSL socket factory.
- Code:
- Exact Method Body:
return mSocketFactorySettings.getSSLSocketFactory();
-
setSSLSocketFactory
public ProxySettings setSSLSocketFactory (javax.net.ssl.SSLSocketFactory factory)
Set an SSL socket factory.- Parameters:
factory
- An SSL socket factory.- Returns:
this
instance.- Code:
- Exact Method Body:
mSocketFactorySettings.setSSLSocketFactory(factory); return this;
-
getSSLContext
public javax.net.ssl.SSLContext getSSLContext()
Get the SSL context that has been set bysetSSLContext(SSLContext)
.- Returns:
- The SSL context.
- Code:
- Exact Method Body:
return mSocketFactorySettings.getSSLContext();
-
setSSLContext
public ProxySettings setSSLContext(javax.net.ssl.SSLContext context)
Set an SSL context to get a socket factory.- Parameters:
context
- An SSL context.- Returns:
this
instance.- Code:
- Exact Method Body:
mSocketFactorySettings.setSSLContext(context); return this;
-
getServerNames
public java.lang.String[] getServerNames()
Get server names for SNI (Server Name Indication).- Returns:
- List of host names.
- Since:
- 2.4
- Code:
- Exact Method Body:
return mServerNames;
-
setServerNames
public ProxySettings setServerNames(java.lang.String[] serverNames)
Set server names for SNI (Server Name Indication). IfsetServerNames(List<SNIServerName>)
method ofSSLParameters
class is available in the underlying system, the method is called to set up server names for SNI (Server Name Indication).- Parameters:
serverNames
- List of host names.- Returns:
this
object.- Since:
- 2.4
- Code:
- Exact Method Body:
mServerNames = serverNames; return this;
-
setServerName
public ProxySettings setServerName(java.lang.String serverName)
Set a server name for SNI (Server Name Indication). This method internally creates a String array of size 1 which contains the givenserverName
and callssetServerNames(String[])
.- Parameters:
serverName
- A host name.- Returns:
this
object.- Since:
- 2.4
- Code:
- Exact Method Body:
return setServerNames(new String[] { serverName });
-
-