Package org.apache.commons.httpclient

Examples of org.apache.commons.httpclient.HostConfiguration


        final int maxTotalConnections = 1234 ;
        final Properties properties = getProperties(Integer.toString(maxTotalConnections), null) ;
        final HttpClient httpClient = HttpClientFactory.createHttpClient(properties) ;
        try
        {
            final HostConfiguration configuration = httpClient.getHostConfiguration() ;
            final HttpConnectionManagerParams params = httpClient.getHttpConnectionManager().getParams() ;
            assertEquals("MAX_TOTAL_CONNECTIONS not set", maxTotalConnections, params.getMaxTotalConnections()) ;
            assertTrue("maxConnectionsPerHost identical", maxTotalConnections !=  params.getMaxConnectionsPerHost(configuration)) ;
        }
        finally
View Full Code Here


        final Properties properties = getProperties(null, Integer.toString(maxConnectionsPerHost)) ;
       
        final HttpClient httpClient = HttpClientFactory.createHttpClient(properties) ;
        try
        {
            final HostConfiguration configuration = httpClient.getHostConfiguration() ;
            final HttpConnectionManagerParams params = httpClient.getHttpConnectionManager().getParams() ;
            assertEquals("MAX_CONNECTIONS_PER_HOST not set", maxConnectionsPerHost, params.getMaxConnectionsPerHost(configuration)) ;
            assertTrue("maxTotalConnections identical", maxConnectionsPerHost !=  params.getMaxTotalConnections()) ;
        }
        finally
View Full Code Here

        try
        {
            final HttpClient secondHttpClient = HttpClientFactory.createHttpClient(secondProperties) ;
            try
            {
                final HostConfiguration firstConfiguration = firstHttpClient.getHostConfiguration() ;
                final HttpConnectionManagerParams firstParams = firstHttpClient.getHttpConnectionManager().getParams() ;
                final HttpConnectionManager firstConnectionManager = firstHttpClient.getHttpConnectionManager() ;
               
                assertEquals("MAX_TOTAL_CONNECTIONS not set", firstMaxTotalConnections, firstParams.getMaxTotalConnections()) ;
                assertEquals("MAX_CONNECTIONS_PER_HOST not set", firstMaxConnectionsPerHost, firstParams.getMaxConnectionsPerHost(firstConfiguration)) ;
                assertNotNull("connection manager is null", firstConnectionManager) ;
                assertEquals("connection manager is not correct type", ESBMultiThreadedHttpConnectionManager.class, firstConnectionManager.getClass()) ;
                assertNotNull("HostConfiguration is null", ((ESBMultiThreadedHttpConnectionManager)firstConnectionManager).getHostConfiguration()) ;
               
                final HostConfiguration secondConfiguration = secondHttpClient.getHostConfiguration() ;
                final HttpConnectionManagerParams secondParams = secondHttpClient.getHttpConnectionManager().getParams() ;
                final HttpConnectionManager secondConnectionManager = secondHttpClient.getHttpConnectionManager() ;
               
                assertEquals("MAX_TOTAL_CONNECTIONS not set", secondMaxTotalConnections, secondParams.getMaxTotalConnections()) ;
                assertEquals("MAX_CONNECTIONS_PER_HOST not set", secondMaxConnectionsPerHost, secondParams.getMaxConnectionsPerHost(secondConfiguration)) ;
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

        if (this.proxyUrl != null) {
            if (log.isDebugEnabled()) {
                log.debug("Configuring HTTP proxy. url [" + this.proxyUrl + "]; port [" + this.proxyPort + "]");
            }

            HostConfiguration hostConfiguration = client.getHostConfiguration();
            hostConfiguration.setProxy(this.proxyUrl, this.proxyPort);

            // If a proxy username was specified, indicate it as the proxy credentials
            if (this.proxyUsername != null) {
                if (log.isDebugEnabled()) {
                    log.debug("Configuring feed for authenticating proxy. proxy-user: " + this.proxyUsername);
View Full Code Here

     */
    private void configureProxy(HttpClient client) {
        // If a proxy URL was specified, configure the client for proxy support
        if (proxyUrl != null) {
            log.debug("Configuring feed for proxy. URL: " + proxyUrl + ", Port: " + proxyPort);
            HostConfiguration hostConfiguration = client.getHostConfiguration();
            hostConfiguration.setProxy(proxyUrl, proxyPort);

            // If a proxy username was specified, indicate it as the proxy credentials
            if (proxyUsername != null) {
                log.debug("Configuring feed for authenticating proxy. User: " + proxyUsername);
                AuthScope proxyAuthScope = new AuthScope(proxyUrl, proxyPort, AuthScope.ANY_REALM);
View Full Code Here

            try
            {
                file_post.addParameter("swf", selected_file);
                HttpClient client = new HttpClient();
                client.getState().setCredentials("realm", new UsernamePasswordCredentials(remote_config.getProperty("remote_user"), remote_config.getProperty("remote_pwd")));
                HostConfiguration hc = new HostConfiguration();
                file_post.setDoAuthentication(true);
                hc.setHost(new URI(remote_url));
                client.setHostConfiguration(hc);
                int status = client.executeMethod(file_post);
                file_post.releaseConnection();

                if (status == 200)
View Full Code Here

     * Initialise the method so that it will connect to the mock server.
     *
     * @param method The method to initialise.
     */
    private void initialiseMethod(HttpMethodBase method) {
        HostConfiguration configuration = new HostConfiguration();
        configuration.setHost("localhost", serverMock.getServerPort(), "http");
        method.setHostConfiguration(configuration);
    }
View Full Code Here

        builder.setConnectionTimeout(timeout);
        builder.setRoundTripTimeout(timeout);
        final HttpClient httpClient = builder.buildHttpClient();

        final GetMethod method = new GetMethod(url.toExternalForm());
        final HostConfiguration configuration = new HostConfiguration();
        configuration.setHost(url.getHost(), url.getPort(), url.getProtocol());
        method.setHostConfiguration(configuration);
        method.setFollowRedirects(true);

        // Get the proxy config to use for the host.
        final Proxy proxy = manager.getProxy(url.getHost());
        if (proxy != null) {
            configuration.setProxy(proxy.getHost(), proxy.getPort());

            if (proxy.useAuthorization()) {
                method.setDoAuthentication(true);

                // mock up a authentication challenge so we can get
View Full Code Here

    // Javadoc inherited.
    public HttpStatusCode executeMethod(HttpMethod method)
            throws IOException {

        HostConfiguration configuration = method.getHostConfiguration();
        if (configuration == null) {
            throw new IllegalStateException("No configuration set on method");
        }

        Protocol originalProtocol = configuration.getProtocol();
        Protocol protocol = updateProtocol(originalProtocol);
        if (protocol != originalProtocol) {
            configuration.setHost(configuration.getHost(),
                    configuration.getVirtualHost(),
                    configuration.getPort(),
                    protocol);
        }

        // Get the connection from the manager, it is the responsibility
        // of the caller to release this connection by calling
        // HttpMethod#releaseConnection.
        HttpConnection connection = manager.getConnection(configuration);
        prepareConnection(connection);

        TimingOutTask task = null;
        int statusCode;
        URI uri = null;
        try {
            // Get the URI now so that it can be used to report errors if
            // necessary.
            uri = new URI(connection.getProtocol().getScheme(), null,
                    configuration.getHost(), connection.getPort(),
                    method.getPath(), method.getQueryString(), null);

            if (roundTripTimeout != Period.INDEFINITELY) {
                task = createTimingOutTask(connection);
                TIMER.schedule(new RunnableTimerTask(task),
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.