org.apache.commons.httpclient

Class HostConfiguration

Implemented Interfaces:
Cloneable

public class HostConfiguration
extends Object
implements Cloneable

Holds all of the variables needed to describe an HTTP connection to a host. This includes remote host, port and protocol, proxy host and port, local address, and virtual host.
Since:
2.0

Field Summary

static HostConfiguration
ANY_HOST_CONFIGURATION
A value to represent any host configuration, instead of using something like null.

Constructor Summary

HostConfiguration()
Constructor for HostConfiguration.
HostConfiguration(HostConfiguration hostConfiguration)
Copy constructor for HostConfiguration

Method Summary

Object
clone()
boolean
equals(Object o)
String
getHost()
Returns the host.
String
getHostURL()
Return the host url.
InetAddress
getLocalAddress()
Return the local address to be used when creating connections.
HostParams
getParams()
Returns HTTP protocol parameters associated with this host.
int
getPort()
Returns the port.
Protocol
getProtocol()
Returns the protocol.
String
getProxyHost()
Returns the proxyHost.
int
getProxyPort()
Returns the proxyPort.
String
getVirtualHost()
Deprecated. use HostParams
int
hashCode()
boolean
hostEquals(HttpConnection connection)
Tests if the host configuration equals the configuration set on the connection.
boolean
isHostSet()
Deprecated. no longer used
boolean
isProxySet()
Deprecated. no longer used
boolean
proxyEquals(HttpConnection connection)
Tests if the proxy configuration equals the configuration set on the connection.
void
setHost(String host)
Set the given host.
void
setHost(String host, int port)
Sets the given host and port.
void
setHost(String host, int port, String protocol)
Sets the given host, port and protocol
void
setHost(String host, int port, Protocol protocol)
Sets the given host, port and protocol.
void
setHost(String host, String virtualHost, int port, Protocol protocol)
Deprecated. #setHost(String, int, Protocol)
void
setHost(HttpHost host)
Sets the given host
void
setHost(URI uri)
Sets the protocol, host and port from the given URI.
void
setLocalAddress(InetAddress localAddress)
Set the local address to be used when creating connections.
void
setParams(HostParams params)
Assigns HTTP protocol parameters specific to this host.
void
setProxy(String proxyHost, int proxyPort)
Set the proxy settings.
void
setProxyHost(ProxyHost proxyHost)
Sets the given proxy host
String
toString()

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

ANY_HOST_CONFIGURATION

public static final HostConfiguration ANY_HOST_CONFIGURATION
A value to represent any host configuration, instead of using something like null. This value should be treated as immutable and only used in lookups and other such places to represent "any" host config.
Usages and Demos :

View More Examples of ANY_HOST_CONFIGURATION
   1: 
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
   4:         ...
   5:     public void setDefaultMaxConnectionsPerHost(int maxHostConnections) {
   6:         setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, maxHostConnections);
   7:     }
   8:         ...
   9:     public void setMaxConnectionsPerHost(
  10:         HostConfiguration hostConfiguration,
  11:         int maxHostConnections) {
  12:         ...
  13:     public int getDefaultMaxConnectionsPerHost() {
  14:         return getMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION);

View Full Code Here

Constructor Details

HostConfiguration

public HostConfiguration()
Constructor for HostConfiguration.
Usages and Demos :

View More Examples of HostConfiguration()
   1: 
   2:             HostConfiguration config = new HostConfiguration();
   3:             config.setHost(host, port);
   4:             HttpClient client = new HttpClient();
   5:             client.setHostConfiguration(config);

View Full Code Here
   1:     private HostConfiguration getHostConfiguration(PortletPublishConfig config) {
   2:         HostConfiguration host = new HostConfiguration();
   3:         host.setHost(config.getHost(), config.getPort(), config.getProtocol());
   4:         return host;
   5:     }

View Full Code Here
   1: 
   2:             HostConfiguration config = new HostConfiguration();
   3:             config.setHost(host, port);
   4:             HttpClient client = new HttpClient();
   5:             client.setHostConfiguration(config);

View Full Code Here
   1:             client = new HttpClient(new MultiThreadedHttpConnectionManager());
   2:             final HostConfiguration config = new HostConfiguration();
   3:             config.setHost(hostname, port, scheme);
   4: 
   5:             if (fileSystemOptions != null)

View Full Code Here
   1:         httpClient.setState(state);
   2:         HostConfiguration hostConfiguration = new HostConfiguration();
   3:         hostConfiguration.setHost(host, port);
   4:         httpClient.setHostConfiguration(hostConfiguration);

View Full Code Here

HostConfiguration

public HostConfiguration(HostConfiguration hostConfiguration)
Copy constructor for HostConfiguration
Parameters:
hostConfiguration - the hostConfiguration to copy
Usages and Demos :

View More Examples of HostConfiguration(HostConfiguration hostConfiguration)

Method Details

clone

public Object clone()
Overrides:
clone in interface Object

equals

public boolean equals(Object o)
Overrides:
equals in interface Object

getHost

public String getHost()
Returns the host.
Returns:
the host(IP or DNS name), or null if not set
See Also:
isHostSet()

getHostURL

public String getHostURL()
Return the host url.
Returns:
The host url.

getLocalAddress

public InetAddress getLocalAddress()
Return the local address to be used when creating connections. If this is unset, the default address should be used.
Returns:
the local address to be used when creating Sockets, or null

getParams

public HostParams getParams()
Returns HTTP protocol parameters associated with this host.
Returns:
HTTP parameters.
Since:
3.0
Usages and Demos :

View More Examples of getParams()
   1: import org.apache.commons.httpclient.Header;
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClientTestBase;
   4:         ...
   5: 
   6:         HostConfiguration hostconfig = new HostConfiguration();
   7:         hostconfig.setHost(
   8:         ...
   9:                 Protocol.getProtocol("http"));
  10:         hostconfig.getParams().setParameter(HostParams.DEFAULT_HEADERS, defaults);
  11:         
  12:         ...
  13: 
  14:         this.client.getParams().setParameter(HttpMethodParams.USER_AGENT, "test");

View Full Code Here

getPort

public int getPort()
Returns the port.
Returns:
the host port, or -1 if not set
See Also:
isHostSet()

getProtocol

public Protocol getProtocol()
Returns the protocol.
Returns:
The protocol.

getProxyHost

public String getProxyHost()
Returns the proxyHost.
Returns:
the proxy host, or null if not set
See Also:
isProxySet()

getProxyPort

public int getProxyPort()
Returns the proxyPort.
Returns:
the proxy port, or -1 if not set
See Also:
isProxySet()

getVirtualHost

public String getVirtualHost()

Deprecated. use HostParams

Returns the virtual host.
Returns:
the virtual host name, or null if not set

hashCode

public int hashCode()
Overrides:
hashCode in interface Object

hostEquals

public boolean hostEquals(HttpConnection connection)
Tests if the host configuration equals the configuration set on the connection. True only if the host, port, protocol, local address and virtual address are equal. If no host configuration has been set false will be returned.
Parameters:
connection - the connection to test against
Returns:
true if the connection's host information equals that of this configuration
Usages and Demos :

View More Examples of hostEquals(HttpConnection connection)
   1: 
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpConnection;
   4:         ...
   5:     public HttpConnection getConnection(
   6:         final HostConfiguration hostConfiguration) {
   7:         return getConnection(hostConfiguration, 0);
   8:         ...
   9:         if(httpConnection == null || !finishLastResponse(httpConnection)
  10:             || !hostConfiguration.hostEquals(httpConnection)
  11:             || !hostConfiguration.proxyEquals(httpConnection)) {

View Full Code Here

isHostSet

public boolean isHostSet()

Deprecated. no longer used

Returns true if the host is set.
Returns:
true if the host is set.

isProxySet

public boolean isProxySet()

Deprecated. no longer used

Tests if the proxy host/port have been set.
Returns:
true if a proxy server has been set.

proxyEquals

public boolean proxyEquals(HttpConnection connection)
Tests if the proxy configuration equals the configuration set on the connection. True only if the proxyHost and proxyPort are equal.
Parameters:
connection - the connection to test against
Returns:
true if the connection's proxy information equals that of this configuration
Usages and Demos :

View More Examples of proxyEquals(HttpConnection connection)
   1: 
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpConnection;
   4:         ...
   5:     public HttpConnection getConnection(
   6:         final HostConfiguration hostConfiguration) {
   7:         return getConnection(hostConfiguration, 0);
   8:         ...
   9:             || !hostConfiguration.hostEquals(httpConnection)
  10:             || !hostConfiguration.proxyEquals(httpConnection)) {

View Full Code Here

setHost

public void setHost(String host)
Set the given host. Uses the default protocol("http") and its port.
Parameters:
host - The host(IP or DNS name).
Usages and Demos :

View More Examples of setHost(String host)
   1: import org.apache.commons.httpclient.HttpClient;
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpException;
   4:         ...
   5: 
   6:     private HostConfiguration getHostConfiguration(PortletPublishConfig config) {
   7:         ...
   8:         HostConfiguration host = new HostConfiguration();
   9:         ...
  10:         host.setHost(config.getHost(), config.getPort(), config.getProtocol());

View Full Code Here
   1: import org.apache.cactus.internal.util.UrlUtil;
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5:         HttpClient client = new HttpClient();
   6:         HostConfiguration hostConfiguration = new HostConfiguration();
   7:         ...
   8:         hostConfiguration.setHost(url.getHost(), url.getPort(),
   9:             Protocol.getProtocol(url.getProtocol()));

View Full Code Here
   1: import org.apache.cactus.util.UrlUtil;
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5:         HttpClient client = new HttpClient();
   6:         HostConfiguration hostConfiguration = new HostConfiguration();
   7:         ...
   8:         hostConfiguration.setHost(url.getHost(), url.getPort(),
   9:             Protocol.getProtocol(url.getProtocol()));

View Full Code Here
   1: import java.util.List;
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5:           HttpClient client = new HttpClient();
   6:           HostConfiguration config = new HostConfiguration();
   7:           BlocklistManager.handleProxySettings(aConfigEntry, config);
   8:         ...
   9:           config.setHost(host);
  10:           client.setHostConfiguration(config);

View Full Code Here
   1: import java.util.List;
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5:         HttpClient client = new HttpClient();
   6:         HostConfiguration config = new HostConfiguration();
   7:         BlocklistManager.handleProxySettings(aConfigEntry, config);
   8:         ...
   9:         config.setHost(host);
  10:         client.setHostConfiguration(config);

View Full Code Here

setHost

public void setHost(String host,
                    int port)
Sets the given host and port. Uses the default protocol "http".
Parameters:
host - the host(IP or DNS name)
port - The port
Usages and Demos :

View More Examples of setHost(String host,int port)
   1: 
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5: 
   6:             HostConfiguration config = new HostConfiguration();
   7:         ...
   8:             config.setHost(host, port);
   9:             HttpClient client = new HttpClient();

View Full Code Here
   1: 
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5: 
   6:             HostConfiguration config = new HostConfiguration();
   7:         ...
   8:             config.setHost(host, port);
   9:             HttpClient client = new HttpClient();

View Full Code Here
   1: 
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5:         httpClient.setState(state);
   6:         HostConfiguration hostConfiguration = new HostConfiguration();
   7:         ...
   8:         hostConfiguration.setHost(host, port);
   9:         httpClient.setHostConfiguration(hostConfiguration);

View Full Code Here

setHost

public void setHost(String host,
                    int port,
                    String protocol)
Sets the given host, port and protocol
Parameters:
host - the host(IP or DNS name)
port - The port
protocol - The protocol.
Usages and Demos :

View More Examples of setHost(String host,int port,String protocol)
   1: 
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5:             client = new HttpClient(new MultiThreadedHttpConnectionManager());
   6:             final HostConfiguration config = new HostConfiguration();
   7:         ...
   8:             config.setHost(hostname, port, scheme);

View Full Code Here
   1: 
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5: 
   6:         HostConfiguration hostConfig = new HostConfiguration();
   7:         ...
   8:         hostConfig.setHost(hostUrl, hostPort, "http");

View Full Code Here
   1: import org.apache.commons.httpclient.Header;
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5: 
   6:         HostConfiguration hc = new HostConfiguration();
   7: 
   8:         if (localAddress != null){
   9:             hc.setLocalAddress(localAddress);

View Full Code Here

setHost

public void setHost(String host,
                    int port,
                    Protocol protocol)
Sets the given host, port and protocol.
Parameters:
host - the host(IP or DNS name)
port - The port
protocol - the protocol
Usages and Demos :

View More Examples of setHost(String host,int port,Protocol protocol)
   1: 
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5:             client = new HttpClient(new MultiThreadedHttpConnectionManager());
   6:             final HostConfiguration config = new HostConfiguration();
   7:         ...
   8:             config.setHost(hostname, port, scheme);

View Full Code Here
   1: 
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5: 
   6:         HostConfiguration hostConfig = new HostConfiguration();
   7:         ...
   8:         hostConfig.setHost(hostUrl, hostPort, "http");

View Full Code Here
   1: import org.apache.commons.httpclient.Header;
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5: 
   6:         HostConfiguration hc = new HostConfiguration();
   7: 
   8:         if (localAddress != null){
   9:             hc.setLocalAddress(localAddress);

View Full Code Here

setHost

public void setHost(String host,
                    String virtualHost,
                    int port,
                    Protocol protocol)

Deprecated. #setHost(String, int, Protocol)

Sets the given host, virtual host, port and protocol.
Parameters:
host - the host(IP or DNS name)
virtualHost - the virtual host name or null
port - the host port or -1 to use protocol default
protocol - the protocol

setHost

public void setHost(HttpHost host)
Sets the given host
Parameters:
host - the host
Usages and Demos :

View More Examples of setHost(HttpHost host)
   1: import org.apache.commons.httpclient.HttpClient;
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpException;
   4:         ...
   5: 
   6:     private HostConfiguration getHostConfiguration(PortletPublishConfig config) {
   7:         ...
   8:         HostConfiguration host = new HostConfiguration();
   9:         ...
  10:         host.setHost(config.getHost(), config.getPort(), config.getProtocol());

View Full Code Here
   1: import org.apache.cactus.internal.util.UrlUtil;
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5:         HttpClient client = new HttpClient();
   6:         HostConfiguration hostConfiguration = new HostConfiguration();
   7:         ...
   8:         hostConfiguration.setHost(url.getHost(), url.getPort(),
   9:             Protocol.getProtocol(url.getProtocol()));

View Full Code Here
   1: import org.apache.cactus.util.UrlUtil;
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5:         HttpClient client = new HttpClient();
   6:         HostConfiguration hostConfiguration = new HostConfiguration();
   7:         ...
   8:         hostConfiguration.setHost(url.getHost(), url.getPort(),
   9:             Protocol.getProtocol(url.getProtocol()));

View Full Code Here
   1: import java.util.List;
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5:           HttpClient client = new HttpClient();
   6:           HostConfiguration config = new HostConfiguration();
   7:           BlocklistManager.handleProxySettings(aConfigEntry, config);
   8:         ...
   9:           config.setHost(host);
  10:           client.setHostConfiguration(config);

View Full Code Here
   1: import java.util.List;
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5:         HttpClient client = new HttpClient();
   6:         HostConfiguration config = new HostConfiguration();
   7:         BlocklistManager.handleProxySettings(aConfigEntry, config);
   8:         ...
   9:         config.setHost(host);
  10:         client.setHostConfiguration(config);

View Full Code Here

setHost

public void setHost(URI uri)
Sets the protocol, host and port from the given URI.
Parameters:
uri - the URI.
Usages and Demos :

View More Examples of setHost(URI uri)
   1: import org.apache.commons.httpclient.HttpClient;
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpException;
   4:         ...
   5: 
   6:     private HostConfiguration getHostConfiguration(PortletPublishConfig config) {
   7:         ...
   8:         HostConfiguration host = new HostConfiguration();
   9:         ...
  10:         host.setHost(config.getHost(), config.getPort(), config.getProtocol());

View Full Code Here
   1: import org.apache.cactus.internal.util.UrlUtil;
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5:         HttpClient client = new HttpClient();
   6:         HostConfiguration hostConfiguration = new HostConfiguration();
   7:         ...
   8:         hostConfiguration.setHost(url.getHost(), url.getPort(),
   9:             Protocol.getProtocol(url.getProtocol()));

View Full Code Here
   1: import org.apache.cactus.util.UrlUtil;
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5:         HttpClient client = new HttpClient();
   6:         HostConfiguration hostConfiguration = new HostConfiguration();
   7:         ...
   8:         hostConfiguration.setHost(url.getHost(), url.getPort(),
   9:             Protocol.getProtocol(url.getProtocol()));

View Full Code Here
   1: import java.util.List;
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5:           HttpClient client = new HttpClient();
   6:           HostConfiguration config = new HostConfiguration();
   7:           BlocklistManager.handleProxySettings(aConfigEntry, config);
   8:         ...
   9:           config.setHost(host);
  10:           client.setHostConfiguration(config);

View Full Code Here
   1: import java.util.List;
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5:         HttpClient client = new HttpClient();
   6:         HostConfiguration config = new HostConfiguration();
   7:         BlocklistManager.handleProxySettings(aConfigEntry, config);
   8:         ...
   9:         config.setHost(host);
  10:         client.setHostConfiguration(config);

View Full Code Here

setLocalAddress

public void setLocalAddress(InetAddress localAddress)
Set the local address to be used when creating connections. If this is unset, the default address will be used. This is useful for specifying the interface to use on multi-homed or clustered systems.
Parameters:
localAddress - the local address to use
Usages and Demos :

View More Examples of setLocalAddress(InetAddress localAddress)
   1: import org.apache.commons.httpclient.Header;
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5: 
   6:         HostConfiguration hc = new HostConfiguration();
   7: 
   8:         ...
   9:         if (localAddress != null){
  10:             hc.setLocalAddress(localAddress);
  11:         }

View Full Code Here

setParams

public void setParams(HostParams params)
Assigns HTTP protocol parameters specific to this host.
Since:
3.0
See Also:
HostParams

setProxy

public void setProxy(String proxyHost,
                     int proxyPort)
Set the proxy settings.
Parameters:
proxyHost - The proxy host
proxyPort - The proxy port
Usages and Demos :

View More Examples of setProxy(String proxyHost,int proxyPort)
   1: 
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5:             client = new HttpClient(new MultiThreadedHttpConnectionManager());
   6:             final HostConfiguration config = new HostConfiguration();
   7:             config.setHost(hostname, port, scheme);
   8:         ...
   9:                 {
  10:                     config.setProxy(proxyHost, proxyPort);
  11:                 }

View Full Code Here
   1: import org.apache.commons.httpclient.Header;
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5:             final HttpMethodBase httpMethod = makeHttpMethod(webRequestSettings);
   6:             final HostConfiguration hostConfiguration = getHostConfiguration(webRequestSettings);
   7:             final long startTime = System.currentTimeMillis();
   8:         ...
   9:             final int proxyPort = webRequestSettings.getProxyPort();
  10:             hostConfiguration.setProxy( proxyHost, proxyPort );
  11:         }

View Full Code Here
   1: import org.apache.commons.httpclient.Header;
   2: import org.apache.commons.httpclient.HostConfiguration;
   3: import org.apache.commons.httpclient.HttpClient;
   4:         ...
   5: 
   6:         HostConfiguration hc = new HostConfiguration();
   7: 
   8:         ...
   9:             }
  10:             hc.setProxy(PROXY_HOST, PROXY_PORT);
  11:             if (PROXY_USER.length() > 0){

View Full Code Here

setProxyHost

public void setProxyHost(ProxyHost proxyHost)
Sets the given proxy host
Parameters:
proxyHost - the proxy host

toString

public String toString()
Overrides:
toString in interface Object