类org.apache.commons.httpclient.HttpHost源码实例Demo

下面列出了怎么用org.apache.commons.httpclient.HttpHost的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: alfresco-core   文件: HttpClientFactory.java
/** Get a host for the given parameters. This method need not be thread-safe. */
public HttpHost getHost(String host, int port, String scheme)
{
    if(scheme == null)
    {
        scheme = "http";
    }
    Protocol protocol = protocols.get(scheme);
    if(protocol == null)
    {
        protocol = Protocol.getProtocol("http");
        if(protocol == null)
        {
            throw new IllegalArgumentException("Unrecognised scheme parameter");
        }
    }

    return new HttpHost(host, port, protocol);
}
 
源代码2 项目: hadoop   文件: SwiftRestClient.java
/**
 * Execute a method in a new HttpClient instance.
 * If the auth failed, authenticate then retry the method.
 *
 * @param method methot to exec
 * @param <M> Method type
 * @return the status code
 * @throws IOException on any failure
 */
private <M extends HttpMethod> int exec(M method) throws IOException {
  final HttpClient client = new HttpClient();
  if (proxyHost != null) {
    client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
            new HttpHost(proxyHost, proxyPort));
  }

  int statusCode = execWithDebugOutput(method, client);

  if ((statusCode == HttpStatus.SC_UNAUTHORIZED
          || statusCode == HttpStatus.SC_BAD_REQUEST)
          && method instanceof AuthPostMethod
          && !useKeystoneAuthentication) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Operation failed with status " + method.getStatusCode() +
               " attempting keystone auth");
    }
    //if rackspace key authentication failed - try custom Keystone authentication
    useKeystoneAuthentication = true;
    final AuthPostMethod authentication = (AuthPostMethod) method;
    //replace rackspace auth with keystone one
    authentication.setRequestEntity(getAuthenticationRequst(keystoneAuthRequest));
    statusCode = execWithDebugOutput(method, client);
  }

  if (statusCode == HttpStatus.SC_UNAUTHORIZED ) {
    //unauthed -or the auth uri rejected it.

    if (method instanceof AuthPostMethod) {
        //unauth response from the AUTH URI itself.
        throw new SwiftAuthenticationFailedException(authRequest.toString(),
                                                     "auth",
                                                     authUri,
                                                     method);
    }
    //any other URL: try again
    if (LOG.isDebugEnabled()) {
      LOG.debug("Reauthenticating");
    }
    //re-auth, this may recurse into the same dir
    authenticate();
    if (LOG.isDebugEnabled()) {
      LOG.debug("Retrying original request");
    }
    statusCode = execWithDebugOutput(method, client);
  }
  return statusCode;
}
 
源代码3 项目: big-c   文件: SwiftRestClient.java
/**
 * Execute a method in a new HttpClient instance.
 * If the auth failed, authenticate then retry the method.
 *
 * @param method methot to exec
 * @param <M> Method type
 * @return the status code
 * @throws IOException on any failure
 */
private <M extends HttpMethod> int exec(M method) throws IOException {
  final HttpClient client = new HttpClient();
  if (proxyHost != null) {
    client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
            new HttpHost(proxyHost, proxyPort));
  }

  int statusCode = execWithDebugOutput(method, client);

  if ((statusCode == HttpStatus.SC_UNAUTHORIZED
          || statusCode == HttpStatus.SC_BAD_REQUEST)
          && method instanceof AuthPostMethod
          && !useKeystoneAuthentication) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Operation failed with status " + method.getStatusCode() +
               " attempting keystone auth");
    }
    //if rackspace key authentication failed - try custom Keystone authentication
    useKeystoneAuthentication = true;
    final AuthPostMethod authentication = (AuthPostMethod) method;
    //replace rackspace auth with keystone one
    authentication.setRequestEntity(getAuthenticationRequst(keystoneAuthRequest));
    statusCode = execWithDebugOutput(method, client);
  }

  if (statusCode == HttpStatus.SC_UNAUTHORIZED ) {
    //unauthed -or the auth uri rejected it.

    if (method instanceof AuthPostMethod) {
        //unauth response from the AUTH URI itself.
        throw new SwiftAuthenticationFailedException(authRequest.toString(),
                                                     "auth",
                                                     authUri,
                                                     method);
    }
    //any other URL: try again
    if (LOG.isDebugEnabled()) {
      LOG.debug("Reauthenticating");
    }
    //re-auth, this may recurse into the same dir
    authenticate();
    if (LOG.isDebugEnabled()) {
      LOG.debug("Retrying original request");
    }
    statusCode = execWithDebugOutput(method, client);
  }
  return statusCode;
}
 
public synchronized void setHost(String host, int port, String scheme)
{
    setHost(new HttpHost(host, port, getNewProtocol(host, port, scheme)));
}
 
源代码5 项目: http4e   文件: HttpHostFactory.java
/** Get a host for the given parameters. This method need not be thread-safe. */
public HttpHost getHost(HostConfiguration old, String scheme, String host, int port)
{
    return new HttpHost(host, port, getProtocol(old, scheme, host, port));
}
 
public synchronized void setHost(String host, int port, String scheme) {
    setHost(new HttpHost(host, port, keepProtocol(host, port, scheme)));
}
 
源代码7 项目: sahara-extra   文件: SwiftRestClient.java
/**
 * Execute a method in a new HttpClient instance.
 * If the auth failed, authenticate then retry the method.
 *
 * @param method methot to exec
 * @param <M> Method type
 * @return the status code
 * @throws IOException on any failure
 */
private <M extends HttpMethod> int exec(M method) throws IOException {
  final HttpClient client = new HttpClient();
  if (proxyHost != null) {
    client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
            new HttpHost(proxyHost, proxyPort));
  }

  int statusCode = execWithDebugOutput(method, client);

  if ((statusCode == HttpStatus.SC_UNAUTHORIZED
          || statusCode == HttpStatus.SC_BAD_REQUEST)
          && method instanceof AuthPostMethod
          && !useKeystoneAuthentication) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Operation failed with status " + method.getStatusCode() +
               " attempting keystone auth");
    }
    //if rackspace key authentication failed - try custom Keystone authentication
    useKeystoneAuthentication = true;
    final AuthPostMethod authentication = (AuthPostMethod) method;
    //replace rackspace auth with keystone one
    authentication.setRequestEntity(getAuthenticationRequst(keystoneAuthRequest));
    statusCode = execWithDebugOutput(method, client);
  }

  if (statusCode == HttpStatus.SC_UNAUTHORIZED ) {
    //unauthed -or the auth uri rejected it.

    if (method instanceof AuthPostMethod) {
        //unauth response from the AUTH URI itself.
        throw new SwiftAuthenticationFailedException(authRequest.toString(),
                                                     "auth",
                                                     authUri,
                                                     method);
    }
    //any other URL: try again
    if (LOG.isDebugEnabled()) {
      LOG.debug("Reauthenticating");
    }
    //re-auth, this may recurse into the same dir
    setAuthToken(method, authenticate());
    if (LOG.isDebugEnabled()) {
      LOG.debug("Retrying original request");
    }
    statusCode = execWithDebugOutput(method, client);
  }
  return statusCode;
}
 
 类方法
 同包方法