Search in sources :

Example 6 with HostConfiguration

use of org.apache.commons.httpclient.HostConfiguration in project pinpoint by naver.

the class HttpClientIT method hostConfig.

@Test
public void hostConfig() throws Exception {
    HttpClient client = new HttpClient();
    client.getParams().setConnectionManagerTimeout(CONNECTION_TIMEOUT);
    client.getParams().setSoTimeout(SO_TIMEOUT);
    HostConfiguration config = new HostConfiguration();
    config.setHost("weather.naver.com", 80, "http");
    GetMethod method = new GetMethod("/rgn/cityWetrMain.nhn");
    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
    method.setQueryString(new NameValuePair[] { new NameValuePair("key2", "value2") });
    try {
        // Execute the method.
        client.executeMethod(config, method);
    } catch (Exception ignored) {
    } finally {
        method.releaseConnection();
    }
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) HostConfiguration(org.apache.commons.httpclient.HostConfiguration) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) DefaultHttpMethodRetryHandler(org.apache.commons.httpclient.DefaultHttpMethodRetryHandler) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) Test(org.junit.Test)

Example 7 with HostConfiguration

use of org.apache.commons.httpclient.HostConfiguration in project zaproxy by zaproxy.

the class HttpSender method executeMethod.

public int executeMethod(HttpMethod method, HttpState state) throws IOException {
    int responseCode = -1;
    String hostName;
    hostName = method.getURI().getHost();
    method.setDoAuthentication(true);
    HostConfiguration hc = null;
    HttpClient requestClient;
    if (isConnectionUpgrade(method)) {
        requestClient = new HttpClient(new ZapHttpConnectionManager());
        if (param.isUseProxy(hostName)) {
            requestClient.getHostConfiguration().setProxy(param.getProxyChainName(), param.getProxyChainPort());
            if (param.isUseProxyChainAuth()) {
                requestClient.getState().setProxyCredentials(getAuthScope(param), getNTCredentials(param));
            }
        }
    } else if (param.isUseProxy(hostName)) {
        requestClient = clientViaProxy;
    } else {
        requestClient = client;
    }
    if (this.initiator == CHECK_FOR_UPDATES_INITIATOR) {
        // Use the 'strict' SSLConnector, ie one that performs all the usual cert checks
        // The 'standard' one 'trusts' everything
        // This is to ensure that all 'check-for update' calls are made to the expected https urls
        // without this is would be possible to intercept and change the response which could result
        // in the user downloading and installing a malicious add-on
        hc = new HostConfiguration() {

            @Override
            public synchronized void setHost(URI uri) {
                try {
                    setHost(new HttpHost(uri.getHost(), uri.getPort(), getProtocol()));
                } catch (URIException e) {
                    throw new IllegalArgumentException(e.toString());
                }
            }

            ;
        };
        hc.setHost(hostName, method.getURI().getPort(), new Protocol("https", (ProtocolSocketFactory) new SSLConnector(false), 443));
        if (param.isUseProxy(hostName)) {
            hc.setProxyHost(new ProxyHost(param.getProxyChainName(), param.getProxyChainPort()));
            if (param.isUseProxyChainAuth()) {
                requestClient.getState().setProxyCredentials(getAuthScope(param), getNTCredentials(param));
            }
        }
    }
    // ZAP: Check if a custom state is being used
    if (state != null) {
        // Make sure cookies are enabled
        method.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
    }
    responseCode = requestClient.executeMethod(hc, method, state);
    return responseCode;
}
Also used : HostConfiguration(org.apache.commons.httpclient.HostConfiguration) ZapHttpConnectionManager(org.zaproxy.zap.ZapHttpConnectionManager) URI(org.apache.commons.httpclient.URI) ProtocolSocketFactory(org.apache.commons.httpclient.protocol.ProtocolSocketFactory) URIException(org.apache.commons.httpclient.URIException) HttpHost(org.apache.commons.httpclient.HttpHost) HttpClient(org.apache.commons.httpclient.HttpClient) ProxyHost(org.apache.commons.httpclient.ProxyHost) Protocol(org.apache.commons.httpclient.protocol.Protocol)

Example 8 with HostConfiguration

use of org.apache.commons.httpclient.HostConfiguration in project maven-plugins by apache.

the class ClassicJiraDownloader method doExecute.

/**
     * Execute the query on the JIRA server.
     *
     * @throws Exception on error
     */
public void doExecute() throws Exception {
    try {
        HttpClient client = new HttpClient();
        // MCHANGES-89 Allow circular redirects
        HttpClientParams clientParams = client.getParams();
        clientParams.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
        // MCHANGES-237
        clientParams.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
        HttpState state = new HttpState();
        HostConfiguration hc = new HostConfiguration();
        client.setHostConfiguration(hc);
        client.setState(state);
        String baseUrl = JiraHelper.getBaseUrl(project.getIssueManagement().getUrl());
        getLog().debug("JIRA lives at: " + baseUrl);
        // Here we only need the host part of the URL
        determineProxy(baseUrl, client);
        prepareBasicAuthentication(client);
        boolean jiraAuthenticationSuccessful = false;
        if (isJiraAuthenticationConfigured()) {
            // Here we only need the parts up to and including the host part of the URL
            jiraAuthenticationSuccessful = doJiraAuthentication(client, baseUrl);
        }
        if ((isJiraAuthenticationConfigured() && jiraAuthenticationSuccessful) || !isJiraAuthenticationConfigured()) {
            String fullUrl;
            if (useJql) {
                fullUrl = getJqlQueryURL();
            } else {
                fullUrl = getParameterBasedQueryURL(client);
            }
            if (log.isDebugEnabled()) {
                log.debug("download jira issues from url " + fullUrl);
            }
            // execute the GET
            download(client, fullUrl);
        }
    } catch (Exception e) {
        if (project.getIssueManagement() != null) {
            getLog().error("Error accessing " + project.getIssueManagement().getUrl(), e);
        } else {
            getLog().error("Error accessing mock project issues", e);
        }
    }
}
Also used : HostConfiguration(org.apache.commons.httpclient.HostConfiguration) HttpClient(org.apache.commons.httpclient.HttpClient) HttpClientParams(org.apache.commons.httpclient.params.HttpClientParams) HttpState(org.apache.commons.httpclient.HttpState) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Aggregations

HostConfiguration (org.apache.commons.httpclient.HostConfiguration)8 HttpClient (org.apache.commons.httpclient.HttpClient)8 NameValuePair (org.apache.commons.httpclient.NameValuePair)3 GetMethod (org.apache.commons.httpclient.methods.GetMethod)3 IOException (java.io.IOException)2 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)2 PostMethod (org.apache.commons.httpclient.methods.PostMethod)2 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)1 InputStream (java.io.InputStream)1 TransportClientProperties (org.apache.axis.components.net.TransportClientProperties)1 Credentials (org.apache.commons.httpclient.Credentials)1 DefaultHttpMethodRetryHandler (org.apache.commons.httpclient.DefaultHttpMethodRetryHandler)1 HttpException (org.apache.commons.httpclient.HttpException)1 HttpHost (org.apache.commons.httpclient.HttpHost)1 HttpState (org.apache.commons.httpclient.HttpState)1 ProxyHost (org.apache.commons.httpclient.ProxyHost)1 URI (org.apache.commons.httpclient.URI)1 URIException (org.apache.commons.httpclient.URIException)1 HttpClientParams (org.apache.commons.httpclient.params.HttpClientParams)1 Protocol (org.apache.commons.httpclient.protocol.Protocol)1