List of usage examples for org.apache.http.client HttpClient getConnectionManager
@Deprecated ClientConnectionManager getConnectionManager();
From source file:spark.protocol.ProtocolDataSource.java
@Override public void close() { HttpClient client = null; synchronized (this) { client = httpClient;/*from ww w . j a v a 2s. c o m*/ httpClient = null; } if (client != null) { client.getConnectionManager().shutdown(); } }
From source file:ecplugins.s3.TestUtils.java
/** * waitForJob: Waits for job to be completed and reports outcome * * @param jobId/*from w w w . j a va 2 s .com*/ * @return outcome of job */ static String getJobStatus(String jobId) throws IOException, JSONException { HttpClient httpClient = new DefaultHttpClient(); String output = ""; HttpGet httpGetRequest = new HttpGet("http://" + props.getProperty(StringConstants.COMMANDER_USER) + ":" + props.getProperty(StringConstants.COMMANDER_PASSWORD) + "@" + StringConstants.COMMANDER_SERVER + ":8000/rest/v1.0/jobs/" + jobId + "?request=getJobDetails"); try { HttpResponse httpResponse = httpClient.execute(httpGetRequest); if (httpResponse.getStatusLine().getStatusCode() >= 400) { throw new RuntimeException("HTTP GET failed with " + httpResponse.getStatusLine().getStatusCode() + "-" + httpResponse.getStatusLine().getReasonPhrase()); } output = new JSONObject(EntityUtils.toString(httpResponse.getEntity())).getJSONObject("job") .getJSONArray("jobStep").getJSONObject(0).getJSONObject("propertySheet") .getJSONArray("property").getJSONObject(1).getString("value"); } finally { httpClient.getConnectionManager().shutdown(); } return output; }
From source file:net.sf.appstatus.demo.check.AbstractHttpCheck.java
protected String doHttpGet(String url) throws ClientProtocolException, IOException { HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(url); ResponseHandler<String> responseHandler = new BasicResponseHandler(); try {//from w ww . j a v a 2 s . c o m String responseBody = httpclient.execute(httpget, responseHandler); return responseBody; } finally { httpclient.getConnectionManager().shutdown(); } }
From source file:org.lorislab.armonitor.jira.client.JIRAClient.java
/** * Creates the JIRA client.//from w ww .j av a 2 s. c o m * * @param server the server URL. * @param username the username. * @param password the password. * @param auth the authentication flag. * @throws Exception if the method fails. */ public JIRAClient(String server, String username, char[] password, boolean auth) throws Exception { this.server = server; HttpClient httpClient = new DefaultHttpClient(); if (server.startsWith(HTTPS)) { SSLSocketFactory sslSocketFactory = new SSLSocketFactory(new TrustSelfSignedStrategy(), SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); httpClient.getConnectionManager().getSchemeRegistry() .register(new Scheme(HTTPS, 443, sslSocketFactory)); } if (auth) { this.executor = new JiraApacheHttpClient4Executor(username, password, httpClient); } }
From source file:org.openremote.android.console.util.AsyncGroupLoader.java
@Override public void run() { synchronized (this) { String server = AppSettingsModel.getSecuredServer(context); if (!TextUtils.isEmpty(server)) { HttpResponse response = null; try { URL url = new URL(server + "/rest/device/group"); HttpGet request = new HttpGet(url.toString()); HttpClient client = new DefaultHttpClient(); Scheme sch = new Scheme(url.getProtocol(), new SelfCertificateSSLSocketFactory(context), url.getPort());/*from w ww . ja va 2 s.co m*/ client.getConnectionManager().getSchemeRegistry().register(sch); response = client.execute(request); } catch (ClientProtocolException e) { Log.e(LOG_CATEGORY + " run:", e.getMessage()); } catch (IOException e) { Log.e(LOG_CATEGORY + " run:", e.getMessage()); } String group = ""; if (response != null && response.getStatusLine().getStatusCode() == 200) { String tmp; try { BufferedReader in = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); while ((tmp = in.readLine()) != null) { group += tmp; } } catch (IOException e) { Log.e(LOG_CATEGORY + " urlConnectionDidReceiveData:", e.getMessage()); } } AppSettingsModel.setGroup(context, group); } done = true; notify(); } }
From source file:com.appdynamics.openstack.nova.RestClient.java
static HttpClient httpClientWithTrustManager() throws KeyManagementException, NoSuchAlgorithmException { HttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, timeout); httpClient.getParams().setParameter("http.connection-manager.max-per-host", 1); X509TrustManager tm = new X509TrustManager() { @Override/* w w w . j ava 2 s. co m*/ public X509Certificate[] getAcceptedIssuers() { // TODO Auto-generated method stub return null; } @Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { // TODO Auto-generated method stub } @Override public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { // TODO Auto-generated method stub } }; SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx); ClientConnectionManager ccm = httpClient.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", ssf, 443)); // Scheme("https", ssf, 443)); return new DefaultHttpClient(ccm, httpClient.getParams()); }
From source file:com.jzc.rfid.cl.listeners.RFIDTagGainListener.java
public void tagGained(TagGainEvent tagGainEvent) { System.out.println(Main.readerId + " " + tagGainEvent.getValue()); final String tagValue = tagGainEvent.getValue(); new Thread(new Runnable() { public void run() { try { List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("cardId", tagValue)); qparams.add(new BasicNameValuePair("readerId", Integer.toString(Main.readerId))); String url = "http://www.electric20.com/thermaPref/cardEvent.php"; HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(qparams, HTTP.UTF_8)); HttpClient httpClient = new DefaultHttpClient(); //HttpHost proxy = new HttpHost("mainproxy.nottingham.ac.uk",8080); //httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); httpClient.execute(httpPost); httpClient.getConnectionManager().closeExpiredConnections(); System.out.println(httpPost.getURI()); } catch (Exception e) { e.printStackTrace();/*w ww.j av a 2s .c o m*/ } } }).start(); try { rfid.setLEDOn(!rfid.getLEDOn()); } catch (PhidgetException e) { e.printStackTrace(); } }
From source file:org.apache.camel.component.cxf.jaxrs.CxfRsConvertBodyToTest.java
@Test public void testPutConsumer() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1);//from w w w. j av a2 s .c om mock.message(0).body().isInstanceOf(Customer.class); 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); 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:org.openntf.xpt.agents.master.ClientSSLResistanceExtender.java
public static HttpClient wrapClient(HttpClient base) { try {//w w w . j av a 2s .c o m SSLContext ctx = SSLContext.getInstance("sslv3"); X509TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; X509HostnameVerifier verifier = new X509HostnameVerifier() { public void verify(String arg0, SSLSocket arg1) throws IOException { } public void verify(String arg0, X509Certificate arg1) throws SSLException { } public void verify(String arg0, String[] arg1, String[] arg2) throws SSLException { } public boolean verify(String hostname, SSLSession session) { return true; } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx, verifier); ClientConnectionManager ccm = base.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", 443, ssf)); return new DefaultHttpClient(ccm, base.getParams()); } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:android.net.http.HttpsThroughHttpProxyTest.java
public void testConnectViaHttps() throws IOException, InterruptedException { TestSSLContext testSSLContext = TestSSLContext.create(); MockWebServer server = new MockWebServer(); server.useHttps(testSSLContext.serverContext.getSocketFactory(), false); server.enqueue(new MockResponse().setResponseCode(200).setBody("this response comes via HTTPS")); server.play();// w ww . jav a2s . c o m HttpClient httpClient = new DefaultHttpClient(); SSLSocketFactory sslSocketFactory = new SSLSocketFactory(testSSLContext.clientContext.getSocketFactory()); 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()); }