本文整理了Java中org.apache.commons.httpclient.ProxyHost
类的一些代码示例,展示了ProxyHost
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ProxyHost
类的具体详情如下:
包路径:org.apache.commons.httpclient.ProxyHost
类名称:ProxyHost
[英]Holds all of the variables needed to describe an HTTP connection to a proxy. Proxy hosts always use plain HTTP connection when communicating with clients.
[中]保存描述到代理的HTTP连接所需的所有变量。代理主机在与客户端通信时总是使用普通HTTP连接。
代码示例来源:origin: commons-httpclient/commons-httpclient
/**
* Set the proxy settings.
* @param proxyHost The proxy host
* @param proxyPort The proxy port
*/
public synchronized void setProxy(final String proxyHost, int proxyPort) {
this.proxyHost = new ProxyHost(proxyHost, proxyPort);
}
代码示例来源:origin: commons-httpclient/commons-httpclient
/**
* Tests if the proxy configuration equals the configuration set on the
* connection. True only if the proxyHost and proxyPort are equal.
*
* @param connection the connection to test against
* @return <code>true</code> if the connection's proxy information equals that of this
* configuration
*
* @see #hostEquals(HttpConnection)
*/
public synchronized boolean proxyEquals(final HttpConnection connection) {
if (connection == null) {
throw new IllegalArgumentException("Connection may not be null");
}
if (this.proxyHost != null) {
return
this.proxyHost.getHostName().equalsIgnoreCase(connection.getProxyHost())
&& this.proxyHost.getPort() == connection.getProxyPort();
} else {
return connection.getProxyHost() == null;
}
}
代码示例来源:origin: commons-httpclient/commons-httpclient
private void init(final HostConfiguration hostConfiguration) {
// wrap all of the assignments in a synchronized block to avoid
// having to negotiate the monitor for each method call
synchronized (hostConfiguration) {
try {
if (hostConfiguration.host != null) {
this.host = (HttpHost) hostConfiguration.host.clone();
} else {
this.host = null;
}
if (hostConfiguration.proxyHost != null) {
this.proxyHost = (ProxyHost) hostConfiguration.proxyHost.clone();
} else {
this.proxyHost = null;
}
this.localAddress = hostConfiguration.getLocalAddress();
this.params = (HostParams)hostConfiguration.getParams().clone();
} catch (CloneNotSupportedException e) {
throw new IllegalArgumentException("Host configuration could not be cloned");
}
}
}
代码示例来源:origin: org.n52.metadata/smarteditor-api
mClient.setHostConfiguration(lConfig);
LOG.debug("Using proxy: " + "Host={};Port={};Scheme={}"
, lProxyHost.getHostName()
, lProxyHost.getPort()
, lProxyHost.getProtocol().getScheme());
代码示例来源:origin: commons-httpclient/commons-httpclient
/**
* Returns the proxyHost.
*
* @return the proxy host, or <code>null</code> if not set
*
* @see #isProxySet()
*/
public synchronized String getProxyHost() {
if (this.proxyHost != null) {
return this.proxyHost.getHostName();
} else {
return null;
}
}
代码示例来源:origin: org.alfresco/alfresco-repository
if (strProxyPort == null || strProxyPort.length() == 0)
proxy = new ProxyHost(proxyHost, defaultPort);
proxy = new ProxyHost(proxyHost, Integer.parseInt(strProxyPort));
logger.debug("ProxyHost: " + proxy.toString());
代码示例来源:origin: commons-httpclient/commons-httpclient
/**
* Returns the proxyPort.
*
* @return the proxy port, or <code>-1</code> if not set
*
* @see #isProxySet()
*/
public synchronized int getProxyPort() {
if (this.proxyHost != null) {
return this.proxyHost.getPort();
} else {
return -1;
}
}
代码示例来源:origin: org.n52.metadata/smarteditor-api
private void initClient() {
this.setClient(new HttpClient());
HostConfiguration lConfig = new HostConfiguration();
ProxyResolver proxyResolver = new ProxyResolver();
try {
URL lUrl = new URL(getEndpoint());
ProxyHost lProxyHost = proxyResolver.createProxyHost(lUrl);
lConfig.setProxyHost(lProxyHost);
if (lProxyHost != null) {
LOG.debug("Using proxy: Host={}; Port{};Scheme={}", lProxyHost.getHostName(), lProxyHost.getPort(), lProxyHost.getProtocol().getScheme());
} else {
LOG.debug("Using no proxy");
}
// set proxy authentication, if any
Credentials lCredentials = proxyResolver.createCredentials(lUrl);
if (lCredentials != null) {
LOG.info("Setting proxy credentials");
HttpState state = new HttpState();
state.setProxyCredentials(AuthScope.ANY, lCredentials);
getClient().setState(state);
}
} catch (MalformedURLException pEx) {
LOG.error("Error cleating proxy for URL " + getEndpoint() + ": " + pEx.getMessage());
}
getClient().setHostConfiguration(lConfig);
}
代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.httpclient
/**
* Returns the proxyHost.
*
* @return the proxy host, or <code>null</code> if not set
*
* @see #isProxySet()
*/
public synchronized String getProxyHost() {
if (this.proxyHost != null) {
return this.proxyHost.getHostName();
} else {
return null;
}
}
代码示例来源:origin: Alfresco/alfresco-repository
if (strProxyPort == null || strProxyPort.length() == 0)
proxy = new ProxyHost(proxyHost, defaultPort);
proxy = new ProxyHost(proxyHost, Integer.parseInt(strProxyPort));
logger.debug("ProxyHost: " + proxy.toString());
代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.httpclient
/**
* Returns the proxyPort.
*
* @return the proxy port, or <code>-1</code> if not set
*
* @see #isProxySet()
*/
public synchronized int getProxyPort() {
if (this.proxyHost != null) {
return this.proxyHost.getPort();
} else {
return -1;
}
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-httpclient
/**
* Set the proxy settings.
* @param proxyHost The proxy host
* @param proxyPort The proxy port
*/
public synchronized void setProxy(final String proxyHost, int proxyPort) {
this.proxyHost = new ProxyHost(proxyHost, proxyPort);
}
代码示例来源:origin: org.alfresco/alfresco-repository
/**
* Create suitable AuthScope for ProxyHost. If the ProxyHost is null, no AuthsScope will be created.
* @param proxyHost ProxyHost
* @return AuthScope for provided ProxyHost, null otherwise.
*/
private AuthScope createProxyAuthScope(final ProxyHost proxyHost)
{
AuthScope authScope = null;
if (proxyHost != null)
{
authScope = new AuthScope(proxyHost.getHostName(), proxyHost.getPort());
}
return authScope;
}
代码示例来源:origin: Alfresco/alfresco-repository
public void testHTTPProxySettings()
{
String host = "testHost";
Integer port = 8080;
setHTTPSystemProperties(host, port, "user1", "password", null);
ProxyHost proxyHost = HttpClientHelper.createProxyHost("http.proxyHost", "http.proxyPort", DEFAULT_HTTP_PORT);
UsernamePasswordCredentials proxyCredentials = (UsernamePasswordCredentials) HttpClientHelper.createProxyCredentials("http.proxyUser", "http.proxyPassword");
assertEquals(HTTP, proxyHost.getProtocol().getScheme());
assertEquals(host, proxyHost.getHostName());
assertEquals(port, Integer.valueOf(proxyHost.getPort()));
assertEquals("user1", proxyCredentials.getUserName());
assertEquals("password", proxyCredentials.getPassword());
// Test default port and no credentials
setHTTPSystemProperties(host, null, null, null, null);
proxyHost = HttpClientHelper.createProxyHost("http.proxyHost", "http.proxyPort", DEFAULT_HTTP_PORT);
proxyCredentials = (UsernamePasswordCredentials) HttpClientHelper.createProxyCredentials("http.proxyUser", "http.proxyPassword");
assertEquals(HTTP, proxyHost.getProtocol().getScheme());
assertEquals(host, proxyHost.getHostName());
assertEquals(DEFAULT_HTTP_PORT, proxyHost.getPort());
assertNull(proxyCredentials);
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-httpclient
/**
* Returns the proxyHost.
*
* @return the proxy host, or <code>null</code> if not set
*
* @see #isProxySet()
*/
public synchronized String getProxyHost() {
if (this.proxyHost != null) {
return this.proxyHost.getHostName();
} else {
return null;
}
}
代码示例来源:origin: org.apache.commons/httpclient
/**
* Returns the proxyPort.
*
* @return the proxy port, or <code>-1</code> if not set
*
* @see #isProxySet()
*/
public synchronized int getProxyPort() {
if (this.proxyHost != null) {
return this.proxyHost.getPort();
} else {
return -1;
}
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-httpclient
private void init(final HostConfiguration hostConfiguration) {
// wrap all of the assignments in a synchronized block to avoid
// having to negotiate the monitor for each method call
synchronized (hostConfiguration) {
try {
if (hostConfiguration.host != null) {
this.host = (HttpHost) hostConfiguration.host.clone();
} else {
this.host = null;
}
if (hostConfiguration.proxyHost != null) {
this.proxyHost = (ProxyHost) hostConfiguration.proxyHost.clone();
} else {
this.proxyHost = null;
}
this.localAddress = hostConfiguration.getLocalAddress();
this.params = (HostParams)hostConfiguration.getParams().clone();
} catch (CloneNotSupportedException e) {
throw new IllegalArgumentException("Host configuration could not be cloned");
}
}
}
代码示例来源:origin: org.wso2.commons-httpclient/commons-httpclient
/**
* Set the proxy settings.
* @param proxyHost The proxy host
* @param proxyPort The proxy port
*/
public synchronized void setProxy(final String proxyHost, int proxyPort) {
this.proxyHost = new ProxyHost(proxyHost, proxyPort);
}
代码示例来源:origin: Alfresco/alfresco-repository
/**
* Create suitable AuthScope for ProxyHost. If the ProxyHost is null, no AuthsScope will be created.
* @param proxyHost ProxyHost
* @return AuthScope for provided ProxyHost, null otherwise.
*/
private AuthScope createProxyAuthScope(final ProxyHost proxyHost)
{
AuthScope authScope = null;
if (proxyHost != null)
{
authScope = new AuthScope(proxyHost.getHostName(), proxyHost.getPort());
}
return authScope;
}
代码示例来源:origin: Alfresco/alfresco-repository
public void testHTTPSProxySettings()
{
String host = "testHost";
Integer port = 8444;
setHTTPSSystemProperties(host, port, "user1", "password", null);
ProxyHost proxyHost = HttpClientHelper.createProxyHost("https.proxyHost", "https.proxyPort", DEFAULT_HTTPS_PORT);
UsernamePasswordCredentials proxyCredentials = (UsernamePasswordCredentials) HttpClientHelper.createProxyCredentials("https.proxyUser", "https.proxyPassword");
// Proxy hosts always use plain HTTP connection when communicating with clients (by commons.httpclient doc)
assertEquals(HTTP, proxyHost.getProtocol().getScheme());
assertEquals(host, proxyHost.getHostName());
assertEquals(port, Integer.valueOf(proxyHost.getPort()));
assertEquals("user1", proxyCredentials.getUserName());
assertEquals("password", proxyCredentials.getPassword());
// Test default port and no credentials
setHTTPSSystemProperties(host, null, null, null, null);
proxyHost = HttpClientHelper.createProxyHost("https.proxyHost", "https.proxyPort", DEFAULT_HTTPS_PORT);
proxyCredentials = (UsernamePasswordCredentials) HttpClientHelper.createProxyCredentials("https.proxyUser", "https.proxyPassword");
assertEquals(host, proxyHost.getHostName());
assertEquals(DEFAULT_HTTPS_PORT, proxyHost.getPort());
assertNull(proxyCredentials);
}
内容来源于网络,如有侵权,请联系作者删除!