Class ProxySettings
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 this ProxySettings instance. The
following is the concrete flow to select a socket factory.
- If
isSecure()returnstrue,
- If an
SSLContextinstance has been set bysetSSLContext(SSLContext), the value returned fromSSLContext.getSocketFactory()method of the instance is used.- Otherwise, if an
SSLSocketFactoryinstance has been set bysetSSLSocketFactory(SSLSocketFactory), the instance is used.- Otherwise, the value returned from
SSLSocketFactory.getDefault()is used.- Otherwise (=
isSecure()returnsfalse),
- If a
SocketFactoryinstance has been set bysetSocketFactory(SocketFactory), the instance is used.- Otherwise, the value returned from
SocketFactory.getDefault()is used.
Note that the current implementation supports only Basic Authentication for authentication at the proxy server.
- Since:
- 1.3
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Stringprivate Stringprivate Stringprivate intprivate booleanprivate String[]private final SocketFactorySettingsprivate final WebSocketFactory -
Constructor Summary
ConstructorsConstructorDescriptionProxySettings(WebSocketFactory factory) Constructor.ProxySettings(WebSocketFactory factory, ProxySettings settings) Constructor with settings. -
Method Summary
Modifier and TypeMethodDescriptionAdd an additional HTTP header passed to the proxy server.Get additional HTTP headers passed to the proxy server.getHost()Get the host name of the proxy server.getId()Get the ID for authentication at the proxy server.Get the password for authentication at the proxy server.intgetPort()Get the port number of the proxy server.String[]Get server names for SNI (Server Name Indication).Get the socket factory that has been set bysetSocketFactory(SocketFactory).Get the SSL context that has been set bysetSSLContext(SSLContext).Get the SSL socket factory that has been set bysetSSLSocketFactory(SSLSocketFactory).Get the associatedWebSocketFactoryinstance.booleanisSecure()Check whether use of TLS is enabled or disabled.reset()Reset the proxy settings.(package private) SocketFactoryprivate voidsetByScheme(String scheme) private voidsetByUserInfo(String userInfo) setCredentials(String id, String password) Set credentials for authentication at the proxy server.Set the host name of the proxy server.Set the ID for authentication at the proxy server.setPassword(String password) Set the password for authentication at the proxy server.setPort(int port) Set the port number of the proxy server.setSecure(boolean secure) Enable or disable use of TLS.Set the proxy server by a URI.private ProxySettingsSet the proxy server by a URI.Set the proxy server by a URL.setServerName(String serverName) Set a server name for SNI (Server Name Indication).setServerNames(String[] serverNames) Set server names for SNI (Server Name Indication).setSocketFactory(SocketFactory factory) Set a socket factory.setSSLContext(SSLContext context) Set an SSL context to get a socket factory.setSSLSocketFactory(SSLSocketFactory factory) Set an SSL socket factory.
-
Field Details
-
mWebSocketFactory
-
mHeaders
-
mSocketFactorySettings
-
mSecure
private boolean mSecure -
mHost
-
mPort
private int mPort -
mId
-
mPassword
-
mServerNames
-
-
Constructor Details
-
ProxySettings
ProxySettings(WebSocketFactory factory) Constructor. AWebSocketFactoryinstance to be associated with.- Parameters:
factory-
-
ProxySettings
ProxySettings(WebSocketFactory factory, ProxySettings settings) Constructor with settings.- Parameters:
factory- AWebSocketFactoryinstance to be associated with.settings- Settings to copy.- Since:
- 2.10
-
-
Method Details
-
getWebSocketFactory
Get the associatedWebSocketFactoryinstance. -
reset
Reset the proxy settings. To be concrete, parameter values are set as shown below.Name Value Description Secure falseUse TLS to connect to the proxy server or not. Host nullThe host name of the proxy server. Port -1The port number of the proxy server. ID nullThe ID for authentication at the proxy server. Password nullThe password for authentication at the proxy server. Headers Cleared Additional HTTP headers passed to the proxy server. Server Names nullServer names for SNI (Server Name Indication). - Returns:
thisobject.
-
isSecure
public boolean isSecure()Check whether use of TLS is enabled or disabled.- Returns:
trueif TLS is used in the communication with the proxy server.
-
setSecure
Enable or disable use of TLS.- Parameters:
secure-trueto use TLS in the communication with the proxy server.- Returns:
thisobject.
-
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.
-
setHost
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:
thisobject.
-
getPort
public int getPort()Get the port number of the proxy server.The default value is
-1.-1means that the default port number (80for non-secure connections and443for secure connections) should be used.- Returns:
- The port number of the proxy server.
-
setPort
Set the port number of the proxy server.If
-1is set, the default port number (80for non-secure connections and443for secure connections) is used.- Parameters:
port- The port number of the proxy server.- Returns:
thisobject.
-
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-Authorizationheader.- Returns:
- The ID for authentication at the proxy server.
-
setId
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-Authorizationheader.- Parameters:
id- The ID for authentication at the proxy server.- Returns:
thisobject.
-
getPassword
Get the password for authentication at the proxy server.- Returns:
- The password for authentication at the proxy server.
-
setPassword
Set the password for authentication at the proxy server.- Parameters:
password- The password for authentication at the proxy server.- Returns:
thisobject.
-
setCredentials
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:
thisobject.
-
setServer
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. Ifnullis given, none of the parameters are updated.- Returns:
thisobject.- Throws:
IllegalArgumentException- Failed to convert the given string to aURIinstance.
-
setServer
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. Ifnullis given, none of the parameters are updated.- Returns:
thisobject.- Throws:
IllegalArgumentException- Failed to convert the given URL to aURIinstance.
-
setServer
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), thesecureparameter is updated tofalseor totrueaccordingly. 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
idparameter and thepasswordparameter are updated accordingly. In other cases, the parameters are not updated.- Host
The
hostparameter is always updated by the given URI.- Port
The
portparameter is always updated by the given URI.
- Parameters:
uri- The URI of the proxy server. Ifnullis given, none of the parameters is updated.- Returns:
thisobject.
-
setServer
-
setByScheme
-
setByUserInfo
-
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.
-
addHeader
Add an additional HTTP header passed to the proxy server.- Parameters:
name- The name of an HTTP header (case-insensitive). Ifnullor an empty string is given, nothing is added.value- The value of the HTTP header.- Returns:
thisobject.
-
getSocketFactory
Get the socket factory that has been set bysetSocketFactory(SocketFactory).- Returns:
- The socket factory.
-
setSocketFactory
Set a socket factory.- Parameters:
factory- A socket factory.- Returns:
thisinstance.
-
getSSLSocketFactory
Get the SSL socket factory that has been set bysetSSLSocketFactory(SSLSocketFactory).- Returns:
- The SSL socket factory.
-
setSSLSocketFactory
Set an SSL socket factory.- Parameters:
factory- An SSL socket factory.- Returns:
thisinstance.
-
getSSLContext
Get the SSL context that has been set bysetSSLContext(SSLContext).- Returns:
- The SSL context.
-
setSSLContext
Set an SSL context to get a socket factory.- Parameters:
context- An SSL context.- Returns:
thisinstance.
-
selectSocketFactory
SocketFactory selectSocketFactory() -
getServerNames
Get server names for SNI (Server Name Indication).- Returns:
- List of host names.
- Since:
- 2.4
-
setServerNames
Set server names for SNI (Server Name Indication). IfsetServerNames(List<SNIServerName>)method ofSSLParametersclass 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:
thisobject.- Since:
- 2.4
-
setServerName
Set a server name for SNI (Server Name Indication). This method internally creates a String array of size 1 which contains the givenserverNameand callssetServerNames(String[]).- Parameters:
serverName- A host name.- Returns:
thisobject.- Since:
- 2.4
-