List of usage examples for org.apache.http.client HttpClient getConnectionManager
@Deprecated ClientConnectionManager getConnectionManager();
From source file:de.uzk.hki.da.webservice.HttpFileTransmissionClient.java
/** * Cleanup.// w w w . j av a2 s .c om * * @throws ClientProtocolException the client protocol exception * @throws IOException Signals that an I/O exception has occurred. */ private void cleanup() { HttpClient httpclient = null; try { httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(url); HttpParams httpRequestParameters = httpget.getParams(); httpRequestParameters.setParameter(ClientPNames.HANDLE_REDIRECTS, true); httpget.setParams(httpRequestParameters); java.net.URI uri = new URIBuilder(httpget.getURI()).addParameter("cleanup", "1").build(); logger.debug("calling webservice for cleanup now. recieving response"); httpget.setURI(uri); HttpResponse response = httpclient.execute(httpget); HttpEntity resEntity = response.getEntity(); printResponse(resEntity); } catch (Exception e) { logger.error("Exception occured in cleanup " + e.getStackTrace()); throw new RuntimeException("Webservice error " + url, e); } finally { if (httpclient != null) httpclient.getConnectionManager().shutdown(); } }
From source file:ecplugins.websphere.TestUtils.java
/** * Creates a new workspace. If the workspace already exists,It continues. * *///w w w. j a v a 2 s .c om static void createCommanderWorkspace() throws Exception { if (!isCommanderWorkspaceCreatedSuccessfully) { HttpClient httpClient = new DefaultHttpClient(); JSONObject jo = new JSONObject(); try { HttpPost httpPostRequest = new HttpPost( "http://" + props.getProperty(StringConstants.COMMANDER_USER) + ":" + props.getProperty(StringConstants.COMMANDER_PASSWORD) + "@" + StringConstants.COMMANDER_SERVER + ":8000/rest/v1.0/workspaces/"); jo.put("workspaceName", StringConstants.WORKSPACE_NAME); jo.put("description", "testAutomationWorkspace"); jo.put("agentDrivePath", "C:/Program Files/Electric Cloud/ElectricCommander"); jo.put("agentUncPath", "C:/Program Files/Electric Cloud/ElectricCommander"); jo.put("agentUnixPath", "/opt/electriccloud/electriccommander"); jo.put("local", true); StringEntity input = new StringEntity(jo.toString()); input.setContentType("application/json"); httpPostRequest.setEntity(input); HttpResponse httpResponse = httpClient.execute(httpPostRequest); if (httpResponse.getStatusLine().getStatusCode() == 409) { System.out.println("Commander workspace already exists.Continuing...."); } else if (httpResponse.getStatusLine().getStatusCode() >= 400) { throw new RuntimeException( "Failed to create commander workspace " + httpResponse.getStatusLine().getStatusCode() + "-" + httpResponse.getStatusLine().getReasonPhrase()); } // Indicate successful creating of workspace isCommanderWorkspaceCreatedSuccessfully = true; } finally { httpClient.getConnectionManager().shutdown(); } } }
From source file:ch.entwine.weblounge.test.harness.rest.PagesEndpointTest.java
/** * Publishes the page.//from ww w.j a v a2s .c o m * * @param serverUrl * the server url * @param id * the page identifier * @throws Exception * if publishing failed */ private void testUnpublishPage(String serverUrl, String id) throws Exception { String requestUrl = UrlUtils.concat(serverUrl, "system/weblounge/pages/"); // Lock the page HttpPut lockPageRequest = new HttpPut(UrlUtils.concat(requestUrl, id, "lock")); HttpClient httpClient = new DefaultHttpClient(); logger.info("Locking the page at {}", requestUrl); try { HttpResponse response = TestUtils.request(httpClient, lockPageRequest, null); assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); } finally { httpClient.getConnectionManager().shutdown(); } // Unpublish it HttpDelete unpublishPageRequest = new HttpDelete(UrlUtils.concat(requestUrl, id, "publish")); httpClient = new DefaultHttpClient(); logger.info("Unpublishing the page at {}", requestUrl); try { HttpResponse response = TestUtils.request(httpClient, unpublishPageRequest, null); assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); } finally { httpClient.getConnectionManager().shutdown(); } // Unlock the page HttpDelete unlockRequest = new HttpDelete(UrlUtils.concat(requestUrl, id, "lock")); httpClient = new DefaultHttpClient(); logger.info("Unlocking the page at {}", requestUrl); try { HttpResponse response = TestUtils.request(httpClient, unlockRequest, null); assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); } finally { httpClient.getConnectionManager().shutdown(); } String requestByIdUrl = UrlUtils.concat(serverUrl, "/weblounge-pages/", id); HttpGet getPageRequest = new HttpGet(requestByIdUrl); httpClient = new DefaultHttpClient(); logger.info("Requesting published page at {}", requestByIdUrl); try { HttpResponse response = TestUtils.request(httpClient, getPageRequest, null); assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatusLine().getStatusCode()); } finally { httpClient.getConnectionManager().shutdown(); } }
From source file:de.unidue.inf.is.ezdl.dlservices.library.manager.referencesystems.connotea.ConnoteaUtils.java
/** send a POST Request and return the response as string */ String sendPostRequest(String url, String bodytext) throws Exception { String sresponse;/* w w w. j ava2s . com*/ HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); // set authentication header httppost.addHeader("Authorization", authHeader); // very important. otherwise there comes a invalid request error httppost.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); StringEntity body = new StringEntity(bodytext); body.setContentType("application/x-www-form-urlencoded"); httppost.setEntity(body); HttpResponse response = httpclient.execute(httppost); // check status code. if (response.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_OK || response.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_CREATED || response.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) { // Not found too. no exception should be thrown. HttpEntity entity = response.getEntity(); sresponse = readResponseStream(entity.getContent()); httpclient.getConnectionManager().shutdown(); } else { HttpEntity entity = response.getEntity(); sresponse = readResponseStream(entity.getContent()); String httpcode = Integer.toString(response.getStatusLine().getStatusCode()); httpclient.getConnectionManager().shutdown(); throw new ReferenceSystemException(httpcode, "Connotea Error", RDFUtils.parseError(sresponse)); } return sresponse; }
From source file:uk.ac.brighton.ci360.bigarrow.PlacesAPISearch.java
@SuppressWarnings("unused") private HttpClient sslClient(HttpClient client) { try {/* w w w.ja va 2s .c om*/ 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; } }; SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new MySSLSocketFactory(ctx); ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = client.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", ssf, 443)); return new DefaultHttpClient(ccm, client.getParams()); } catch (Exception ex) { return null; } }
From source file:ch.entwine.weblounge.test.harness.rest.PagesEndpointTest.java
/** * Deletes the page./*from w w w . ja v a 2 s. c o m*/ * * @param serverUrl * the server url * @param id * the page id * @throws Exception * if deletion failed */ private void testDeletePage(String serverUrl, String id) throws Exception { String requestUrl = UrlUtils.concat(serverUrl, "system/weblounge/pages"); HttpDelete deleteRequest = new HttpDelete(UrlUtils.concat(requestUrl, pageId)); HttpClient httpClient = new DefaultHttpClient(); // Delete the page logger.info("Sending delete request to {}", requestUrl); try { HttpResponse response = TestUtils.request(httpClient, deleteRequest, null); assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); } finally { httpClient.getConnectionManager().shutdown(); } // Make sure it's gone logger.info("Make sure page {} is gone", id); HttpGet getPageRequest = new HttpGet(UrlUtils.concat(requestUrl, id)); httpClient = new DefaultHttpClient(); try { HttpResponse response = TestUtils.request(httpClient, getPageRequest, null); assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatusLine().getStatusCode()); } finally { httpClient.getConnectionManager().shutdown(); } }
From source file:org.owasp.goatdroid.herdfinancial.requestresponse.AuthenticatedRestClient.java
private void executeRequest(HttpUriRequest request, String url, Context context) throws KeyManagementException, NoSuchAlgorithmException { HttpClient client = CustomSSLSocketFactory.getNewHttpClient(); HashMap<String, String> proxyInfo = Utils.getProxyMap(context); String proxyHost = proxyInfo.get("proxyHost"); String proxyPort = proxyInfo.get("proxyPort"); if (!(proxyHost.equals("") || proxyPort.equals(""))) { HttpHost proxy = new HttpHost(proxyHost, Integer.parseInt(proxyPort)); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); }/*from ww w . ja v a2s. com*/ HttpResponse httpResponse; try { httpResponse = client.execute(request); responseCode = httpResponse.getStatusLine().getStatusCode(); message = httpResponse.getStatusLine().getReasonPhrase(); HttpEntity entity = httpResponse.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); response = convertStreamToString(instream); instream.close(); } } catch (ClientProtocolException e) { client.getConnectionManager().shutdown(); } catch (IOException e) { client.getConnectionManager().shutdown(); } }
From source file:ch.entwine.weblounge.test.harness.rest.PagesEndpointTest.java
/** * Publishes the page.//w w w .ja va2s . c o m * * @param serverUrl * the server url * @param id * the page identifier * @param path * the page path * @throws Exception * if publishing failed */ private void testPublishPage(String serverUrl, String id, String path) throws Exception { String requestUrl = UrlUtils.concat(serverUrl, "system/weblounge/pages/"); // Lock the page HttpPut lockPageRequest = new HttpPut(UrlUtils.concat(requestUrl, id, "lock")); HttpClient httpClient = new DefaultHttpClient(); logger.info("Locking the page at {}", requestUrl); try { HttpResponse response = TestUtils.request(httpClient, lockPageRequest, null); assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); } finally { httpClient.getConnectionManager().shutdown(); } // Publish it HttpPut publishPageRequest = new HttpPut(UrlUtils.concat(requestUrl, id, "publish")); httpClient = new DefaultHttpClient(); logger.info("Publishing the page at {}", requestUrl); try { HttpResponse response = TestUtils.request(httpClient, publishPageRequest, null); assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); } finally { httpClient.getConnectionManager().shutdown(); } // Unlock the page HttpDelete unlockRequest = new HttpDelete(UrlUtils.concat(requestUrl, id, "lock")); httpClient = new DefaultHttpClient(); logger.info("Unlocking the page at {}", requestUrl); try { HttpResponse response = TestUtils.request(httpClient, unlockRequest, null); assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); } finally { httpClient.getConnectionManager().shutdown(); } // Make sure the published page is reachable // Wait a second, since when publishing the page, we cut off the millisecond // portion of the publishing start date Thread.sleep(1000); // Get the page using its id String requestByIdUrl = UrlUtils.concat(serverUrl, "/weblounge-pages/", id); HttpGet getPageRequest = new HttpGet(requestByIdUrl); httpClient = new DefaultHttpClient(); logger.info("Requesting published page at {}", requestByIdUrl); try { HttpResponse response = TestUtils.request(httpClient, getPageRequest, null); assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); } finally { httpClient.getConnectionManager().shutdown(); } // Get the page using its path String requestByPathUrl = UrlUtils.concat(serverUrl, path); getPageRequest = new HttpGet(requestByPathUrl); httpClient = new DefaultHttpClient(); logger.info("Requesting published page at {}", requestByPathUrl); try { HttpResponse response = TestUtils.request(httpClient, getPageRequest, null); assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); } finally { httpClient.getConnectionManager().shutdown(); } }
From source file:ui.shared.URLReader.java
private DefaultHttpClient getSecuredHttpClient(HttpClient httpClient) throws Exception { final X509Certificate[] _AcceptedIssuers = new X509Certificate[] {}; try {//from ww w . j a v a 2s. c om SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return _AcceptedIssuers; } public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { } public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { } }; ctx.init(null, new TrustManager[] { tm }, new SecureRandom()); SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = httpClient.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", 443, ssf)); return new DefaultHttpClient(ccm, httpClient.getParams()); } catch (Exception e) { throw e; } }
From source file:no.kantega.kwashc.server.test.SSLCipherSuiteTest.java
private HttpResponse checkClientForCiphers(Site site, int httpsPort, HttpClient httpclient, String[] ciphers) throws NoSuchAlgorithmException, KeyManagementException, IOException { SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, new TrustManager[] { allowAllTrustManager }, null); SSLSocketFactory sf = new SSLSocketFactory(sslcontext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 1000); params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 1000); SSLSocket socket = (SSLSocket) sf.createSocket(params); socket.setEnabledCipherSuites(ciphers); URL url = new URL(site.getAddress()); InetSocketAddress address = new InetSocketAddress(url.getHost(), httpsPort); sf.connectSocket(socket, address, null, params); Scheme sch = new Scheme("https", httpsPort, sf); httpclient.getConnectionManager().getSchemeRegistry().register(sch); HttpGet request = new HttpGet( "https://" + url.getHost() + ":" + site.getSecureport() + url.getPath() + "blog"); return httpclient.execute(request); }