List of usage examples for org.apache.http.client HttpClient getConnectionManager
@Deprecated ClientConnectionManager getConnectionManager();
From source file:util.Slack.java
private static void sendMsg(StringEntity jsonMsg, String url) throws IOException { HttpClient httpClient = HttpClientBuilder.create().build(); //Use this instead try {//ww w . j a va2 s . c om HttpPost request = new HttpPost(url); request.addHeader("content-type", "application/json; charset=UTF-8"); request.setEntity(jsonMsg); HttpResponse response = httpClient.execute(request); System.out.println(response); } finally { httpClient.getConnectionManager().shutdown(); //Deprecated } }
From source file:com.foundationdb.http.HttpThreadedLoginIT.java
private static int openRestURL(String userInfo, int port, String path) throws Exception { HttpClient client = new DefaultHttpClient(); URI uri = new URI("http", userInfo, "localhost", port, path, null, null); HttpGet get = new HttpGet(uri); HttpResponse response = client.execute(get); int code = response.getStatusLine().getStatusCode(); EntityUtils.consume(response.getEntity()); client.getConnectionManager().shutdown(); return code;/* w w w . ja v a 2 s .c om*/ }
From source file:com.devdungeon.simplejson.DecodeJson.java
public static String getJsonFromUrl(String url) { HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(url); httpget.setHeader("User-Agent", "Java Reddit Test Client 0.0.1"); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = null;/*from w w w. ja va 2s. c om*/ try { responseBody = httpclient.execute(httpget, responseHandler); } catch (IOException ex) { ex.printStackTrace(); } httpclient.getConnectionManager().shutdown(); return responseBody; }
From source file:org.wso2.bps.integration.tests.bpmn.BPMNTestUtils.java
/** * Returns response after the given DELETE request * * @param url string url suffix to delete the request * @return HttpResponse for the post request * @throws IOException// w w w .ja va2 s.co m */ public static HttpResponse deleteRequest(String url) throws IOException { String restUrl = getRestEndPoint(url); log.info("Sending HTTP DELETE request: " + restUrl); HttpClient client = new DefaultHttpClient(); HttpDelete delete = new HttpDelete(restUrl); delete.addHeader(BasicScheme.authenticate(new UsernamePasswordCredentials("admin", "admin"), Charset.defaultCharset().toString(), false)); client.getConnectionManager().closeExpiredConnections(); HttpResponse response = client.execute(delete); return response; }
From source file:net.netheos.pcsapi.utils.PcsUtils.java
public static void releaseHttpClient(HttpClient httpClient) { if (ANDROID) { // Special close for android if (httpClient instanceof android.net.http.AndroidHttpClient) { ((android.net.http.AndroidHttpClient) httpClient).close(); }/*from w w w.ja v a 2s . co m*/ } httpClient.getConnectionManager().shutdown(); }
From source file:com.base.httpclient.HttpJsonClient.java
/** * http delete//from w w w . j a v a 2 s.c o m * * @param url * URL * @return JSON * @throws ClientProtocolException * @throws IOException */ public static String delete(String url) throws ClientProtocolException, IOException { HttpClient httpclient = new DefaultHttpClient(); try { HttpDelete httpget = new HttpDelete(url); ResponseHandler<String> responseHandler = new BasicResponseHandler(); return httpclient.execute(httpget, responseHandler); } finally { httpclient.getConnectionManager().shutdown(); } }
From source file:com.weavers.duqhan.util.CurrencyConverter.java
public static Double convert(String currencyFrom, String currencyTo) throws IOException { HttpClient httpclient = new DefaultHttpClient(); // HttpGet httpGet = new HttpGet("https://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json"); HttpGet httpGet = new HttpGet("https://cdn.shopify.com/s/javascripts/currencies.js"); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = httpclient.execute(httpGet, responseHandler); httpclient.getConnectionManager().shutdown(); String rates = responseBody.split("rates:")[1].split("convert")[0]; rates = rates.substring(0, rates.length() - 1); ObjectMapper mapper = new ObjectMapper(); CurrencyRates jSONReader = null;/*from w w w .j a va 2 s . c om*/ jSONReader = mapper.readValue(rates, CurrencyRates.class); // System.out.println("ssssssssssss == " + jSONReader.getINR()); double ratio = 0.0; if (currencyTo.equals("USD")) { ratio = jSONReader.getINR() / jSONReader.getUSD(); } else { ratio = jSONReader.getUSD() / jSONReader.getINR(); } return ratio; }
From source file:org.wso2.bps.integration.tests.bpmn.BPMNTestUtils.java
public static HttpResponse doPut(String url, Object payload, String user, String password) throws IOException { String restUrl = getRestEndPoint(url); HttpClient client = new DefaultHttpClient(); HttpPut put = new HttpPut(restUrl); put.addHeader(BasicScheme.authenticate(new UsernamePasswordCredentials(user, password), "UTF-8", false)); put.setEntity(new StringEntity(payload.toString(), ContentType.APPLICATION_JSON)); client.getConnectionManager().closeExpiredConnections(); HttpResponse response = client.execute(put); return response; }
From source file:org.openjena.riot.web.HttpOp.java
/** GET * <p>The acceptHeader string is any legal value for HTTP Accept: field. * <p>The handlers are the set of content types (without charset), * used to dispatch the response body for handling. * <p>A Map entry of ("*",....) is used "no handler found". * <p>HTTP responses 400 and 500 become exceptions. *///from ww w.ja v a 2s.co m public static void execHttpGet(String url, String acceptHeader, Map<String, HttpResponseHandler> handlers) { try { long id = counter.incrementAndGet(); String requestURI = determineRequestURI(url); String baseIRI = determineBaseIRI(requestURI); HttpGet httpget = new HttpGet(requestURI); if (log.isDebugEnabled()) log.debug(format("[%d] %s %s", id, httpget.getMethod(), httpget.getURI().toString())); // Accept if (acceptHeader != null) httpget.addHeader(HttpNames.hAccept, acceptHeader); // Execute HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(httpget); // Handle response httpResponse(id, response, baseIRI, handlers); httpclient.getConnectionManager().shutdown(); } catch (IOException ex) { ex.printStackTrace(System.err); } }
From source file:org.openjena.riot.web.HttpOp.java
/** POST with response body. * <p>The content for the POST body comes from the HttpEntity. * <p>The response is handled bythe handler map, as per {@link #execHttpGet(String, String, Map)} *//*from ww w . j a v a 2 s . co m*/ public static void execHttpPost(String url, HttpEntity provider, String acceptType, Map<String, HttpResponseHandler> handlers) { try { long id = counter.incrementAndGet(); String requestURI = determineBaseIRI(url); String baseIRI = determineBaseIRI(requestURI); HttpPost httppost = new HttpPost(requestURI); if (log.isDebugEnabled()) log.debug(format("[%d] %s %s", id, httppost.getMethod(), httppost.getURI().toString())); if (provider.getContentType() == null) log.debug(format("[%d] No content type")); // Execute HttpClient httpclient = new DefaultHttpClient(); httppost.setEntity(provider); HttpResponse response = httpclient.execute(httppost); httpResponse(id, response, baseIRI, handlers); httpclient.getConnectionManager().shutdown(); } catch (IOException ex) { ex.printStackTrace(System.err); } finally { closeEntity(provider); } }