GetMethod get = new GetMethod("http://httpcomponents.apache.org"); // execute method and handle any error responses. ... InputStream in = get.getResponseBodyAsStream(); // Process the data from the input stream. get.releaseConnection();
} finally { method.releaseConnection();
throw new RuntimeException(e); } finally { get.releaseConnection(); this.httpClientPool.returnObject(httpClient);
} finally { method.releaseConnection();
} finally { if (method != null) { method.releaseConnection();
throw new RuntimeException(e); } finally { get.releaseConnection(); this.httpClientPool.returnObject(httpClient);
// Create an instance of HttpClient. HttpClient client = new HttpClient(); // Create a method instance. GetMethod method = new GetMethod(url); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); try { // Execute the method. int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + method.getStatusLine()); } // Read the response body. byte[] responseBody = method.getResponseBody(); // Deal with the response. // Use caution: ensure correct character encoding and is not binary data System.out.println(new String(responseBody)); } catch (HttpException e) { System.err.println("Fatal protocol violation: " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println("Fatal transport error: " + e.getMessage()); e.printStackTrace(); } finally { // Release the connection. method.releaseConnection(); }
throw new SchemaRegistryException(e); } finally { get.releaseConnection(); this.httpClientPool.returnObject(httpClient);
throw new SchemaRegistryException(e); } finally { get.releaseConnection(); this.httpClientPool.returnObject(httpClient);
getMethod.releaseConnection();
public Get get(String uri, Class c) { GetMethod get = new GetMethod("http://127.0.0.1:54321/" + uri); Get res = new Get(); try { res._status = _client.executeMethod(get); if( res._status == 200 ) { Gson gson = new Gson(); res._res = gson.fromJson(new InputStreamReader(get.getResponseBodyAsStream()), c); } } catch( Exception e ) { throw new RuntimeException(e); } get.releaseConnection(); return res; }
@Override public HTTPResponse get(final URL url) throws IOException { GetMethod getMethod = new GetMethod(url.toExternalForm()); getMethod.setDoAuthentication(user != null && password != null); int responseCode = client.executeMethod(getMethod); if (200 != responseCode) { getMethod.releaseConnection(); throw new IOException( "Server returned HTTP error code " + responseCode + " for URL " + url.toExternalForm()); } return new HttpMethodResponse(getMethod); }
@Override public boolean downloadTemplate() { try { int status = client.executeMethod(request); if (status != HttpStatus.SC_OK) { s_logger.warn("Not able to download template, status code: " + status); return false; } return performDownload(); } catch (IOException e) { throw new CloudRuntimeException("Error on HTTP request: " + e.getMessage()); } finally { request.releaseConnection(); } }
public static List<String> getMetalinkChecksums(String url) { HttpClient httpClient = getHttpClient(); GetMethod getMethod = new GetMethod(url); try { if (httpClient.executeMethod(getMethod) == HttpStatus.SC_OK) { InputStream is = getMethod.getResponseBodyAsStream(); Map<String, List<String>> checksums = getMultipleValuesFromXML(is, new String[] {"hash"}); if (checksums.containsKey("hash")) { List<String> listChksum = new ArrayList<>(); for (String chk : checksums.get("hash")) { listChksum.add(chk.replaceAll("\n", "").replaceAll(" ", "").trim()); } return listChksum; } } } catch (IOException e) { e.printStackTrace(); } finally { getMethod.releaseConnection(); } return null; } /**
} catch (IOException e) { s_logger.error("Error retrieving urls form metalink: " + metalinkUrl); getMethod.releaseConnection(); return null; s_logger.warn(e.getMessage()); } finally { getMethod.releaseConnection();
@Override public HTTPResponse get(final URL url) throws IOException { GetMethod getMethod = new GetMethod(url.toExternalForm()); getMethod.setDoAuthentication(user != null && password != null); if (tryGzip) { getMethod.setRequestHeader("Accept-Encoding", "gzip"); } int responseCode = executeMethod(getMethod); if (200 != responseCode) { getMethod.releaseConnection(); throw new IOException( "Server returned HTTP error code " + responseCode + " for URL " + url.toExternalForm()); } return new HttpMethodResponse(getMethod); }
s_logger.warn(e.getMessage()); } finally { getMethod.releaseConnection();
throw new BigSwitchBcfApiException(e); } finally { gm.releaseConnection();
getMethod.releaseConnection(); s_logger.error("Failed to retrieve object : " + errorMessage); throw new NeutronRestApiException("Failed to retrieve object : " + errorMessage); throw new NeutronRestApiException(e); } finally { getMethod.releaseConnection();