/** * Gets an input stream for the HttpMethod response body. * @throws IOException If an IO problem occurs. * @return The input stream. * @see java.net.HttpURLConnection#getInputStream() * @see org.apache.commons.httpclient.HttpMethod#getResponseBodyAsStream() */ public InputStream getInputStream() throws IOException { LOG.trace("enter HttpURLConnection.getInputStream()"); return this.method.getResponseBodyAsStream(); }
public ResponseInputStream(HttpMethod http) throws IOException { super(http.getResponseBodyAsStream()); this.method = http; reusable = (delegate() instanceof ByteArrayInputStream); }
@Override public InputStream copy() { try { return (reusable ? method.getResponseBodyAsStream() : null); } catch (IOException ex) { throw new EsHadoopIllegalStateException(ex); } }
HttpClient httpclient = new DefaultHttpClient(); // truststore KeyStore ts = KeyStore.getInstance("JKS", "SUN"); ts.load(PostService.class.getResourceAsStream("/truststore.jks"), "amber%".toCharArray()); // if you remove me, you've got 'javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated' on missing truststore if(0 == ts.size()) throw new IOException("Error loading truststore"); // tmf TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); tmf.init(ts); // keystore KeyStore ks = KeyStore.getInstance("PKCS12", "SunJSSE"); ks.load(PostService.class.getResourceAsStream("/" + certName), certPwd.toCharArray()); // if you remove me, you've got 'javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated' on missing keystore if(0 == ks.size()) throw new IOException("Error loading keystore"); // kmf KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmf.init(ks, certPwd.toCharArray()); // SSL SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); // socket SSLSocketFactory socketFactory = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme sch = new Scheme("https", 8443, socketFactory); httpclient.getConnectionManager().getSchemeRegistry().register(sch); // request HttpMethod get = new GetMethod("https://localhost:8443/foo"); client.executeMethod(get); IOUtils.copy(get.getResponseBodyAsStream(), System.out);
String responseBody = IOUtils.toString(method.getResponseBodyAsStream()); if (!responseBody.isEmpty()) { logger.debug("{}", responseBody);
@Override public InputStream getResponseStream() throws IOException { if (responseBodyAsStream == null) { responseBodyAsStream = methodResponse.getResponseBodyAsStream(); } return responseBodyAsStream; }
public InputStream getContent() throws IOException { return httpMethod.getResponseBodyAsStream(); }
if (method.getResponseBodyAsStream() != null) { method.getResponseBodyAsStream().close(); (releaseConnection || method.getResponseBodyAsStream() == null) && this.conn != null ) {
@Override public InputStream getResponseStream() throws IOException { if (responseBodyAsStream == null) { responseBodyAsStream = methodResponse.getResponseBodyAsStream(); // commons httpclient does not handle gzip encoding automatically, we have to check // ourselves: https://issues.apache.org/jira/browse/HTTPCLIENT-816 Header header = methodResponse.getResponseHeader("Content-Encoding"); if (header != null && "gzip".equals(header.getValue())) { responseBodyAsStream = new GZIPInputStream(responseBodyAsStream); } } return responseBodyAsStream; }
private InputStream setupInputStream(URL url, Map<String, String> headers) throws IOException { HttpClient client = new HttpClient(); String uri = url.toExternalForm(); if (LOGGER.isLoggable(Level.FINE)) LOGGER.log(Level.FINE, "URL is " + uri); HttpMethod get = new GetMethod(uri); if (MapUtils.isNotEmpty(headers)) { for (String headerName : headers.keySet()) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log( Level.FINE, "Adding header " + headerName + " = " + headers.get(headerName)); } get.addRequestHeader(headerName, headers.get(headerName)); } } int code = client.executeMethod(get); if (code != 200) { throw new IOException("Connection returned code " + code); } return get.getResponseBodyAsStream(); } }
HttpMethod method = new GetMethod(url); if (client.executeMethod(method) == 200) { InputStream is = method.getResponseBodyAsStream(); XStream xstream = new XStream(new DomDriver()); xstream.alias("useraccount", UserAccountVO.class);
HttpMethod method = new GetMethod(url); if (client.executeMethod(method) == 200) { InputStream is = method.getResponseBodyAsStream(); XStream xstream = new XStream(new DomDriver());
HttpMethod method = new GetMethod(url); if (client.executeMethod(method) == 200) { InputStream is = method.getResponseBodyAsStream();
public void mockConnection(String responseBody) throws Exception { InputStream is = new ByteArrayInputStream(responseBody.getBytes()); StatusLine statusLine = new StatusLine("HTTP/1.1 200 OK"); this.httpMethodMock = mock(HttpMethod.class); when(httpMethodMock.getStatusLine()).thenReturn(statusLine); when(httpMethodMock.getStatusCode()).thenReturn(200); when(httpMethodMock.getResponseBodyAsStream()).thenReturn(is); } }
@Override public InputStream getResponseStream() throws IOException { if (responseBodyAsStream == null) { responseBodyAsStream = methodResponse.getResponseBodyAsStream(); } return responseBodyAsStream; }
/** * Gets an input stream for the HttpMethod response body. * @throws IOException If an IO problem occurs. * @return The input stream. * @see java.net.HttpURLConnection#getInputStream() * @see org.apache.commons.httpclient.HttpMethod#getResponseBodyAsStream() */ public InputStream getInputStream() throws IOException { LOG.trace("enter HttpURLConnection.getInputStream()"); return this.method.getResponseBodyAsStream(); }
public ResponseInputStream(HttpMethod http) throws IOException { super(http.getResponseBodyAsStream()); this.method = http; reusable = (delegate() instanceof ByteArrayInputStream); }
protected Object extractPayloadFromHttpMethod(HttpMethod httpMethod) throws IOException { InputStream body = httpMethod.getResponseBodyAsStream(); if (body != null) { return new ReleasingInputStream(body, httpMethod); } else { return StringUtils.EMPTY; } }
@Override public InputStream copy() { try { return (reusable ? method.getResponseBodyAsStream() : null); } catch (IOException ex) { throw new EsHadoopIllegalStateException(ex); } }
public ResponseInputStream(HttpMethod http) throws IOException { super(http.getResponseBodyAsStream()); this.method = http; reusable = (delegate() instanceof ByteArrayInputStream); }