Example usage for org.apache.http.client HttpClient getConnectionManager

List of usage examples for org.apache.http.client HttpClient getConnectionManager

Introduction

In this page you can find the example usage for org.apache.http.client HttpClient getConnectionManager.

Prototype

@Deprecated
ClientConnectionManager getConnectionManager();

Source Link

Document

Obtains the connection manager used by this client.

Usage

From source file:com.android.volley.toolbox.http.HttpClientStack.java

public void setSSLSocketFactory(HttpClient mClient, SSLSocketFactory mSslSocketFactory) {
    if (mSslSocketFactory != null && mClient != null) {
        ClientConnectionManager manager = mClient.getConnectionManager();
        SchemeRegistry schemeRegistry = manager.getSchemeRegistry();
        schemeRegistry.unregister("https");
        Scheme scheme = new Scheme("https", mSslSocketFactory, 443);
        schemeRegistry.register(scheme);
    }/*from  w  w  w  .  j av  a2  s.  com*/
}

From source file:org.si4t.solr.SolrIndexDispatcher.java

public void destroyServers() {
    for (Entry<String, CoreContainer> entry : _solrContainers.entrySet()) {
        CoreContainer c = entry.getValue();
        if (c != null) {
            log.info("Shutting down CoreContainer for searcher: " + entry.getKey());
            c.shutdown();//from w w w. ja v a 2 s .com
        }
    }

    for (Entry<String, HttpClient> clients : _httpClients.entrySet()) {
        HttpClient client = clients.getValue();
        if (client != null) {
            log.info("Closing down HttpClient for url: " + clients.getKey());
            client.getConnectionManager().shutdown();
        }
    }
}

From source file:org.apache.camel.component.cxf.CxfConusmerNamespacePayLoadTest.java

@Test
public void testInvokingServiceFromClient() throws Exception {
    // just send a request which has all the namespace in the soap header
    HttpPost post = new HttpPost(simpleEndpointAddress);
    post.addHeader("Accept", "text/xml");

    StringEntity entity = new StringEntity(ECHO_REQUEST, ContentType.create("text/xml", "ISO-8859-1"));
    post.setEntity(entity);/*www  . j a v a 2 s  . co m*/
    HttpClient httpclient = new DefaultHttpClient();

    try {
        HttpResponse response = httpclient.execute(post);
        assertEquals(200, response.getStatusLine().getStatusCode());
        String responseBody = EntityUtils.toString(response.getEntity());

        assertEquals("Get a wrong response", ECHO_RESPONSE, responseBody);
    } finally {
        httpclient.getConnectionManager().shutdown();
    }

}

From source file:com.mp3tunes.android.player.RemoteAlbumArtHandler.java

private String getRemoteArtworkForLocalTrack(Track t) {
    String id = "stYqie5s3hGAz_VW3cXxwQ";
    String render = "json";
    String album = t.getAlbumTitle();
    String artist = t.getArtistName();
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("_id", id));
    params.add(new BasicNameValuePair("_render", render));
    params.add(new BasicNameValuePair("album", album));
    params.add(new BasicNameValuePair("artist", artist));

    try {/* w  w  w .  java  2s.  c o m*/
        URI uri = URIUtils.createURI("http", "pipes.yahoo.com", -1, "/pipes/pipe.run",
                URLEncodedUtils.format(params, "UTF-8"), null);

        HttpGet get = new HttpGet(uri);
        Log.w("Mp3Tunes", "Url: " + get.getURI().toString());

        HttpClient client = new DefaultHttpClient();
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String response = client.execute(get, responseHandler);
        client.getConnectionManager().shutdown();

        JSONObject obj = new JSONObject(response);
        JSONObject value = obj.getJSONObject("value");
        JSONArray items = value.getJSONArray("items");
        JSONObject item = items.getJSONObject(0);
        JSONObject image = item.getJSONObject("image");

        return image.getString("url");

    } catch (URISyntaxException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:org.apache.camel.itest.osgi.cxf.blueprint.CxfBeanBlueprintRouterTest.java

@Test
public void testGetCustomer() throws Exception {
    HttpGet get = new HttpGet("http://localhost:9000/route/customerservice/customers/123");
    get.addHeader("Accept", "application/json");
    HttpClient httpclient = new DefaultHttpClient();

    try {/* ww w. ja  v  a  2s .c  om*/
        HttpResponse response = httpclient.execute(get);
        assertEquals(200, response.getStatusLine().getStatusCode());
        assertEquals("{\"Customer\":{\"id\":123,\"name\":\"John\"}}",
                EntityUtils.toString(response.getEntity()));
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:org.apache.camel.itest.osgi.cxf.blueprint.CxfBeanBlueprintRouterTest.java

@Test
public void testGetCustomerWithQuery() throws Exception {
    HttpGet get = new HttpGet("http://localhost:9000/route/customerservice/customers?id=123");
    get.addHeader("Accept", "application/json");
    HttpClient httpclient = new DefaultHttpClient();

    try {// w w  w . j a v a2 s  . c o m
        HttpResponse response = httpclient.execute(get);
        assertEquals(200, response.getStatusLine().getStatusCode());
        assertEquals("{\"Customer\":{\"id\":123,\"name\":\"John\"}}",
                EntityUtils.toString(response.getEntity()));
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:hornet.framework.technical.HTTPClientParameterBuilderTest.java

/**
 * Test connection manager class default value.
 * /*from ww w  . j  a v a2  s.c om*/
 * @throws Exception
 *             the exception
 */
@Test
public void testConnectionManagerClassDefaultValue() throws Exception {

    final HttpClient httpClient = new DefaultHttpClient();
    HTTPClientParameterBuilder.loadHttpParamToHttpClientFromConfig(httpClient, "http-parameters");
    assertEquals(BasicClientConnectionManager.class, httpClient.getConnectionManager().getClass());
}

From source file:com.alliander.osgp.adapter.ws.smartmetering.infra.ws.WebServiceTemplateFactory.java

/**
 * @throws WebServiceSecurityException//www . j a  v a  2s  .  co  m
 *             if an error occurs while attempting to create a secured
 *             connection.
 */
private HttpComponentsMessageSender webServiceMessageSender(final String keystore)
        throws WebServiceSecurityException {

    try {
        // Open keystore, assuming same identity
        final KeyStoreFactoryBean keyStoreFactory = new KeyStoreFactoryBean();
        keyStoreFactory.setType(this.keyStoreType);
        keyStoreFactory.setLocation(new FileSystemResource(this.keyStoreLocation + "/" + keystore + ".pfx"));
        keyStoreFactory.setPassword(this.keyStorePassword);
        keyStoreFactory.afterPropertiesSet();

        final KeyStore keyStore = keyStoreFactory.getObject();
        if (keyStore == null || keyStore.size() == 0) {
            throw new KeyStoreException("Key store is empty");
        }

        // Create HTTP sender and associate keystore to it
        final HttpComponentsMessageSender sender = new HttpComponentsMessageSender();
        final HttpClient client = sender.getHttpClient();
        final SSLSocketFactory socketFactory = new SSLSocketFactory(keyStore, this.keyStorePassword,
                this.trustStoreFactory.getObject());

        final Scheme scheme = new Scheme("https", 443, socketFactory);
        client.getConnectionManager().getSchemeRegistry().register(scheme);

        return sender;

    } catch (IOException | GeneralSecurityException e) {
        throw new WebServiceSecurityException("An exception occured while creating a secured connection.", e);
    }

}

From source file:ca.sqlpower.enterprise.ClientSideSessionUtils.java

public static List<ProjectLocation> getWorkspaceNames(SPServerInfo serviceInfo, CookieStore cookieStore,
        UserPrompterFactory upf) throws IOException, URISyntaxException, JSONException {
    HttpClient httpClient = ClientSideSessionUtils.createHttpClient(serviceInfo, cookieStore);
    try {//from   ww  w .jav a2 s  .c  o m
        HttpUriRequest request = new HttpGet(
                getServerURI(serviceInfo, "/" + ClientSideSessionUtils.REST_TAG + "/jcr/projects"));
        JSONMessage message = httpClient.execute(request, new JSONResponseHandler());
        if (message.getStatusCode() == 412) { //precondition failed
            upf.createUserPrompter(message.getBody(), UserPromptType.MESSAGE, UserPromptOptions.OK,
                    UserPromptResponse.OK, null, "OK").promptUser();
        }
        List<ProjectLocation> workspaces = new ArrayList<ProjectLocation>();
        JSONArray response = new JSONArray(message.getBody());
        for (int i = 0; i < response.length(); i++) {
            JSONObject workspace = (JSONObject) response.get(i);
            workspaces.add(
                    new ProjectLocation(workspace.getString("uuid"), workspace.getString("name"), serviceInfo));
        }
        return workspaces;
    } catch (AccessDeniedException e) {
        throw e;
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
}

From source file:com.lostad.app.base.util.RequestUtil.java

public static String postForm(String url, List<NameValuePair> params, boolean isSingleton) throws Exception {
    String json = null;/*from w w  w.  j  a va  2  s . c  o  m*/
    HttpClient client = HttpClientManager.getHttpClient(isSingleton);
    HttpEntity resEntity = null;
    HttpPost post = new HttpPost(url);
    try {

        if (params != null) {
            UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, HTTP.UTF_8);
            post.setEntity(entity);
        }
        HttpResponse response = client.execute(post, new BasicHttpContext());
        resEntity = response.getEntity();
        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {// 200
            // ?
            json = EntityUtils.toString(resEntity);
        }
    } catch (Exception e) {
        if (post != null) {
            post.abort();//
        }
        throw e;
    } finally {

        if (resEntity != null) {
            try {
                resEntity.consumeContent();//?

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        client.getConnectionManager().closeExpiredConnections();
        ///client.getConnectionManager().shutdown();
    }
    return json;

}