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

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

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

HttpClient.getParams介绍

[英]Returns HttpClientParams associated with this HttpClient.
[中]返回与此HttpClient关联的HttpClientParams。

代码示例

代码示例来源:origin: elastic/elasticsearch-hadoop

private void completeAuth(Object[] authSettings) {
  if (authSettings[1] != null) {
    client.setState((HttpState) authSettings[1]);
    client.getParams().setAuthenticationPreemptive(true);
  }
}

代码示例来源:origin: apache/incubator-gobblin

@Override
public HttpClient create() throws Exception {
 HttpClient client = new HttpClient();
 if (soTimeout >= 0) {
  client.getParams().setSoTimeout(soTimeout);
 }
 if (connTimeout >= 0) {
  client.getHttpConnectionManager().getParams().setConnectionTimeout(connTimeout);
 }
 return client;
}

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

client.getParams().setAuthenticationPreemptive(true);
client.getState().setCredentials(AuthScope.ANY, credentials);

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

public HttpComponent3Factory() {
  httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
  httpClient.getParams().setHttpElementCharset(Consts.UTF_8.name());
  httpClient.getParams().setParameter("http.protocol.uri-charset",
      Consts.UTF_8.name());
  // httpMethod.getParams().setUriCharset(Consts.UTF_8.name());
  httpClient.getParams().setContentCharset(Consts.UTF_8.name());
  Protocol.registerProtocol("https",
      new Protocol("https", new SSLProtocolSocketFactory(
          HttpClientFactory.allowSSLContext()), 443));
}

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

private void resetCredentials() {
  client.getState().clearCredentials();
  if (user != null && password != null) {
    AuthScope authscope = AuthScope.ANY;
    Credentials credentials = new UsernamePasswordCredentials(user, password);
    client.getParams().setAuthenticationPreemptive(true);
    client.getState().setCredentials(authscope, credentials);
  } else {
    client.getParams().setAuthenticationPreemptive(false);
  }
}

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

private void resetCredentials() {
  client.getState().clearCredentials();
  if (user != null && password != null) {
    AuthScope authscope = AuthScope.ANY;
    Credentials credentials = new UsernamePasswordCredentials(user, password);
    client.getParams().setAuthenticationPreemptive(true);
    client.getState().setCredentials(authscope, credentials);
  } else {
    client.getParams().setAuthenticationPreemptive(false);
  }
}

代码示例来源:origin: KylinOLAP/Kylin

private void init(String host, int port, String userName, String password) {
  this.host = host;
  this.port = port;
  this.userName = userName;
  this.password = password;
  this.baseUrl = "http://" + host + ":" + port + "/kylin/api";
  client = new HttpClient();
  if (userName != null && password != null) {
    client.getParams().setAuthenticationPreemptive(true);
    Credentials creds = new UsernamePasswordCredentials(userName, password);
    client.getState().setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM), creds);
  }
}

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

protected NeutronRestApi(final Class<? extends HttpMethodBase> httpClazz, final String protocol, final int port) {
  client = createHttpClient();
  client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
  this.httpClazz = httpClazz;
  try {
    // Cast to ProtocolSocketFactory to avoid the deprecated constructor
    // with the SecureProtocolSocketFactory parameter
    Protocol.registerProtocol(protocol, new Protocol(protocol, (ProtocolSocketFactory) new TrustingProtocolSocketFactory(), HTTPS_PORT));
  } catch (IOException e) {
    s_logger.warn("Failed to register the TrustingProtocolSocketFactory, falling back to default SSLSocketFactory", e);
  }
}

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

public BigSwitchBcfApi() {
  _client = createHttpClient();
  _client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
  try {
    // Cast to ProtocolSocketFactory to avoid the deprecated constructor with the SecureProtocolSocketFactory parameter
    Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) new TrustingProtocolSocketFactory(), _port));
  } catch (IOException e) {
    S_LOGGER.warn("Failed to register the TrustingProtocolSocketFactory, falling back to default SSLSocketFactory", e);
  }
}

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

public static InputStream getInputStreamFromUrl(String url, String user, String password) {
  try {
    Pair<String, Integer> hostAndPort = validateUrl(url);
    HttpClient httpclient = new HttpClient(new MultiThreadedHttpConnectionManager());
    if ((user != null) && (password != null)) {
      httpclient.getParams().setAuthenticationPreemptive(true);
      Credentials defaultcreds = new UsernamePasswordCredentials(user, password);
      httpclient.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds);
      s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second());
    }
    // Execute the method.
    GetMethod method = new GetMethod(url);
    int statusCode = httpclient.executeMethod(method);
    if (statusCode != HttpStatus.SC_OK) {
      s_logger.error("Failed to read from URL: " + url);
      return null;
    }
    return method.getResponseBodyAsStream();
  } catch (Exception ex) {
    s_logger.error("Failed to read from URL: " + url);
    return null;
  }
}

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

private void checkCredentials(String user, String password) {
  try {
    Pair<String, Integer> hostAndPort = UriUtils.validateUrl(downloadUrl);
    if ((user != null) && (password != null)) {
      client.getParams().setAuthenticationPreemptive(true);
      Credentials defaultcreds = new UsernamePasswordCredentials(user, password);
      client.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds);
      s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second());
    } else {
      s_logger.info("No credentials configured for host=" + hostAndPort.first() + ":" + hostAndPort.second());
    }
  } catch (IllegalArgumentException iae) {
    errorString = iae.getMessage();
    status = TemplateDownloader.Status.UNRECOVERABLE_ERROR;
    inited = false;
  }
}

代码示例来源: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: naver/ngrinder

@Ignore
  @Test
  public void testRestAPI() throws IOException {
    HttpClient client = new HttpClient();
    // To be avoided unless in debug mode
    Credentials defaultcreds = new UsernamePasswordCredentials("admin", "111111");
    client.getParams().setAuthenticationPreemptive(true);
    client.getState().setCredentials(AuthScope.ANY, defaultcreds);
    PutMethod method = new PutMethod("http://localhost:8080/agent/api/36");
    final HttpMethodParams params = new HttpMethodParams();
    params.setParameter("action", "approve");
    method.setParams(params);
    final int i = client.executeMethod(method);
    System.out.println(method.getResponseBodyAsString());
  }
}

代码示例来源:origin: org.apache.abdera/abdera-client

/**
 * Configure the client to use preemptive authentication (HTTP Basic Authentication only)
 */
public AbderaClient usePreemptiveAuthentication(boolean val) {
  client.getParams().setAuthenticationPreemptive(val);
  return this;
}

代码示例来源:origin: org.apache.abdera/abdera-client

/**
 * Return the socket timeout for the connection in milliseconds A timeout value of zero is interpreted as an
 * infinite timeout.
 */
public int getSocketTimeout() {
  return client.getParams().getSoTimeout();
}

代码示例来源:origin: org.apache.abdera/abdera-client

/**
 * Get the maximum number of redirects
 */
public int getMaximumRedirects() {
  return client.getParams().getIntParameter(HttpClientParams.MAX_REDIRECTS, DEFAULT_MAX_REDIRECTS);
}

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

public void setUserAgent(String agent)
{
  useragent = agent;
  if(useragent != null && sessionClient != null)
    sessionClient.getParams().setParameter(USER_AGENT, useragent);
}

代码示例来源:origin: rometools/rome

@Override
  public void addAuthentication(final HttpClient httpClient, final HttpMethodBase method) throws ProponoException {
    httpClient.getParams().setAuthenticationPreemptive(true);
    final String header = "Basic " + credentials;
    method.setRequestHeader("Authorization", header);
  }
}

代码示例来源:origin: rometools/rome

@Override
  public void addAuthentication(final HttpClient httpClient, final HttpMethodBase method) throws ProponoException {
    httpClient.getParams().setAuthenticationPreemptive(true);
    method.setRequestHeader("Authorization", authToken);
  }
}

代码示例来源:origin: org.springframework.ws/spring-ws-core

@Override
public void afterPropertiesSet() throws Exception {
  if (getCredentials() != null) {
    getHttpClient().getState().setCredentials(getAuthScope(), getCredentials());
    getHttpClient().getParams().setAuthenticationPreemptive(true);
  }
}

相关文章