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:ca.sqlpower.enterprise.ClientSideSessionUtils.java

public static ProjectLocation uploadProject(SPServerInfo serviceInfo, String name, File project,
        UserPrompterFactory session, CookieStore cookieStore)
        throws URISyntaxException, ClientProtocolException, IOException, JSONException {
    HttpClient httpClient = ClientSideSessionUtils.createHttpClient(serviceInfo, cookieStore);
    try {//from   w w  w.j  a  v  a 2s .co  m
        MultipartEntity entity = new MultipartEntity();
        ContentBody fileBody = new FileBody(project);
        ContentBody nameBody = new StringBody(name);
        entity.addPart("file", fileBody);
        entity.addPart("name", nameBody);

        HttpPost request = new HttpPost(ClientSideSessionUtils.getServerURI(serviceInfo,
                "/" + ClientSideSessionUtils.REST_TAG + "/jcr", "name=" + name));
        request.setEntity(entity);
        JSONMessage message = httpClient.execute(request, new JSONResponseHandler());
        JSONObject response = new JSONObject(message.getBody());
        return new ProjectLocation(response.getString("uuid"), response.getString("name"), serviceInfo);
    } catch (AccessDeniedException e) {
        session.createUserPrompter("You do not have sufficient privileges to create a new workspace.",
                UserPromptType.MESSAGE, UserPromptOptions.OK, UserPromptResponse.OK, "OK", "OK").promptUser("");
        return null;
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
}

From source file:net.sourceforge.subsonic.service.sonos.SonosServiceRegistration.java

private String executeRequest(HttpUriRequest request) throws IOException {
    HttpClient client = new DefaultHttpClient();
    HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000);
    HttpConnectionParams.setSoTimeout(client.getParams(), 10000);

    try {//from  w w w. j  a  va  2 s.  c  o  m
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        return client.execute(request, responseHandler);

    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:org.apache.camel.component.cxf.jaxrs.CxfRsConsumerTest.java

private void invokeGetCustomer(String uri, String expect) throws Exception {
    HttpGet get = new HttpGet(uri);
    get.addHeader("Accept", "application/json");
    HttpClient httpclient = new DefaultHttpClient();

    try {/*w w  w. j  av a  2 s.  c om*/
        HttpResponse response = httpclient.execute(get);
        assertEquals(200, response.getStatusLine().getStatusCode());
        assertEquals(expect, EntityUtils.toString(response.getEntity()));
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:org.apache.camel.component.cxf.jaxrs.CxfRsConsumerTest.java

@Test
public void testPutConsumer() throws Exception {
    HttpPut put = new HttpPut("http://localhost:" + CXT + "/rest/customerservice/customers");
    StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1");
    entity.setContentType("text/xml; charset=ISO-8859-1");
    put.addHeader("test", "header1;header2");
    put.setEntity(entity);/*from  w ww.  ja  v a  2s . c  o  m*/
    HttpClient httpclient = new DefaultHttpClient();

    try {
        HttpResponse response = httpclient.execute(put);
        assertEquals(200, response.getStatusLine().getStatusCode());
        assertEquals("", EntityUtils.toString(response.getEntity()));
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:android.net.http.AbstractProxyTest.java

public void testConnectToHttps() throws Exception {
    TestSSLContext testSSLContext = TestSSLContext.create();

    server.useHttps(testSSLContext.serverContext.getSocketFactory(), false);
    server.enqueue(new MockResponse().setResponseCode(200).setBody("this response comes via HTTPS"));
    server.play();//www  .  ja  va  2s . c  o m

    HttpClient httpClient = newHttpClient();

    SSLSocketFactory sslSocketFactory = newSslSocketFactory(testSSLContext);
    sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier());
    httpClient.getConnectionManager().getSchemeRegistry()
            .register(new Scheme("https", sslSocketFactory, server.getPort()));

    HttpResponse response = httpClient.execute(new HttpGet("https://localhost:" + server.getPort() + "/foo"));
    assertEquals("this response comes via HTTPS", contentToString(response));

    RecordedRequest request = server.takeRequest();
    assertEquals("GET /foo HTTP/1.1", request.getRequestLine());
}

From source file:org.apache.camel.component.cxf.jaxrs.CxfRsRouterTest.java

@Test
public void testPutConsumer() throws Exception {
    HttpPut put = new HttpPut(
            "http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/customers");
    StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1");
    entity.setContentType("text/xml; charset=ISO-8859-1");
    put.setEntity(entity);/*from ww  w.j  av a2 s  .co m*/
    HttpClient httpclient = new DefaultHttpClient();

    try {
        HttpResponse response = httpclient.execute(put);
        assertEquals(200, response.getStatusLine().getStatusCode());
        assertEquals("", EntityUtils.toString(response.getEntity()));
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:android.net.http.AbstractProxyTest.java

private void testConnectViaHttpProxyToHttps(ProxyConfig proxyConfig) throws Exception {
    TestSSLContext testSSLContext = TestSSLContext.create();

    server.useHttps(testSSLContext.serverContext.getSocketFactory(), true);
    server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.UPGRADE_TO_SSL_AT_END).clearHeaders());
    server.enqueue(new MockResponse().setResponseCode(200).setBody("this response comes via a secure proxy"));
    server.play();/* www.j  a  v a  2 s  .  c o m*/

    HttpClient httpProxyClient = newHttpClient();
    SSLSocketFactory sslSocketFactory = newSslSocketFactory(testSSLContext);
    sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier());
    httpProxyClient.getConnectionManager().getSchemeRegistry()
            .register(new Scheme("https", sslSocketFactory, 443));

    HttpGet request = new HttpGet("https://android.com/foo");
    proxyConfig.configure(server, httpProxyClient, request);

    HttpResponse response = httpProxyClient.execute(request);
    assertEquals("this response comes via a secure proxy", contentToString(response));

    RecordedRequest connect = server.takeRequest();
    assertEquals("Connect line failure on proxy " + proxyConfig, "CONNECT android.com:443 HTTP/1.1",
            connect.getRequestLine());
    assertContains(connect.getHeaders(), "Host: android.com");

    RecordedRequest get = server.takeRequest();
    assertEquals("GET /foo HTTP/1.1", get.getRequestLine());
    assertContains(get.getHeaders(), "Host: android.com");
}

From source file:org.factpub.ui.gui.network.PostFile.java

public static List<String> uploadToFactpub(File file) throws Exception {
    List<String> status = new ArrayList<String>();
    int i = 0;/*from w ww.j  a v  a 2s . c o m*/

    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

    String postUrl = FEConstants.SERVER_POST_HANDLER + "?id=" + AuthMediaWikiIdHTTP.authorisedUser + "&ps="
            + AuthMediaWikiIdHTTP.userPassword;

    HttpPost httppost = new HttpPost(postUrl);

    System.out.println(postUrl);

    MultipartEntity mpEntity = new MultipartEntity();
    ContentBody cbFile = new FileBody(file, "json");

    // name must be "uploadfile". this is same on the server side.
    mpEntity.addPart(FEConstants.SERVER_UPLOAD_FILE_NAME, cbFile);

    httppost.setEntity(mpEntity);
    System.out.println("executing request " + httppost.getRequestLine());
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity resEntity = response.getEntity();

    System.out.println(response.getStatusLine());

    if (response.getStatusLine().toString().contains("502 Bad Gateway")) {
        status.add("Looks server is down.");
    } else {
        if (resEntity != null) {
            status.add(EntityUtils.toString(resEntity));
            System.out.println(status.get(i));
            i++;
        }

        if (resEntity != null) {
            resEntity.consumeContent();
        }
    }
    httpclient.getConnectionManager().shutdown();

    //String status = "Upload Success!";
    return status;
}

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

@Test
public void testPutConsumer() throws Exception {
    HttpPut put = new HttpPut("http://localhost:9000/route/customerservice/customers");
    StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1");
    entity.setContentType("text/xml; charset=ISO-8859-1");
    put.setEntity(entity);//from w  w  w . j  a  v  a  2 s  . c o m
    HttpClient httpclient = new DefaultHttpClient();

    try {
        HttpResponse response = httpclient.execute(put);
        assertEquals(200, response.getStatusLine().getStatusCode());
        assertEquals("", EntityUtils.toString(response.getEntity()));
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}