List of usage examples for org.apache.http.client HttpClient getConnectionManager
@Deprecated ClientConnectionManager getConnectionManager();
From source file:org.eclipse.json.http.HttpHelper.java
public static JsonValue makeRequest(String url) throws IOException { long startTime = 0; HttpClient httpClient = new DefaultHttpClient(); try {/*from w w w . j a v a 2 s. co m*/ // Post JSON Tern doc HttpGet httpGet = new HttpGet(url); HttpResponse httpResponse = httpClient.execute(httpGet); HttpEntity entity = httpResponse.getEntity(); InputStream in = entity.getContent(); // Check the status StatusLine statusLine = httpResponse.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode != HttpStatus.SC_OK) { // node.js server throws error /* * String message = IOUtils.toString(in); if * (StringUtils.isEmpty(message)) { throw new * TernException(statusLine.toString()); } throw new * TernException(message); */ } try { JsonValue response = JsonValue.readFrom(new InputStreamReader(in)); return response; } catch (ParseException e) { throw new IOException(e); } } catch (Exception e) { if (e instanceof IOException) { throw (IOException) e; } throw new IOException(e); } finally { httpClient.getConnectionManager().shutdown(); } }
From source file:test.java.ecplugins.weblogic.TestUtils.java
/** * callRunProcedure// w w w . j a va 2s .c om * * @param jo * @return the jobId of the job launched by runProcedure */ public static String callRunProcedure(JSONObject jo) throws Exception { props = getProperties(); HttpClient httpClient = new DefaultHttpClient(); JSONObject result = null; try { String encoding = new String( org.apache.commons.codec.binary.Base64.encodeBase64(org.apache.commons.codec.binary.StringUtils .getBytesUtf8(props.getProperty(StringConstants.COMMANDER_USER) + ":" + props.getProperty(StringConstants.COMMANDER_PASSWORD)))); HttpPost httpPostRequest = new HttpPost("http://" + props.getProperty(StringConstants.COMMANDER_SERVER) + ":8000/rest/v1.0/jobs?request=runProcedure"); StringEntity input = new StringEntity(jo.toString()); input.setContentType("application/json"); httpPostRequest.setEntity(input); httpPostRequest.setHeader("Authorization", "Basic " + encoding); HttpResponse httpResponse = httpClient.execute(httpPostRequest); result = new JSONObject(EntityUtils.toString(httpResponse.getEntity())); return result.getString("jobId"); } finally { httpClient.getConnectionManager().shutdown(); } }
From source file:org.neo4j.server.rest.DisableWADLDocIT.java
@Test public void should404OnAnyUriEndinginWADL() throws Exception { URI nodeUri = new URI("http://localhost:7474/db/data/application.wadl"); HttpClient httpclient = new DefaultHttpClient(); try {/*from w w w .java 2 s . com*/ HttpGet httpget = new HttpGet(nodeUri); httpget.setHeader("Accept", "*/*"); HttpResponse response = httpclient.execute(httpget); assertEquals(404, response.getStatusLine().getStatusCode()); } finally { httpclient.getConnectionManager().shutdown(); } }
From source file:com.alu.e3.gateway.loadbalancer.E3HttpClientConfigurer.java
@Override public void configureHttpClient(HttpClient httpClient) { ClientConnectionManager clientConnectionManager = httpClient.getConnectionManager(); HttpParams params = httpClient.getParams(); // set Connection Pool Manager if (clientConnectionManager instanceof ThreadSafeClientConnManager) { setThreadSafeConnectionManager(clientConnectionManager); } else {//ww w . j a va 2s . c o m LOGGER.error( "The given settings for the HttpClient connection pool will be ignored: Unsupported implementation"); } // set HttpClient global setting HttpConnectionParamBean httpConnectionParamBean = new HttpConnectionParamBean(params); if (getSocketTimeOut() != null) { httpConnectionParamBean.setSoTimeout(getSocketTimeOut()); } // set HttpClient global connection timeout if (getConnectionTimeOut() != null) { httpConnectionParamBean.setConnectionTimeout(getConnectionTimeOut()); } // set HttpClient Proxy settings if (getForwardProxy() != null) { setForwardProxy(httpClient, params); } }
From source file:com.lostad.app.base.util.RequestUtil.java
public static String getRequest(final String url, String token, final boolean isSingleton) throws Exception { String json = null;/*from w ww. jav a 2s . c o m*/ HttpClient client = HttpClientManager.getHttpClient(isSingleton); HttpEntity resEntity = null; HttpGet get = new HttpGet(url); if (Validator.isNotEmpty(token)) { get.addHeader("token", token); } try { //long t1 = System.currentTimeMillis(); HttpResponse response = client.execute(get, new BasicHttpContext()); resEntity = response.getEntity(); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {// 200 //? json = EntityUtils.toString(resEntity); } } catch (Exception e) { if (get != null) { get.abort(); } throw e; } finally { if (resEntity != null) { try { resEntity.consumeContent(); } catch (IOException e) { e.printStackTrace(); } } client.getConnectionManager().closeExpiredConnections(); } return json; }
From source file:com.sparkplatform.api.core.HttpClientTest.java
@Test public void testSSL() throws Exception { SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, new TrustManager[] { new ConnectionApacheHttps.FullTrustManager() }, null); HttpClient c = new DefaultHttpClient(); //SSLSocketFactory sf = new SSLSocketFactory(sslContext,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); SSLSocketFactory sf = SSLSocketFactory.getSocketFactory(); @SuppressWarnings("deprecation") Scheme https = new Scheme("https", sf, 443); c.getConnectionManager().getSchemeRegistry().register(https); HttpHost h = new HttpHost("api.flexmls.com", 443, "https"); HttpRequest r = new HttpGet("/v1/"); HttpResponse rs = c.execute(h, r);//ww w . java2s .co m assertEquals(404, rs.getStatusLine().getStatusCode()); String s = readString(rs.getEntity().getContent()); assertEquals(s, "{\"D\":{\"Success\":false,\"Code\":404,\"Message\":\"Not Found\"}}"); }
From source file:com.evrythng.java.wrapper.core.api.ApiCommand.java
/** * Shuts down the connection manager to ensure immediate deallocation of all * system resources./*from w ww. j ava2 s .com*/ * * @param client the {@link HttpClient} to shut down */ protected void shutdown(final HttpClient client) { client.getConnectionManager().shutdown(); }
From source file:org.apache.juddi.v3.tck.JUDDI_200_GUI_IntegrationTest.java
private void runTest(String url) throws Exception { Assume.assumeTrue(TckPublisher.isJUDDI()); Assume.assumeTrue(baseurl != null && baseurl.length() >= 5); HttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); logger.info("Fetching " + httpGet.getURI()); HttpResponse response = client.execute(httpGet); client.getConnectionManager().shutdown(); Assert.assertTrue(//from w w w .ja v a2s.c o m response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase(), response.getStatusLine().getStatusCode() == 200); }
From source file:net.officefloor.tutorials.performance.NginxServicer.java
@Override public void start() throws Exception { // Ensure Nginx running HttpClient client = new DefaultHttpClient(); try {//from w w w . j a v a2s .co m HttpResponse response = client.execute(new HttpGet("http://localhost:" + this.getPort() + "/test.php")); if (response.getStatusLine().getStatusCode() != 200) { throw new Exception("Nginx seems to not be running"); } } finally { client.getConnectionManager().shutdown(); } }
From source file:net.officefloor.tutorials.performance.ApacheServicer.java
@Override public void start() throws Exception { // Ensure Apache running HttpClient client = new DefaultHttpClient(); try {//from w w w . j a va2 s.co m HttpResponse response = client.execute(new HttpGet("http://localhost:" + this.getPort() + "/test.php")); if (response.getStatusLine().getStatusCode() != 200) { throw new Exception("Apache seems to not be running"); } } finally { client.getConnectionManager().shutdown(); } }