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:ecplugins.s3.TestUtils.java

/**
 * callRunProcedure/*from www  .  j  a  v a2s .  c  o m*/
 *
 * @param jo
 * @return the jobId of the job launched by runProcedure
 */
public static String callRunProcedure(JSONObject jo) throws Exception {

    HttpClient httpClient = new DefaultHttpClient();
    JSONObject result = null;

    try {
        HttpPost httpPostRequest = new HttpPost("http://" + props.getProperty(StringConstants.COMMANDER_USER)
                + ":" + props.getProperty(StringConstants.COMMANDER_PASSWORD) + "@"
                + StringConstants.COMMANDER_SERVER + ":8000/rest/v1.0/jobs?request=runProcedure");
        StringEntity input = new StringEntity(jo.toString());

        input.setContentType("application/json");
        httpPostRequest.setEntity(input);
        HttpResponse httpResponse = httpClient.execute(httpPostRequest);

        result = new JSONObject(EntityUtils.toString(httpResponse.getEntity()));
        return result.getString("jobId");

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

}

From source file:at.ac.tuwien.big.testsuite.impl.util.HttpClientProducer.java

void disposeHttpClient(@Disposes HttpClient httpClient) {
    httpClient.getConnectionManager().shutdown();
}

From source file:org.tellervo.desktop.wsi.WebJaxbAccessor.java

public static void setSelfSignableHTTPSScheme(HttpClient client) {
    if (selfSignableHTTPSScheme == null) {
        try {/*ww w .j  a  v  a  2s.  c om*/
            // make a new SSL context
            SSLContext sc = SSLContext.getInstance("SSL");
            sc.init(null, trustAllCerts, new java.security.SecureRandom());

            // make a new socket factory
            SSLSocketFactory socketFactory = new SSLSocketFactory(sc);

            // register the scheme with the connection
            selfSignableHTTPSScheme = new Scheme("https", socketFactory, 443);
        } catch (Exception e) {
            // don't do anything; we'll just get errors later.
            return;
        }
    }

    client.getConnectionManager().getSchemeRegistry().register(selfSignableHTTPSScheme);
}

From source file:com.lurencun.cfuture09.androidkit.http.Http.java

/**
 * /*from w w w . j av  a2 s  .  c om*/
 *
 * @param url
 *            ?URL
 * @param entity
 *            
 * @return ?
 * @throws ClientProtocolException
 * @throws IOException
 */
private static String doUpload(String url, SimpleMultipartEntity entity)
        throws ClientProtocolException, IOException {
    HttpClient httpclient = null;
    try {
        httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
        HttpPost httppost = new HttpPost(url);
        httppost.setEntity(entity);
        HttpResponse response;
        response = httpclient.execute(httppost);
        return EntityUtils.toString(response.getEntity());
    } finally {
        if (httpclient != null) {
            httpclient.getConnectionManager().shutdown();
        }
    }
}

From source file:org.cloudifysource.azure.CliAzureDeploymentTest.java

/**
 * This methods extracts the number of machines running gs-agents using the rest admin api 
 *  /*from  w  w  w  .  j  a v a  2 s.  c om*/
 * @param machinesRestAdminUrl
 * @return number of machines running gs-agents
 * @throws IOException
 * @throws URISyntaxException 
 */
private static int getNumberOfMachines(URL machinesRestAdminUrl) throws IOException, URISyntaxException {
    HttpClient client = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(machinesRestAdminUrl.toURI());
    try {
        String json = client.execute(httpGet, new BasicResponseHandler());
        Matcher matcher = Pattern.compile("\"Size\":\"([0-9]+)\"").matcher(json);
        if (matcher.find()) {
            String rawSize = matcher.group(1);
            int size = Integer.parseInt(rawSize);
            return size;
        } else {
            return 0;
        }
    } catch (Exception e) {
        return 0;
    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:Technique.PostFile.java

public static void upload(String files) throws Exception {

    String userHome = System.getProperty("user.home");
    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    HttpPost httppost = new HttpPost("http://localhost/image/up.php");
    File file = new File(files);
    MultipartEntity mpEntity = new MultipartEntity();
    ContentBody contentFile = new FileBody(file);
    mpEntity.addPart("userfile", contentFile);
    httppost.setEntity(mpEntity);//from   w  ww.j a v a2 s.  c o m
    System.out.println("executing request " + httppost.getRequestLine());
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity resEntity = response.getEntity();

    if (!(response.getStatusLine().toString()).equals("HTTP/1.1 200 OK")) {
        // Successfully Uploaded
    } else {
        // Did not upload. Add your logic here. Maybe you want to retry.
    }
    System.out.println(response.getStatusLine());
    if (resEntity != null) {
        System.out.println(EntityUtils.toString(resEntity));
    }
    if (resEntity != null) {
        resEntity.consumeContent();
    }
    httpclient.getConnectionManager().shutdown();
}

From source file:com.xtremelabs.imageutils.DefaultNetworkRequestCreator.java

@Override
public void getInputStream(String url, InputStreamListener listener) {
    HttpEntity entity = null;//from  w w  w .j  a  v  a 2 s  .c o  m
    InputStream inputStream = null;

    HttpClient client = new DefaultHttpClient();
    client.getConnectionManager().closeExpiredConnections();
    HttpUriRequest request;
    try {
        request = new HttpGet(url);
    } catch (IllegalArgumentException e) {
        try {
            request = new HttpGet(URLEncoder.encode(url, "UTF-8"));
        } catch (UnsupportedEncodingException e1) {
            String errorMessage = "Unable to download image. Reason: Bad URL. URL: " + url;
            Log.w(ImageLoader.TAG, errorMessage);
            listener.onFailure(errorMessage);
            return;
        }
    }
    HttpResponse response;
    try {
        response = client.execute(request);

        entity = response.getEntity();
        if (entity == null) {
            listener.onFailure("Was unable to retrieve an HttpEntity for the image!");
            return;
        }

        inputStream = new BufferedInputStream(entity.getContent());
        listener.onInputStreamReady(inputStream);
    } catch (IOException e) {
        listener.onFailure("IOException caught when attempting to download an image! Stack trace below. URL: "
                + url + ", Message: " + e.getMessage());
        e.printStackTrace();
    }

    try {
        if (entity != null) {
            entity.consumeContent();
        }
    } catch (IOException e) {
    }

    client.getConnectionManager().closeExpiredConnections();
}

From source file:org.cloudifysource.azure.AbstractCliAzureDeploymentTest.java

protected static boolean isUrlAvailable(URL url) throws URISyntaxException {
    HttpClient client = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(url.toURI());
    httpGet.addHeader("Cache-Control", "no-cache");
    try {/*from   ww w. j  a va  2 s  .c o  m*/
        HttpResponse response = client.execute(httpGet);
        logger.info("HTTP GET " + url + " returned " + response.getStatusLine().getReasonPhrase()
                + " Response: [" + response.getStatusLine().getStatusCode() + "] "
                + EntityUtils.toString(response.getEntity()));
        if (response.getStatusLine().getStatusCode() == 404
                || response.getStatusLine().getStatusCode() == 502) {
            return false;
        }
        return true;
    } catch (Exception e) {
        log("Failed connecting to " + url, e);
        return false;
    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:com.subgraph.vega.internal.http.requests.HttpRequestEngineFactory.java

private void configureClient(HttpClient client, IHttpRequestEngineConfig config) {
    final ClientConnectionManager connectionManager = client.getConnectionManager();
    if (connectionManager instanceof ThreadSafeClientConnManager) {
        ThreadSafeClientConnManager ccm = (ThreadSafeClientConnManager) connectionManager;
        ccm.setMaxTotal(config.getMaxConnections());
        ccm.setDefaultMaxPerRoute(config.getMaxConnectionsPerRoute());
    }/* ww  w.j  a  va 2s. c o  m*/
}

From source file:realizer.com.schoolgenieparent.ServerUtilities.java

private static StringBuilder post(String regID, String EmpId) {
    //String my = "http://104.217.254.180/RestWCF/svcEmp.svc/registerDevice/" + EmpId + "/" + regID;
    SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(ctx);
    String did = sharedpreferences.getString("DWEVICEID", "");

    //String my = "http://192.168.1.14/SJRestWCF/registerDevice/" + EmpId + "/" + regID;
    String my = Config.URL + "RegisterStudentDevice/" + EmpId + "/" + did + "/" + regID;
    Log.d("GCMDID", my);
    builder = new StringBuilder();
    HttpGet httpGet = new HttpGet(my);
    HttpClient client = new DefaultHttpClient();
    try {/*from   w w w  .j  a  v a2s.  c o  m*/
        HttpResponse response = client.execute(httpGet);
        StatusLine statusLine = response.getStatusLine();

        int statusCode = statusLine.getStatusCode();
        Log.d("GCMSTATUS", "" + statusCode);
        if (statusCode == 200) {
            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(content));
            String line;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }
        } else {
            Log.e("Error", "Failed to Login");
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        client.getConnectionManager().closeExpiredConnections();
        client.getConnectionManager().shutdown();
    }

    return builder;
}