List of usage examples for org.apache.http.impl.client DefaultHttpClient getConnectionManager
public synchronized final ClientConnectionManager getConnectionManager()
From source file:com.onesite.commons.net.http.rest.client.RestClient.java
/** * Connect to a Url.//from w w w . j av a 2 s. c o m * URL = scheme://host:port/path?query_string * * @param path * @param params * * @return statusCode */ public int get(String path, Map<String, String> params) throws Exception { String url = this.generateEncodeURLString(path, params); DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet request = new HttpGet(url); request.addHeader("accept", "application/json"); try { HttpResponse response = httpClient.execute(this.target, request); try { this.processHttpResponse(response); } catch (Exception e) { log.error("Error processing HttpResponse from " + url); throw e; } } catch (Exception e) { log.error("Error occurred during calling to " + url); throw e; } finally { httpClient.getConnectionManager().shutdown(); } return status; }
From source file:se.vgregion.incidentreport.pivotaltracker.impl.PivotalTrackerServiceImpl.java
/** */ private TyckTillProjectData getSingleProject(String projectId, String token) throws Exception { if (token == null) { throw new RuntimeException("Token cannot be null. Please set it first."); }//ww w .j a va 2 s. co m DefaultHttpClient client = getNewClient(); TyckTillProjectData result = null; try { HttpResponse response = HTTPUtils.makeRequest(GET_PROJECT + "/" + projectId, token, client); HttpEntity entity = response.getEntity(); // Convert the xml response into an object result = getProjectData(entity.getContent()).get(0); } catch (RuntimeException e) { e.printStackTrace(); } finally { client.getConnectionManager().shutdown(); } return result; }
From source file:org.sonar.updatecenter.server.HttpDownloader.java
File downloadFile(URI fileURI, File toFile, String login, String password) { LOG.info("Download " + fileURI + " in " + toFile); DefaultHttpClient client = new DefaultHttpClient(); try {// ww w.j a v a 2s . co m if (StringUtils.isNotBlank(login)) { client.getCredentialsProvider().setCredentials(new AuthScope(fileURI.getHost(), fileURI.getPort()), new UsernamePasswordCredentials(login, password)); } HttpGet httpget = new HttpGet(fileURI); byte[] data = client.execute(httpget, new ByteResponseHandler()); if (data != null) { FileUtils.writeByteArrayToFile(toFile, data); } } catch (Exception e) { LOG.error("Fail to download " + fileURI + " to " + toFile, e); FileUtils.deleteQuietly(toFile); } finally { client.getConnectionManager().shutdown(); } return toFile; }
From source file:com.meschbach.psi.util.EchoApplication.java
public String echo(String aMessage) throws PSIException { /*//from ww w . j a v a2 s . co m * */ DefaultHttpClient hc = new DefaultHttpClient(); try { String url; try { url = contextURL + "/EchoServlet?input=" + URLEncoder.encode(aMessage, "UTF-8"); } catch (UnsupportedEncodingException uee) { throw new PSIException(uee); } HttpGet get = new HttpGet(url); try { HttpResponse response = hc.execute(get); InputStream entity = response.getEntity().getContent(); String result = Util.convertToString(entity); return result; } catch (IOException t) { throw new PSIException(t); } } finally { hc.getConnectionManager().shutdown(); } }
From source file:org.jenkinsci.plugins.appio.service.AppioService.java
/** * @param appId//from w w w . j a v a 2s . com */ public void deleteApp(String appId) { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpDelete httpDelete = new HttpDelete("/api/apps" + "/" + appId); // App.io Authorization and Content-Type headers String appioAuth = "Basic " + apiKey; httpDelete.addHeader("Authorization", appioAuth); httpDelete.addHeader("Accept", appio_v1); try { LOGGER.fine("AppioService.deleteApp(): deleting app id " + appId); httpClient.execute(httpHost, httpDelete); } catch (Exception e) { e.printStackTrace(); } finally { try { httpClient.getConnectionManager().shutdown(); } catch (Exception ignore) { } } }
From source file:jp.canetrash.maven.plugin.bijint.BujintMojo.java
/** * http://www.bijint.com/ ?????URL??//from w w w. j a v a 2 s . co m * * @return ??URL */ String nowTimeImageUrl() throws Exception { String time = DateFormatUtils.format(new Date(), "hhmm"); DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = buildDefaultHttpMessage(new HttpGet("http://www.bijint.com/cache/" + time + ".html")); httpget.setHeader("Referer", "http://www.bijint.com/jp/"); HttpResponse response = httpclient.execute(httpget); if (response.getStatusLine().getStatusCode() != 200) { getLog().error( "????????????????"); return null; } String result = IOUtils.toString(response.getEntity().getContent(), "UTF-8"); httpclient.getConnectionManager().shutdown(); return "http://www.bijint.com" + getImagePath(result); }
From source file:org.kaaproject.kaa.demo.powerplant.data.RestDataEndpoint.java
private JSONArray fetchJson(HttpGet getRequest) throws IOException, ClientProtocolException, JSONException { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(getRequest); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); }//from w w w. ja v a 2 s.c o m BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); StringBuilder sb = new StringBuilder(); System.out.println("Output from Server .... \n"); String output; while ((output = br.readLine()) != null) { sb.append(output); sb.append(System.getProperty("line.separator")); } httpClient.getConnectionManager().shutdown(); JSONArray jsonArray = new JSONArray(sb.toString()); return jsonArray; }
From source file:com.francetelecom.clara.cloud.activation.plugin.cf.infrastructure.AbstractCfAdapterIT.java
private String fetchRoutedContentAsString(String uri, HttpClientConfig httpClientConfig) throws IOException { String contentA;/*from w ww . j a v a2s. c o m*/ DefaultHttpClient httpclient = new DefaultHttpClient(); if (httpClientConfig != null) { httpClientConfig.applyConfig(httpclient); } try { HttpGet httpget = new HttpGet(uri); contentA = httpclient.execute(httpget, new BasicResponseHandler()); } finally { httpclient.getConnectionManager().shutdown(); } return contentA; }
From source file:BusinessLogic.Controller.RestController.java
public String deletePlan(Integer planId) throws Exception { StringBuilder responseS = new StringBuilder(); try {// w w w . j a v a2 s. c om DefaultHttpClient httpClient = new DefaultHttpClient(); HttpDelete delete = new HttpDelete("http://localhost/JoyCenter/resources/plans" + planId); HttpResponse response = httpClient.execute(delete); if (response.getStatusLine().getStatusCode() != 201) { throw new RuntimeException( "Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output; System.out.println("Output from Server .... \n"); httpClient.getConnectionManager().shutdown(); } catch (IOException e) { e.printStackTrace(); } return "null"; }
From source file:vitro.vgw.wsiadapter.TCSWSIAdapter.java
public static String doHttpGet(String endpoint) { String output;//from w ww .j a v a 2 s. c om String temp = ""; try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet getRequest = new HttpGet(endpoint); getRequest.addHeader("accept", "application/json"); HttpResponse response = httpClient.execute(getRequest); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException( "Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { System.out.println(output); temp = output; } br.close(); httpClient.getConnectionManager().shutdown(); } catch (ClientProtocolException e) { System.err.println("ClientProtocolException\n"); return ""; } catch (IOException e) { System.err.println("IOException\n"); return ""; } return temp; }