public class ProxySettings extends Object
Proxy settings.
<p>
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.
</p>
<blockquote>
<ol>
<li>
If isSecure() returns true,
<ol type="i">
<li>
If an SSLContext instance has been set by setSSLContext(SSLContext), the value returned from SSLContext.getSocketFactory() method of the instance is used.
<li>
Otherwise, if an SSLSocketFactory instance has been
set by setSSLSocketFactory(SSLSocketFactory), the
instance is used.
<li>
Otherwise, the value returned from SSLSocketFactory.getDefault()
is used.
</ol>
<li>
Otherwise (= isSecure() returns false),
<ol type="i">
<li>
If a SocketFactory instance has been set by setSocketFactory(SocketFactory), the instance is used.
<li>
Otherwise, the value returned from SocketFactory.getDefault()
is used.
</ol>
</ol>
</blockquote>
<p> Note that the current implementation supports only Basic Authentication for authentication at the proxy server. </p>
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()
Get the associated WebSocketFactory instance.
public ProxySettings reset()
Reset the proxy settings. To be concrete, parameter values are set as shown below.
<blockquote>
<table border="1" cellpadding="5" style="border-collapse: collapse;">
<thead>
<tr>
<th>Name</th>
<th>Value</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>Secure</td>
<td>false</td>
<td>Use TLS to connect to the proxy server or not.</td>
</tr>
<tr>
<td>Host</td>
<td>null</td>
<td>The host name of the proxy server.</td>
</tr>
<tr>
<td>Port</td>
<td>-1</td>
<td>The port number of the proxy server.</td>
</tr>
<tr>
<td>ID</td>
<td>null</td>
<td>The ID for authentication at the proxy server.</td>
</tr>
<tr>
<td>Password</td>
<td>null</td>
<td>The password for authentication at the proxy server.</td>
</tr>
<tr>
<td>Headers</td>
<td>Cleared</td>
<td>Additional HTTP headers passed to the proxy server.</td>
</tr>
<tr>
<td>Server Names</td>
<td>null</td>
<td>Server names for SNI (Server Name Indication).</td>
</tr>
</tbody>
</table>
</blockquote>
this object.public boolean isSecure()
Check whether use of TLS is enabled or disabled.
true if TLS is used in the communication with
the proxy server.public ProxySettings setSecure(boolean secure)
Enable or disable use of TLS.
secure - true to use TLS in the communication with
the proxy server.this object.public String getHost()
Get the host name of the proxy server.
<p>
The default value is null. If this method returns
a non-null value, it is used as the proxy server.
</p>
public ProxySettings setHost(String host)
Set the host name of the proxy server.
<p> If a non-null value is set, it is used as the proxy server. </p>
host - The host name of the proxy server.this object.public int getPort()
Get the port number of the proxy server.
<p>
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.
</p>
public ProxySettings setPort(int port)
Set the port number of the proxy server.
<p>
If -1 is set, the default port number (80
for non-secure connections and 443 for secure
connections) is used.
</p>
port - The port number of the proxy server.this object.public String getId()
Get the ID for authentication at the proxy server.
<p>
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 <code><a href=
"http://tools.ietf.org/html/rfc2616#section-14.34"
>Proxy-Authorization</a></code> header.
</p>
public ProxySettings setId(String id)
Set the ID for authentication at the proxy server.
<p> 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 <code><a href= "http://tools.ietf.org/html/rfc2616#section-14.34" >Proxy-Authorization</a></code> header. </p>
id - The ID for authentication at the proxy server.this object.public String getPassword()
Get the password for authentication at the proxy server.
public ProxySettings setPassword(String password)
Set the password for authentication at the proxy server.
password - The password for authentication at the proxy server.this object.public ProxySettings setCredentials(String id, String password)
Set credentials for authentication at the proxy server.
This method is an alias of setId(id).setPassword(password).
id - The ID.password - The password.this object.public ProxySettings setServer(String uri)
Set the proxy server by a URI. See the description of
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)
Set the proxy server by a URL. See the description of
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)
Set the proxy server by a URI. The parameters are updated as described below.
<blockquote>
<dl>
<dt>Secure</dt>
<dd><p>
If the URI contains the scheme part and its value is
either "http" or "https" (case-insensitive),
the secure parameter is updated to false
or to true accordingly. In other cases, the parameter
is not updated.
</p></dd>
<dt>ID & Password</dt>
<dd><p>
If the URI contains the userinfo part and the ID embedded
in the userinfo part is not an empty string, the id parameter and the password parameter are updated
accordingly. In other cases, the parameters are not updated.
</p></dd>
<dt>Host</dt>
<dd><p>
The host parameter is always updated by the given URI.
</p></dd>
<dt>Port</dt>
<dd><p>
The port parameter is always updated by the given URI.
</p></dd>
</dl>
</blockquote>
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()
Get additional HTTP headers passed to the proxy server.
String.CASE_INSENSITIVE_ORDER.public ProxySettings addHeader(String name, String value)
Add an additional HTTP header passed to the proxy server.
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()
Get the socket factory that has been set by setSocketFactory(SocketFactory).
public ProxySettings setSocketFactory(SocketFactory factory)
Set a socket factory.
factory - A socket factory.this instance.public SSLSocketFactory getSSLSocketFactory()
Get the SSL socket factory that has been set by setSSLSocketFactory(SSLSocketFactory).
public ProxySettings setSSLSocketFactory(SSLSocketFactory factory)
Set an SSL socket factory.
factory - An SSL socket factory.this instance.public SSLContext getSSLContext()
Get the SSL context that has been set by setSSLContext(SSLContext).
public ProxySettings setSSLContext(SSLContext context)
Set an SSL context to get a socket factory.
context - An SSL context.this instance.public String[] getServerNames()
Get server names for SNI (Server Name Indication).
public ProxySettings setServerNames(String[] serverNames)
Set server names for SNI (Server Name Indication).
If 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)
Set a server name for SNI (Server Name Indication).
This method internally creates a String array of size 1 which
contains the given serverName and calls setServerNames(String[]).
serverName - A host name.this object.Copyright © 2021. All Rights Reserved.