public class ProxySettings extends Object
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
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.- 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.
Note that the current implementation supports only Basic Authentication for authentication at the proxy server.
WebSocketFactory.getProxySettings()
Modifier and Type | Method and 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).
|
SocketFactory |
getSocketFactory()
Get the socket factory that has been set by
setSocketFactory(SocketFactory) . |
SSLContext |
getSSLContext()
Get the SSL context that has been set by
setSSLContext(SSLContext) . |
SSLSocketFactory |
getSSLSocketFactory()
Get the SSL socket factory that has been set by
setSSLSocketFactory(SSLSocketFactory) . |
WebSocketFactory |
getWebSocketFactory()
Get the associated
WebSocketFactory 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(SocketFactory factory)
Set a socket factory.
|
ProxySettings |
setSSLContext(SSLContext context)
Set an SSL context to get a socket factory.
|
ProxySettings |
setSSLSocketFactory(SSLSocketFactory factory)
Set an SSL socket factory.
|
public WebSocketFactory getWebSocketFactory()
WebSocketFactory
instance.public ProxySettings reset()
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).
this
object.public boolean isSecure()
true
if TLS is used in the communication with
the proxy server.public ProxySettings setSecure(boolean secure)
secure
- true
to use TLS in the communication with
the proxy server.this
object.public String getHost()
The default value is null
. If this method returns
a non-null value, it is used as the proxy server.
public ProxySettings setHost(String host)
If a non-null value is set, it is used as the proxy server.
host
- The host name of the proxy server.this
object.public int getPort()
The default value is -1
. -1
means that
the default port number (80
for non-secure
connections and 443
for secure connections)
should be used.
public ProxySettings setPort(int port)
If -1
is set, the default port number (80
for non-secure connections and 443
for secure
connections) is used.
port
- The port number of the proxy server.this
object.public String getId()
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 of Proxy-Authorization
header.
public ProxySettings setId(String id)
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.
id
- The ID for authentication at the proxy server.this
object.public String getPassword()
public ProxySettings setPassword(String password)
password
- The password for authentication at the proxy server.this
object.public ProxySettings setCredentials(String id, String password)
setId
(id).
setPassword
(password)
.id
- The ID.password
- The password.this
object.public ProxySettings setServer(String uri)
setServer(URI)
about how the parameters are updated.uri
- The URI of the proxy server. If null
is given,
none of the parameters are updated.this
object.IllegalArgumentException
- Failed to convert the given string to a URI
instance.public ProxySettings setServer(URL url)
setServer(URI)
about how the parameters are updated.url
- The URL of the proxy server. If null
is given,
none of the parameters are updated.this
object.IllegalArgumentException
- Failed to convert the given URL to a URI
instance.public ProxySettings setServer(URI uri)
- 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.
uri
- The URI of the proxy server. If null
is given,
none of the parameters is updated.this
object.public Map<String,List<String>> getHeaders()
String.CASE_INSENSITIVE_ORDER
.public ProxySettings addHeader(String name, String value)
name
- The name of an HTTP header (case-insensitive).
If null
or an empty string is given,
nothing is added.value
- The value of the HTTP header.this
object.public SocketFactory getSocketFactory()
setSocketFactory(SocketFactory)
.public ProxySettings setSocketFactory(SocketFactory factory)
factory
- A socket factory.this
instance.public SSLSocketFactory getSSLSocketFactory()
setSSLSocketFactory(SSLSocketFactory)
.public ProxySettings setSSLSocketFactory(SSLSocketFactory factory)
factory
- An SSL socket factory.this
instance.public SSLContext getSSLContext()
setSSLContext(SSLContext)
.public ProxySettings setSSLContext(SSLContext context)
context
- An SSL context.this
instance.public String[] getServerNames()
public ProxySettings setServerNames(String[] serverNames)
setServerNames(List<SNIServerName>)
method of
SSLParameters
class is available
in the underlying system, the method is called to set up server names
for SNI (Server Name Indication).serverNames
- List of host names.this
object.public ProxySettings setServerName(String serverName)
serverName
and calls setServerNames(String[])
.serverName
- A host name.this
object.Copyright © 2021. All rights reserved.