Package org.apache.commons.httpclient

Examples of org.apache.commons.httpclient.HostConfiguration


    public static Cookie[] createCookieArray(final HttpMethod method,
                                             final Header header)
            throws MalformedCookieException {

        final String path = method.getPath();
        final HostConfiguration hostDetails = method.getHostConfiguration();
        final String host = hostDetails.getHost();
        final int port = hostDetails.getPort();
        final Protocol protocol = hostDetails.getProtocol();
        final boolean isSecure = protocol.isSecure();
        return COOKIE_SPEC.parse(host, port, path, isSecure, header);
    }
View Full Code Here


        URL url = new URL(urlAsString);
        GetMethod method = null;

        if (!"".equals(url.getHost())) {
            HostConfiguration hostConfig = new HostConfiguration();

            hostConfig.setHost(url.getHost(), url.getPort());

            method = new GetMethod();
            method.setHostConfiguration(hostConfig);
            method.setPath(url.getPath());
            method.setRequestHeader(MCS_PROJECT_HEADER, url.toExternalForm());
View Full Code Here

        if (src.isRelativeURI()) {
            throw new ProcessingException("Invalid URL \"" + src.toString() + "\"");
        }

        /* Configure the method with the resolved URL */
        HostConfiguration hc = new HostConfiguration();
        hc.setHost(src);
        this.method.setHostConfiguration(hc);
        this.method.setPath(src.getPath());
        this.method.setQueryString(src.getQuery());

        /* And now process the query string (from the parameters above) */
 
View Full Code Here

        this.qValueFactory = qValueFactory;
        this.itemInfoCacheSize = itemInfoCacheSize;

        try {
            URI repositoryUri = new URI((uri.endsWith("/")) ? uri : uri+"/", true);
            hostConfig = new HostConfiguration();
            hostConfig.setHost(repositoryUri);

            nsCache = new NamespaceCache();
            uriResolver = new URIResolverImpl(repositoryUri, this, DomUtil.createDocument());
            NamePathResolver resolver = new NamePathResolverImpl(nsCache);
View Full Code Here

        this.qValueFactory = qValueFactory;
        this.itemInfoCacheSize = itemInfoCacheSize;

        try {
            URI repositoryUri = computeRepositoryUri(uri);
            hostConfig = new HostConfiguration();
            hostConfig.setHost(repositoryUri);

            nsCache = new NamespaceCache();
            uriResolver = new URIResolverImpl(repositoryUri, this, DomUtil.createDocument());
            NamePathResolver resolver = new NamePathResolverImpl(nsCache);
View Full Code Here

         *  so need to ensure that any items used in its equals/hashcode methods are
         *  not changed after use, i.e.:
         *  host, port, protocol, localAddress, proxy
         * 
        */
    HostConfiguration hc = new HostConfiguration();
    hc.setHost(host, port, protocol); // All needed to ensure re-usablility

        // Set up the local address if one exists
        if (localAddress != null){
            hc.setLocalAddress(localAddress);
        }
       
        boolean useProxy = PROXY_DEFINED && !isNonProxy(host);
        if (useProxy) {
            if (log.isDebugEnabled()){
                log.debug("Setting proxy: "+PROXY_HOST+":"+PROXY_PORT);
            }
            hc.setProxy(PROXY_HOST, PROXY_PORT);
        }
       
        Map map = (Map) httpClients.get();
    HttpClient httpClient = (HttpClient) map.get(hc);
   
View Full Code Here

            HttpClientParams clientParams = client.getParams();
            clientParams.setBooleanParameter( HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true );

            HttpState state = new HttpState();

            HostConfiguration hc = new HostConfiguration();

            client.setHostConfiguration( hc );

            client.setState( state );
View Full Code Here

         *  so need to ensure that any items used in its equals/hashcode methods are
         *  not changed after use, i.e.:
         *  host, port, protocol, localAddress, proxy
         *
        */
        HostConfiguration hc = new HostConfiguration();
        hc.setHost(host, port, protocol); // All needed to ensure re-usablility

        // Set up the local address if one exists
        final InetAddress inetAddr = getIpSourceAddress();
        if (inetAddr != null) {// Use special field ip source address (for pseudo 'ip spoofing')
            hc.setLocalAddress(inetAddr);
        } else {
            hc.setLocalAddress(localAddress); // null means use the default
        }

        final String proxyHost = getProxyHost();
        final int proxyPort = getProxyPortInt();

        boolean useStaticProxy = isStaticProxy(host);
        boolean useDynamicProxy = isDynamicProxy(proxyHost, proxyPort);

        if (useDynamicProxy){
            hc.setProxy(proxyHost, proxyPort);
            useStaticProxy = false; // Dynamic proxy overrules static proxy
        } else if (useStaticProxy) {
            if (log.isDebugEnabled()){
                log.debug("Setting proxy: "+PROXY_HOST+":"+PROXY_PORT);
            }
            hc.setProxy(PROXY_HOST, PROXY_PORT);
        }

        Map<HostConfiguration, HttpClient> map = httpClients.get();
        // N.B. HostConfiguration.equals() includes proxy settings in the compare.
        HttpClient httpClient = map.get(hc);
View Full Code Here

      params.setDefaultMaxConnectionsPerHost(maxThreadsPerHost);
    } else {
      params.setDefaultMaxConnectionsPerHost(maxThreadsTotal);
    }

    HostConfiguration hostConf = client.getHostConfiguration();
    ArrayList headers = new ArrayList();
    // prefer English
    headers.add(new Header("Accept-Language", "en-us,en-gb,en;q=0.7,*;q=0.3"));
    // prefer UTF-8
    headers.add(new Header("Accept-Charset", "utf-8,ISO-8859-1;q=0.7,*;q=0.7"));
    // prefer understandable formats
    headers.add(new Header("Accept",
            "text/html,application/xml;q=0.9,application/xhtml+xml,text/xml;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"));
    // accept gzipped content
    headers.add(new Header("Accept-Encoding", "x-gzip, gzip"));
    hostConf.getParams().setParameter("http.default-headers", headers);
    if (useProxy) {
      hostConf.setProxy(proxyHost, proxyPort);
    }
    if (ntlmUsername.length() > 0) {
      Credentials ntCreds = new NTCredentials(ntlmUsername, ntlmPassword, ntlmHost, ntlmDomain);
      client.getState().setCredentials(new AuthScope(ntlmHost, AuthScope.ANY_PORT), ntCreds);

View Full Code Here

  } else {
      throw new CannotExecuteException
    ("First parameter must be \"GET\" or \"POST\", is \""
     + methodParm + "\"");
  }
  HostConfiguration hc = method.getHostConfiguration();
  if (hc != null && proxyHost != null) {
      if (nonProxyHostsPattern == null
    || !nonProxyHostsPattern.matcher(hc.getHost()).matches ()) {
    if (logger.isDebugEnabled()) {
        logger.debug ("Using proxy to access " + url);
    }
    hc.setProxy(proxyHost, proxyPort);
      } else {
    if (logger.isDebugEnabled()) {
        logger.debug ("Accessing " + url + " directly");
    }
      }   
  }
  if (authenticate) {
      client.getState().setCredentials
    (realm, hc.getHost (),
     new UsernamePasswordCredentials (username, password));
  }
  int statusCode = -1;
  try {
      for (int attempts = 0; attempts < 3; attempts += 1) {
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.HostConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.