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();
JsonUtils.inputStreamToObject(getMethod.getResponseBodyAsStream(), TableSizeInfo.class); serverToSegmentSizeInfoListMap.put(instance, tableSizeInfo.segments); } catch (Exception e) {
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; }
private boolean performDownload() { try ( InputStream in = request.getResponseBodyAsStream(); OutputStream out = new FileOutputStream(_toFile); ) { IOUtils.copy(in, out); } catch (IOException e) { LOGGER.error("Error downloading template from: " + _downloadUrl + " due to: " + e.getMessage()); return false; } return true; } @Override
HttpClient mockHttpClient = mock(HttpClient.class); when(mockHttpClient.executeMethod(any(GetMethod.class)).thenReturn(HttpStatus.SC_OK); MethodFactory factory = mock(MethodFactory.class); GetMethod get = mock(GetMethod.class); when(factory.createMethod()).thenReturn(get); when(get.getResponseBodyAsStream()).thenReturn(new FileInputStream(source));
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; } /**
protected boolean performDownload() { s_logger.info("Downloading template " + getTemplateId() + " from " + getUrl() + " to: " + getDownloadedFilePath()); try ( InputStream in = request.getResponseBodyAsStream(); OutputStream out = new FileOutputStream(getDownloadedFilePath()); ) { IOUtils.copy(in, out); } catch (IOException e) { s_logger.error("Error downloading template " + getTemplateId() + " due to: " + e.getMessage()); return false; } return true; } }
InputStream is = getMethod.getResponseBodyAsStream(); if (status == HttpStatus.SC_OK) { Map<String, List<String>> metalinkUrlsMap = getMultipleValuesFromXML(is, new String[] {"url"});
try { if (httpClient.executeMethod(getMethod) == HttpStatus.SC_OK) { InputStream is = getMethod.getResponseBodyAsStream(); Map<String, List<String>> metalinkUrls = getMultipleValuesFromXML(is, new String[] {"url"}); if (metalinkUrls.containsKey("url")) {
try (InputStream in = request.getResponseBodyAsStream(); RandomAccessFile out = new RandomAccessFile(file, "rw"); ) {
public static InputStream getInputStreamFromUrl(String url, String user, String password) { try { Pair<String, Integer> hostAndPort = validateUrl(url); HttpClient httpclient = new HttpClient(new MultiThreadedHttpConnectionManager()); if ((user != null) && (password != null)) { httpclient.getParams().setAuthenticationPreemptive(true); Credentials defaultcreds = new UsernamePasswordCredentials(user, password); httpclient.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds); s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second()); } // Execute the method. GetMethod method = new GetMethod(url); int statusCode = httpclient.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { s_logger.error("Failed to read from URL: " + url); return null; } return method.getResponseBodyAsStream(); } catch (Exception ex) { s_logger.error("Failed to read from URL: " + url); return null; } }
inputStream = new BufferedInputStream(getMethod.getResponseBodyAsStream()); } catch (IOException e) { errorString = "Exception occurred while opening InputStream for template " + downloadUrl;
public HttpInputStream(final GetMethod method) throws IOException { super(method.getResponseBodyAsStream()); this.method = method; }
GetMethod get = new GetMethod(href); InputStream in = get.getResponseBodyAsStream(); File file=new File("csv-file-"+ (++filesCounter) + ".csv"); OutputStream out = new FileOutputStream(file); int read = 0; byte[] bytes = new byte[1024]; while ((read = inputStream.read(bytes)) != -1) { out.write(bytes, 0, read); } in.close(); out.flush(); out.close();
protected GeocodeResponse request(final Gson gson, final String urlString) throws IOException { final GetMethod getMethod = new GetMethod(urlString); try { httpClient.executeMethod(getMethod); final Reader reader = new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet()); return gson.fromJson(reader, GeocodeResponse.class); } finally { getMethod.releaseConnection(); } } }
@Override public BufferedReader getResponseBodyAsReader() throws IOException { connect(); inputStream = httpGetMethod.getResponseBodyAsStream(); String charset = httpGetMethod.getRequestCharSet(); InputStreamReader reader = new InputStreamReader(inputStream, Charset.forName(charset)); return new BufferedReader(reader); }
public InputStream executeCometRequest(String url) throws Exception { HttpClient httpClient = HttpClientHelper.createClient(this.beesClientConfiguration); HttpParams params = httpClient.getParams(); params.setIntParameter(HttpConnectionParams.SO_TIMEOUT, 0); GetMethod getMethod = new GetMethod(url); decorateWithAuthorization(getMethod); int code = httpClient.executeMethod(getMethod); if (code >= 300) { processError(getResponseString(getMethod.getResponseBodyAsStream()), code); } return getMethod.getResponseBodyAsStream(); }
HttpClient httpclient = new HttpClient(new MultiThreadedHttpConnectionManager()); GetMethod httpget = new GetMethod("http://www.myhost.com/"); try { httpclient.executeMethod(httpget); Reader reader = new InputStreamReader( httpget.getResponseBodyAsStream(), httpget.getResponseCharSet()); // consume the response entity } finally { httpget.releaseConnection(); }
final HttpClient client = new HttpClient(); final GetMethod method = new GetMethod("http://structureddata.wikispaces.com/Test"); try { if (HttpStatus.SC_OK == client.executeMethod(method)) { System.out.println(IOUtils.toString(method.getResponseBodyAsStream())); } else { throw new IOException("Unable to load page, error " + method.getStatusLine()); } } finally { method.releaseConnection(); }
public InputStream openStream(URL url) throws IOException { GetMethod get = doGet(url, 0); if (!checkStatusCode(url, get)) { get.releaseConnection(); throw new IOException("The HTTP response code for " + url + " did not indicate a success." + " See log for more detail."); } Header encoding = get.getResponseHeader("Content-Encoding"); return getDecodingInputStream(encoding == null ? null : encoding.getValue(), get.getResponseBodyAsStream()); }