From eaa0a2a0828037227312970668eba7bf951b4049 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 23 Dec 2012 00:21:57 +0100 Subject: o Storing the raw bytes with the parsed data from Jenkins. --- .../io/trygvis/esper/testing/util/HttpClient.java | 24 ++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src/main/java/io/trygvis/esper/testing/util') diff --git a/src/main/java/io/trygvis/esper/testing/util/HttpClient.java b/src/main/java/io/trygvis/esper/testing/util/HttpClient.java index a194cd1..69c74fe 100644 --- a/src/main/java/io/trygvis/esper/testing/util/HttpClient.java +++ b/src/main/java/io/trygvis/esper/testing/util/HttpClient.java @@ -3,14 +3,15 @@ package io.trygvis.esper.testing.util; import fj.*; import fj.data.*; import io.trygvis.esper.testing.*; +import org.apache.commons.io.*; import org.apache.http.conn.scheme.*; import org.apache.http.impl.client.*; import org.apache.http.impl.conn.tsccm.*; import org.apache.http.params.*; import org.codehaus.httpcache4j.*; import org.codehaus.httpcache4j.cache.*; +import org.codehaus.httpcache4j.payload.*; import org.codehaus.httpcache4j.resolver.*; -import org.h2.util.*; import org.slf4j.*; import java.io.*; @@ -39,13 +40,13 @@ public class HttpClient { try { return f.f(inputStream); } finally { - IOUtils.closeSilently(inputStream); + IOUtils.closeQuietly(inputStream); } } }; } - public Option fetch(URI uri) { + public Option> fetch(URI uri) { HTTPResponse response = null; try { @@ -57,10 +58,25 @@ public class HttpClient { return none(); } - return f.f(response); + final ByteArrayOutputStream buffer = new ByteArrayOutputStream(1024 * 1024); + + IOUtils.copy(response.getPayload().getInputStream(), buffer); + + final byte[] bytes = buffer.toByteArray(); + + response = new HTTPResponse(new ByteArrayPayload(new ByteArrayInputStream(bytes), response.getPayload().getMimeType()), response.getStatusLine(), response.getHeaders()); + + return f.f(response).map(new F>() { + public P2 f(A a) { + return P.p(a, bytes); + } + }); } catch (HTTPException e) { logger.warn("Error while fetching: " + uri, e); return none(); + } catch (IOException e) { + logger.warn("Error while fetching: " + uri, e); + return none(); } finally { if (response != null) { try { -- cgit v1.2.3