Package org.apache.commons.httpclient

Examples of org.apache.commons.httpclient.HostConfiguration


            AuthScope scope = new AuthScope( host, port );
            client.getState().setCredentials( scope, creds );
        }

        HostConfiguration hc = new HostConfiguration();

        ProxyInfo proxyInfo = getProxyInfo( getRepository().getProtocol(), getRepository().getHost() );
        if ( proxyInfo != null )
        {
            String proxyUsername = proxyInfo.getUserName();
            String proxyPassword = proxyInfo.getPassword();
            String proxyHost = proxyInfo.getHost();
            int proxyPort = proxyInfo.getPort();
            String proxyNtlmHost = proxyInfo.getNtlmHost();
            String proxyNtlmDomain = proxyInfo.getNtlmDomain();
            if ( proxyHost != null )
            {
                hc.setProxy( proxyHost, proxyPort );

                if ( proxyUsername != null && proxyPassword != null )
                {
                    Credentials creds;
                    if ( proxyNtlmHost != null || proxyNtlmDomain != null )
                    {
                        creds = new NTCredentials( proxyUsername, proxyPassword, proxyNtlmHost, proxyNtlmDomain );
                    }
                    else
                    {
                        creds = new UsernamePasswordCredentials( proxyUsername, proxyPassword );
                    }

                    int port = proxyInfo.getPort() > -1 ? proxyInfo.getPort() : AuthScope.ANY_PORT;

                    AuthScope scope = new AuthScope( proxyHost, port );
                    client.getState().setProxyCredentials( scope, creds );
                }
            }
        }

        hc.setHost( host );

        //start a session with the webserver
        client.setHostConfiguration( hc );
    }
View Full Code Here


            }
        });

        params.setConnectionManagerTimeout(settings.getHttpTimeout());
        params.setSoTimeout((int) settings.getHttpTimeout());
        HostConfiguration hostConfig = new HostConfiguration();

        hostConfig = setupSSLIfNeeded(settings, hostConfig);
        hostConfig = setupSocksProxy(settings, hostConfig);
        Object[] authSettings = setupHttpProxy(settings, hostConfig);
        hostConfig = (HostConfiguration) authSettings[0];

        try {
            hostConfig.setHost(new URI(escapeUri(host, settings.getNetworkSSLEnabled()), false));
        } catch (IOException ex) {
            throw new EsHadoopTransportException("Invalid target URI " + host, ex);
        }
        client = new HttpClient(params, new SocketTrackingConnectionManager());
        client.setHostConfiguration(hostConfig);
View Full Code Here

        }
        assertEquals(0, errors.size());
    }

    protected void checkHtmlPage(HttpClient client, URL url) throws IOException {
        client.setHostConfiguration(new HostConfiguration());
        client.getHostConfiguration().setHost(url.getHost(), url.getPort());
        GetMethod get = new GetMethod("");
        get.getParams().setVersion(HttpVersion.HTTP_1_1);
        client.executeMethod(get);
        String str = get.getResponseBodyAsString();
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

    private static void copyHttpMethodBase(
      HttpMethodBase m, HttpMethodBase copy) {
        if (m.getHostConfiguration() != null) {
            copy.setHostConfiguration(
              new HostConfiguration(m.getHostConfiguration()));
        }
        try {
            copy.setParams((HttpMethodParams)m.getParams().clone());
        } catch (CloneNotSupportedException e) {
            // Should never happen
View Full Code Here

   
    if (System.getProperty("http.proxyHost") != null)
    {
      String proxyHost = System.getProperty("http.proxyHost");
      int proxyPort = Integer.parseInt(System.getProperty("http.proxyPort"));
      HostConfiguration config = httpClient.getHostConfiguration();
      if (config == null) {
        config = new HostConfiguration();
      }
      config.setProxy(proxyHost, proxyPort);
      httpClient.setHostConfiguration(config);
    }
   
    session.setAttribute( HTTP_CLIENT, httpClient );
  }
View Full Code Here

        if (reset || client == null) {
            client = new HttpClient();
            // Set a state which allows lock tracking
            client.setState(new WebdavState());
            HostConfiguration hostConfig = client.getHostConfiguration();
            hostConfig.setHost(httpURL);
            if (proxyHost != null && proxyPort > 0)
                hostConfig.setProxy(proxyHost, proxyPort);

            String userName = httpURL.getUser();
            if (userName != null && userName.length() > 0) {
                String password = httpURL.getPassword();
                HttpState clientState = client.getState();
View Full Code Here

        defaults.add(new Header("this-header", "value1"));
        defaults.add(new Header("that-header", "value1"));
        defaults.add(new Header("that-header", "value2"));
        defaults.add(new Header("User-Agent", "test"));

        HostConfiguration hostconfig = new HostConfiguration();
        hostconfig.setHost(
                this.server.getLocalAddress(),
                this.server.getLocalPort(),
                Protocol.getProtocol("http"));
        hostconfig.getParams().setParameter(HostParams.DEFAULT_HEADERS, defaults);
       
        GetMethod httpget = new GetMethod("/miss/");
        try {
            this.client.executeMethod(hostconfig, httpget);
        } finally {
View Full Code Here

        Log wireLog = LogFactory.getLog("httpclient.wire");
       
        URI url = new HttpURL(request.getRequestLine().getUri());

        HttpClient client = new HttpClient();
        HostConfiguration hc = new HostConfiguration();
        hc.setHost(url);
        client.setHostConfiguration(hc);
       
        //TODO support other methods
        HttpMethod method = new GetMethod(url.getPathQuery());
        Header[] headers = request.getHeaders();
View Full Code Here

                String name = (String) e.nextElement();
                httpMethod.addRequestHeader(name, request.getHeader(name));
                log.debug("Header Name=" + name + "value=" + request.getHeader(name));
            }

            HostConfiguration hostConfiguration = new HostConfiguration();
            hostConfiguration.setHost(url.getHost(), url.getPort(), url.getProtocol());

            log.debug("\n----------------------------------------------------------------"
                    + "\n- Starting session at URI: " + url + "\n- Host:                    "
                    + url.getHost() + "\n- Port:                    " + url.getPort()
                    + "\n----------------------------------------------------------------");
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.