Package org.apache.http.impl.conn

Examples of org.apache.http.impl.conn.BasicClientConnectionManager


    Scheme http = new Scheme("http", port, PlainSocketFactory.getSocketFactory());
    Scheme https = new Scheme("https", port, new org.apache.http.conn.ssl.SSLSocketFactory(getSslFactory(), null));
    SchemeRegistry sr = new SchemeRegistry();
    sr.register(http);
    sr.register(https);
    ClientConnectionManager connMrg = new BasicClientConnectionManager(sr);
    this.httpClient = new DefaultHttpClient(connMrg);
  }
View Full Code Here


            }
        }
        if (factory != null) {
            connManager = factory.newInstance(params, registry);
        } else {
            connManager = new BasicClientConnectionManager(registry);
        }

        return connManager;
    }
View Full Code Here

            SSLSocketFactory socketFactory = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
            SchemeRegistry registry = new SchemeRegistry();

            registry.register(new Scheme("https", iPort, socketFactory));

            BasicClientConnectionManager mgr = new BasicClientConnectionManager(registry);
            DefaultHttpClient client = new DefaultHttpClient();

            return new DefaultHttpClient(mgr, client.getParams());
        }
        catch (NoSuchAlgorithmException ex) {
View Full Code Here

    }

    private boolean getValuesOrAvailability(MeasurementReport report, Set<MeasurementScheduleRequest> metrics)
        throws Exception {

        BasicClientConnectionManager httpConnectionManager = new BasicClientConnectionManager();
        DefaultHttpClient client = new DefaultHttpClient(httpConnectionManager);

        String userName = pluginConfig.getSimpleValue(ConfigKeys.USER, EMPTY_STRING);
        // Set credentials only if a user name is configured
        if (isNotBlank(userName)) {
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

            }
        }
        if (factory != null) {
            connManager = factory.newInstance(params, registry);
        } else {
            connManager = new BasicClientConnectionManager(registry);
        }

        return connManager;
    }
View Full Code Here

        this.url = url;
        this.username = username;
        this.password = password;
        this.charset = charset;

        this.httpClient = new DefaultHttpClient( new BasicClientConnectionManager() );
        if ( StringUtils.isNotEmpty( username ) && StringUtils.isNotEmpty( password ) )
        {
            Credentials creds = new UsernamePasswordCredentials( username, password );

            String host = url.getHost();
View Full Code Here

    Scheme httpsScheme = new Scheme("https", 10101, sf);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(httpsScheme);

    // apache HttpClient version >4.2 should use BasicClientConnectionManager
    ClientConnectionManager cm = new BasicClientConnectionManager(schemeRegistry);
    return new DefaultHttpClient(cm);
  }
View Full Code Here

            }
        }
        if (factory != null) {
            connManager = factory.newInstance(params, registry);
        } else {
            connManager = new BasicClientConnectionManager(registry);
        }

        return connManager;
    }
View Full Code Here

    SSLSocketFactory socketFactory = new SSLSocketFactory( ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER );

    SchemeRegistry schemes = new SchemeRegistry();
    schemes.register( new Scheme( "https", port, socketFactory ) );
    ClientConnectionManager cm = new BasicClientConnectionManager( schemes );

    HttpClient client = new DefaultHttpClient( cm );

    HttpGet get = new HttpGet( url );
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
View Full Code Here

TOP

Related Classes of org.apache.http.impl.conn.BasicClientConnectionManager

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.