org.apache.commons.httpclient.HttpClient.getHostConfiguration()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(206)

本文整理了Java中org.apache.commons.httpclient.HttpClient.getHostConfiguration()方法的一些代码示例,展示了HttpClient.getHostConfiguration()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient.getHostConfiguration()方法的具体详情如下:
包路径:org.apache.commons.httpclient.HttpClient
类名称:HttpClient
方法名:getHostConfiguration

HttpClient.getHostConfiguration介绍

[英]Returns the HostConfiguration associated with the HttpClient.
[中]返回与HttpClient关联的主机配置。

代码示例

代码示例来源:origin: jenkinsci/jenkins

client.getHostConfiguration().setProxy(name, port);
Credentials credentials = createCredentials(userName, password);
AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT);

代码示例来源:origin: openhab/openhab1-addons

client.getHostConfiguration().setProxy(proxyHost, proxyPort);
if (StringUtils.isNotBlank(proxyUser)) {
  client.getState().setProxyCredentials(AuthScope.ANY,

代码示例来源:origin: commons-httpclient/commons-httpclient

throw new IllegalArgumentException("HttpMethod parameter may not be null");
HostConfiguration defaulthostconfig = getHostConfiguration();
if (hostconfig == null) {
  hostconfig = defaulthostconfig;

代码示例来源:origin: apache/cloudstack

/**
 * @param username
 * @param password
 * @param httpClient
 */
public static void setCredentials(String username, String password, HttpClient httpClient) {
  if (username != null && password != null && httpClient != null) {
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Setting credentials with username " + username + " for host " + httpClient.getHostConfiguration().getHost() + ":" + httpClient.getHostConfiguration().getPort());
    }
    httpClient.getParams().setAuthenticationPreemptive(true);
    httpClient.getState().setCredentials(
        new AuthScope(httpClient.getHostConfiguration().getHost(), httpClient.getHostConfiguration().getPort(), AuthScope.ANY_REALM), new UsernamePasswordCredentials(username, password));
  }
}

代码示例来源:origin: geotools/geotools

"Found 'http.proxyHost' Java System property. Using it as proxy server. Port: "
        + proxyPort);
HostConfiguration hostConfig = client.getHostConfiguration();
if (nonProxyHostProp != null) {
  if (nonProxyHostProp.startsWith("\"")) {

代码示例来源:origin: geotools/geotools

"Found 'http.proxyHost' Java System property. Using it as proxy server. Port: "
        + proxyPort);
HostConfiguration hostConfig = client.getHostConfiguration();
hostConfig.setProxy(proxyHost, proxyPort);

代码示例来源:origin: apache/cloudstack

/**
 * @param proxy
 * @param httpClient
 */
public static void setProxy(Proxy proxy, HttpClient httpClient) {
  if (proxy != null && httpClient != null) {
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Setting proxy with host " + proxy.getHost() + " and port " + proxy.getPort() + " for host " + httpClient.getHostConfiguration().getHost() + ":" + httpClient.getHostConfiguration().getPort());
    }
    httpClient.getHostConfiguration().setProxy(proxy.getHost(), proxy.getPort());
    if (proxy.getUserName() != null && proxy.getPassword() != null) {
      httpClient.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxy.getUserName(), proxy.getPassword()));
    }
  }
}

代码示例来源:origin: apache/cloudstack

private void checkProxy(Proxy proxy) {
  if (proxy != null) {
    client.getHostConfiguration().setProxy(proxy.getHost(), proxy.getPort());
    if (proxy.getUserName() != null) {
      Credentials proxyCreds = new UsernamePasswordCredentials(proxy.getUserName(), proxy.getPassword());
      client.getState().setProxyCredentials(AuthScope.ANY, proxyCreds);
    }
  }
}

代码示例来源:origin: foxinmy/weixin4j

private void resolveHttpParams(HttpParams params) {
  if (params != null) {
    if (params.getProxy() != null) {
      InetSocketAddress socketAddress = (InetSocketAddress) params
          .getProxy().address();
      httpClient.getHostConfiguration().setProxy(
          socketAddress.getHostName(), socketAddress.getPort());
    }
    if (params.getSSLContext() != null) {
      Protocol.registerProtocol("https", new Protocol("https",
          new SSLProtocolSocketFactory(params.getSSLContext()),
          443));
    }
    httpClient.getHttpConnectionManager().getParams()
        .setConnectionTimeout(params.getConnectTimeout());
  }
}

代码示例来源:origin: org.netpreserve.openwayback.access-control/access-control-core

@Override
  public void setRobotProxy(String host, int port) {
    http.getHostConfiguration().setProxy(host, port);
  }
}

代码示例来源:origin: edu.ucar/netcdf

void
setProxy(Proxy proxy)
{
  if(sessionClient == null) return;
  if(proxy != null && proxy.host != null)
    sessionClient.getHostConfiguration().setProxy(proxy.host, proxy.port);
}

代码示例来源:origin: org.nuiton/maven-helper-plugin

protected String getUri(String... paths) {
  String uri = client.getHostConfiguration().getHostURL();
  for (String path : paths) {
    uri += '/' + path;
  }
  return uri;
}

代码示例来源:origin: org.dasein/dasein-persist

private HttpClient getClient() {
  HttpClient client = new HttpClient();
  
  if( proxyHost != null ) {
    client.getHostConfiguration().setProxy(proxyHost, proxyPort);
  }
  return client;
}

代码示例来源:origin: org.swordapp/sword-common

/**
 * Create a new Client. The client will not use authentication by default.
 */
public Client() {
  client = new HttpClient();
  client.getParams().setParameter("http.socket.timeout",
      new Integer(DEFAULT_TIMEOUT));
  log.debug("proxy host: " + client.getHostConfiguration().getProxyHost());
  log.debug("proxy port: " + client.getHostConfiguration().getProxyPort());
  doAuthentication = false;
}

代码示例来源:origin: org.alfresco/alfresco-core

protected HttpClient getDefaultHttpClient(String httpHost, int httpPort)
{
  HttpClient httpClient = constructHttpClient();
  httpClient.getHostConfiguration().setHost(httpHost, httpPort);
  return httpClient;
}

代码示例来源:origin: org.nuiton/maven-helper-plugin

protected HttpConnection getConnection() {
  return client.getHttpConnectionManager().getConnection(
      client.getHostConfiguration()
  );
}

代码示例来源:origin: digital-preservation/droid

/**
 * {@inheritDoc}
 */
@Override
public void onProxyChange(ProxySettings proxySettings) {
  
  if (proxySettings.isEnabled()) {
    client = new HttpClient();
    client.getHostConfiguration().setProxy(proxySettings.getProxyHost(), proxySettings.getProxyPort());
  } else {
    client = new HttpClient();
  }
  
}

代码示例来源:origin: org.n52.security/52n-security-facade

private void initHttpClient() {
  m_client = new HttpClient();
  ProxyManager proxyManager = new ProxyManager();
  ProxyHost proxy = proxyManager.getProxyHost(getURL());
  if (proxy != null) {
    LOG.debug("for server " + getURL() + " using proxy: '" + proxy.getHostName() + "'");
  } else {
    LOG.debug("for server " + getURL() + " not using proxy!");
  }
  m_client.getHostConfiguration().setProxyHost(proxy);
  m_client.getState().setProxyCredentials(AuthScope.ANY, proxyManager.getProxyCredentials(getURL()));
}

代码示例来源:origin: org.sonatype.nexus/nexus-proxy

protected void updateContext( ProxyRepository repository, RemoteStorageContext ctx )
{
  HttpClient httpClient = new HttpClient( new CustomMultiThreadedHttpConnectionManager() );
  HttpClientProxyUtil.applyProxyToHttpClient( httpClient, ctx, getLogger() );
  ctx.putContextObject( CTX_KEY_CLIENT, httpClient );
  ctx.putContextObject( CTX_KEY_HTTP_CONFIGURATION, httpClient.getHostConfiguration() );
  // NEXUS-3338: we don't know afer config change is remote S3 (url changed maybe)
  ctx.putContextObject( CTX_KEY_S3_FLAG, new BooleanFlagHolder() );
}

代码示例来源:origin: org.alfresco/alfresco-core

protected HttpClient getHttpsClient(String httpsHost, int httpsPort)
{
  // Configure a custom SSL socket factory that will enforce mutual authentication
  HttpClient httpClient = constructHttpClient();
  HttpHostFactory hostFactory = new HttpHostFactory(new Protocol("https", sslSocketFactory, httpsPort));
  httpClient.setHostConfiguration(new HostConfigurationWithHostFactory(hostFactory));
  httpClient.getHostConfiguration().setHost(httpsHost, httpsPort, "https");
  return httpClient;
}

相关文章