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.DataSourceCollectionUpdater.java

public void removeJDBCDataSourceType(JDBCDataSourceType jdst) {
    HttpClient httpClient = getHttpClient();
    try {//  w  w w  . j  a va  2 s  . co m
        HttpDelete request = new HttpDelete(jdbcDataSourceTypeURI(jdst));
        httpClient.execute(request, responseHandler);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
}

From source file:com.nostra13.example.universalimageloader.ImageGridActivity.java

private void getImageJson() {
    try {/* www .  ja v  a 2s .c o m*/
        HttpParams params = new BasicHttpParams();
        HttpConnectionParams.setSoTimeout(params, 0);
        HttpClient httpClient = new DefaultHttpClient(params);

        HttpGet httpget = new HttpGet(imageUrlString);
        HttpEntity entity = httpClient.execute(httpget).getEntity();
        if (entity != null) {
            String response = EntityUtils.toString(entity);
            Log.d("Parse", response);
            entity.consumeContent();
            httpClient.getConnectionManager().shutdown();

            JSONArray json_photoArray = new JSONArray(response);

            if (json_photoArray != null) {
                for (int i = 0; i < json_photoArray.length(); i++) {

                    JSONObject object1 = (JSONObject) json_photoArray.get(i);
                    String photourlString = object1.getString("url");
                    tmp_ImageJsonArray.add(photourlString);
                    Log.d("Photo", photourlString);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        String error = e.toString();
        Log.d("wqe", error);
    }
}

From source file:ca.sqlpower.wabit.enterprise.client.WabitClientSession.java

/**
 * List all the workspaces on this context's server.
 * // ww  w. j av a2  s.com
 * @param serviceInfo
 * @return
 * @throws IOException
 * @throws URISyntaxException
 * @throws JSONException 
 */
public static List<WorkspaceLocation> getWorkspaceNames(SPServerInfo serviceInfo)
        throws IOException, URISyntaxException, JSONException {
    HttpClient httpClient = createHttpClient(serviceInfo);
    try {
        HttpUriRequest request = new HttpGet(getServerURI(serviceInfo, "workspaces"));
        String responseBody = httpClient.execute(request, new BasicResponseHandler());
        JSONArray response;
        List<WorkspaceLocation> workspaces = new ArrayList<WorkspaceLocation>();
        response = new JSONArray(responseBody);
        logger.debug("Workspace list:\n" + responseBody);
        for (int i = 0; i < response.length(); i++) {
            JSONObject workspace = (JSONObject) response.get(i);
            workspaces.add(new WorkspaceLocation(workspace.getString("name"), workspace.getString("UUID"),
                    serviceInfo));
        }
        return workspaces;
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
}

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

@Test
public void testGetSubResource() throws Exception {
    HttpGet get = new HttpGet(
            "http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/orders/223/products/323");
    get.addHeader("Accept", "application/json");
    HttpClient httpclient = new DefaultHttpClient();

    try {//from ww w  .ja v  a  2 s . c om
        HttpResponse response = httpclient.execute(get);
        assertEquals(200, response.getStatusLine().getStatusCode());
        assertEquals("{\"Product\":{\"description\":\"product 323\",\"id\":323}}",
                EntityUtils.toString(response.getEntity()));
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}

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

@Test
public void testGetSubResource() throws Exception {
    HttpGet get = new HttpGet("http://localhost:9000/route/customerservice/orders/223/products/323");
    get.addHeader("Accept", "application/json");
    HttpClient httpclient = new DefaultHttpClient();

    try {/*w w  w .  j a v a2  s . co  m*/
        HttpResponse response = httpclient.execute(get);
        assertEquals(200, response.getStatusLine().getStatusCode());
        assertEquals("{\"Product\":{\"description\":\"product 323\",\"id\":323}}",
                EntityUtils.toString(response.getEntity()));
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:com.nloko.android.Utils.java

public static InputStream downloadPictureAsStream(String url) throws IOException {
    if (url == null) {
        throw new IllegalArgumentException("url");
    }/*  w ww .j  ava2  s  .  c o m*/

    HttpClient httpclient = null;
    InputStream stream = null;
    try {
        HttpParams params = new BasicHttpParams();
        // Set the timeout in milliseconds until a connection is established.
        HttpConnectionParams.setConnectionTimeout(params, 5000);
        // Set the default socket timeout (SO_TIMEOUT) 
        // in milliseconds which is the timeout for waiting for data.
        HttpConnectionParams.setSoTimeout(params, 10000);

        httpclient = new DefaultHttpClient(params);
        HttpGet httpget = new HttpGet(url);

        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            BufferedHttpEntity buff = new BufferedHttpEntity(entity);
            stream = buff.getContent();
            //   image = BitmapFactory.decodeStream(stream);
        }
    } catch (IOException ex) {
        Log.e(null, android.util.Log.getStackTraceString(ex));
        throw ex;
    } finally {
        try {
            if (httpclient != null) {
                httpclient.getConnectionManager().shutdown();
            }
            if (stream != null) {
                stream.close();
            }
        } catch (Exception e) {
        }
    }

    return stream;
}

From source file:com.mark.SimpleApp.SimpleAsyncTask.java

private String getHttp() {
    // some basic code to do an HttpGet call
    String body = null;/*from  w  ww .j  a va2s .c  om*/
    Header[] headers;
    HttpClient httpClient = new DefaultHttpClient();
    try {
        HttpGet get = new HttpGet(new URI("http://www.appnexus.com"));

        HttpResponse response = httpClient.execute(get);

        headers = response.getAllHeaders();
        body = EntityUtils.toString(response.getEntity());
    }

    catch (URISyntaxException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        httpClient.getConnectionManager().shutdown();
    }

    return body;
}

From source file:uk.ac.susx.tag.method51.twitter.geocoding.geonames.GeonamesSPARQLLocationDatabase.java

public String makeRequest(String query) throws IOException, URISyntaxException {

    HttpGet get = new HttpGet();

    String queryString = "query=" + URLEncoder.encode(query, "UTF-8");

    queryString += "&output=json";

    String locationLookupURI = "/ds/query";
    int locationLookupPort = port;
    String locationLookupHost = host;
    URI uri = URIUtils.createURI("http", locationLookupHost, locationLookupPort, locationLookupURI, queryString,
            null);/*from   w  w w .ja va  2  s  .  c  o  m*/

    get.setURI(uri);

    HttpClient httpClient = new DefaultHttpClient();

    ResponseHandler<String> responseHandler = new BasicResponseHandler();

    String responseBody = httpClient.execute(get, responseHandler);

    httpClient.getConnectionManager().shutdown();

    return responseBody;
}

From source file:com.cloudhopper.sxmp.SxmpSender.java

static public Response send(String url, Request request, boolean shouldParseResponse)
        throws UnsupportedEncodingException, SxmpErrorException, IOException, SxmpParsingException,
        SAXException, ParserConfigurationException {
    // convert request into xml
    String requestXml = SxmpWriter.createString(request);
    String responseXml = null;/*w w  w  . ja  v  a2 s .  c o  m*/

    HttpClient client = new DefaultHttpClient();
    client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    client.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE);

    long start = System.currentTimeMillis();
    long stop = 0;

    logger.debug("Request XML:\n" + requestXml);

    // execute request
    try {
        HttpPost post = new HttpPost(url);
        StringEntity entity = new StringEntity(requestXml);
        // write old or new encoding?
        if (request.getVersion().equals(SxmpParser.VERSION_1_1)) {
            // v1.1 is utf-8
            entity.setContentType("text/xml; charset=\"utf-8\"");
        } else {
            // v1.0 was 8859-1, though that's technically wrong
            // unspecified XML must be encoded in UTF-8
            // maintained this way for backward compatibility
            entity.setContentType("text/xml; charset=\"iso-8859-1\"");
        }
        post.setEntity(entity);

        ResponseHandler<String> responseHandler = new BasicResponseHandler();

        // execute request (will throw exception if fails)
        responseXml = client.execute(post, responseHandler);

        stop = System.currentTimeMillis();
    } finally {
        // clean up all resources
        client.getConnectionManager().shutdown();
    }

    logger.debug("Response XML:\n" + responseXml);
    logger.debug("Response Time: " + (stop - start) + " ms");

    // deliver responses sometimes aren't parseable since its acceptable
    // for delivery responses to merely return "OK" and an HTTP 200 error
    if (!shouldParseResponse) {
        return null;
    } else {
        // convert response xml into an object
        SxmpParser parser = new SxmpParser(SxmpParser.VERSION_1_0);
        // v1.0 data remains in ISO-8859-1, and responses are v1.0
        ByteArrayInputStream bais = new ByteArrayInputStream(responseXml.getBytes("ISO-8859-1"));
        Operation op = parser.parse(bais);

        if (!(op instanceof Response)) {
            throw new SxmpErrorException(SxmpErrorCode.OPTYPE_MISMATCH,
                    "Unexpected response class type parsed");
        }

        return (Response) op;
    }
}

From source file:it.component.ProjectSearchTest.java

/**
 * SONAR-3105/*from w w  w .j a  va  2s. co m*/
 */
@Test
public void projects_web_service() throws IOException {
    SonarScanner build = SonarScanner.create(projectDir("shared/xoo-sample"));
    orchestrator.executeBuild(build);

    String url = orchestrator.getServer().getUrl() + "/api/projects/index?key=sample&versions=true";
    HttpClient httpclient = new DefaultHttpClient();
    try {
        HttpGet get = new HttpGet(url);
        HttpResponse response = httpclient.execute(get);

        assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
        String content = IOUtils.toString(response.getEntity().getContent());
        assertThat(content).doesNotContain("error");
        assertThat(content).contains("sample");
        EntityUtils.consume(response.getEntity());

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