Package org.apache.http.conn

Examples of org.apache.http.conn.ClientConnectionManager


        registry.register(
                new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(
                new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

        ClientConnectionManager connManager = null;    
        HttpParams params = getParams();
       
        ClientConnectionManagerFactory factory = null;

        String className = (String) params.getParameter(
View Full Code Here


        }

        closeQuietly(cacheOutputStream);

        SchemeRegistry schemeRegistry = new SchemeRegistryBuilder(asConnectionParams).buildSchemeRegistry();
        ClientConnectionManager httpConnectionManager = new BasicClientConnectionManager(schemeRegistry);
        DefaultHttpClient httpClient = new DefaultHttpClient(httpConnectionManager);
        HttpParams httpParams = httpClient.getParams();
        HttpConnectionParams.setConnectionTimeout(httpParams, SOCKET_CONNECTION_TIMEOUT);
        HttpConnectionParams.setSoTimeout(httpParams, timeout);

        if (credentials != null && !asConnectionParams.isClientcertAuthentication()) {
            httpClient.getCredentialsProvider().setCredentials(
                new AuthScope(asConnectionParams.getHost(), asConnectionParams.getPort()), credentials);

            // If credentials were provided, we will first send a GET request to trigger the authentication challenge
            // This allows to send the potentially big file only once to the server
            // The typical resulting http exchange would be:
            //
            // GET without auth <- 401 (start auth challenge : the server will name the realm and the scheme)
            // GET with auth <- 200
            // POST big file
            //
            // Note this only works because we use SimpleHttpConnectionManager which maintains only one HttpConnection
            //
            // A better way to avoid uploading a big file twice would be to use the header "Expect: Continue"
            // Unfortunately AS7 replies "100 Continue" even if authentication headers are not present yet
            //
            // There is no need to trigger digest authentication when client certification authentication is used

            HttpGet triggerAuthRequest = new HttpGet(triggerAuthUri);
            try {
                // Send GET request in order to trigger authentication
                // We don't check response code because we're not already uploading the file
                httpClient.execute(triggerAuthRequest);
            } catch (Exception ignore) {
                // We don't stop trying upload if triggerAuthRequest raises exception
                // See comment above
            } finally {
                triggerAuthRequest.abort();
            }
        }

        String uploadURL = (asConnectionParams.isSecure() ? HTTPS_SCHEME : HTTP_SCHEME) + "://"
            + asConnectionParams.getHost() + ":" + asConnectionParams.getPort() + UPLOAD_URI;
        HttpPost uploadRequest = new HttpPost(uploadUri);
        try {

            // Now upload file with multipart POST request
            MultipartEntity multipartEntity = new MultipartEntity();
            multipartEntity.addPart(filename, new FileBody(cacheFile));
            uploadRequest.setEntity(multipartEntity);
            HttpResponse uploadResponse = httpClient.execute(uploadRequest);
            if (uploadResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                logUploadDoesNotEndWithHttpOkStatus(uploadResponse);
                return null;
            }

            ObjectMapper objectMapper = new ObjectMapper();
            InputStream responseBodyAsStream = uploadResponse.getEntity().getContent();
            if (responseBodyAsStream == null) {
                LOG.warn("POST request has no response body");
                return objectMapper.readTree(EMPTY_JSON_TREE);
            }
            return objectMapper.readTree(responseBodyAsStream);

        } catch (Exception e) {
            LOG.error(e);
            return null;
        } finally {
            // Release httpclient resources
            uploadRequest.abort();
            httpConnectionManager.shutdown();
            // Delete cache file
            deleteCacheFile();
        }
    }
View Full Code Here

        HttpConnectionParams.setSoTimeout(defaultParameters, 60000);

        SchemeRegistry supportedSchemes = new SchemeRegistry();
        supportedSchemes.register(new Scheme(HttpHost.DEFAULT_SCHEME_NAME, PlainSocketFactory.getSocketFactory(), 80));

        ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(defaultParameters, supportedSchemes);

        httpClient = new DefaultHttpClient(connectionManager, defaultParameters);
    }
View Full Code Here

    // Create and initialize scheme registry
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);

    DefaultHttpClient client = new DefaultHttpClient(cm, params);

    // try resending the request once
    client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(1, true));
View Full Code Here

        // Set-up the scheme registry
        SchemeRegistry schemeRegistry = new SchemeRegistry();
        configure(schemeRegistry);

        // Create the connection manager
        ClientConnectionManager connectionManager = createClientConnectionManager(
                params, schemeRegistry);

        // Create and configure the HTTP client
        this.httpClient = new DefaultHttpClient(connectionManager, params);
        configure(this.httpClient);
View Full Code Here

        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

        ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
        HttpClient httpClient = new DefaultHttpClient(cm, params);

        return new ApacheHttpClient4Executor(httpClient);
    }
View Full Code Here


    protected ClientConnectionManager createClientConnectionManager() {
        final SchemeRegistry registry = SchemeRegistryFactory.createDefault();

        ClientConnectionManager connManager = null;
        final HttpParams params = getParams();

        ClientConnectionManagerFactory factory = null;

        final String className = (String) params.getParameter(
View Full Code Here

                this.log.debug("Releasing connection " + conn);
            }
            if (managedConn.getPoolEntry() == null) {
                return; // already released
            }
            final ClientConnectionManager manager = managedConn.getManager();
            Asserts.check(manager == this, "Connection not obtained from this manager");
            synchronized (this) {
                if (this.shutdown) {
                    shutdownConnection(managedConn);
                    return;
View Full Code Here

                }
            };
            ctx.init(null, new TrustManager[]{tm}, null);
            SSLSocketFactory ssf = new SSLSocketFactory(ctx);
            ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
            ClientConnectionManager ccm = base.getConnectionManager();
            SchemeRegistry sr = ccm.getSchemeRegistry();
            sr.register(new Scheme("https", ssf, 443));
            return new DefaultHttpClient(ccm, base.getParams());
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
View Full Code Here

    ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);

    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory
        .getSocketFactory(), 80));
    ClientConnectionManager cm = new ThreadSafeClientConnManager(params,
        schemeRegistry);
    httpClient = new DefaultHttpClient(cm, params);

    httpClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
View Full Code Here

TOP

Related Classes of org.apache.http.conn.ClientConnectionManager

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.