summaryrefslogtreecommitdiff
path: root/eaaf_core_utils/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'eaaf_core_utils/src/main')
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java
index 10555822..365e969d 100644
--- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java
+++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java
@@ -18,7 +18,9 @@
package at.gv.egiz.eaaf.core.impl.http;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
@@ -37,6 +39,7 @@ import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.conn.ssl.TrustAllStrategy;
+import org.apache.http.entity.ContentType;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.ssl.TrustStrategy;
@@ -46,6 +49,7 @@ import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;
import at.gv.egiz.eaaf.core.exceptions.EaafConfigurationException;
import at.gv.egiz.eaaf.core.exceptions.EaafFactoryException;
import at.gv.egiz.eaaf.core.impl.data.Pair;
+import at.gv.egiz.eaaf.core.impl.data.Triple;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@@ -71,6 +75,27 @@ public class HttpUtils {
}
/**
+ * Http response-handler that gives a pair of http status-code,
+ * a copy of the full http-body as {@link InputStream} and the response {@link ContentType}.
+ *
+ * @return {@link Triple} of http response {@link StatusLine}, http body as {@link InputStream},
+ * and {@link ContentType}
+ */
+ public static ResponseHandler<Triple<StatusLine, ByteArrayInputStream, ContentType>>
+ bodyStatusCodeResponseHandler() {
+ return new ResponseHandler<Triple<StatusLine, ByteArrayInputStream, ContentType>>() {
+ @Override
+ public Triple<StatusLine, ByteArrayInputStream, ContentType> handleResponse(HttpResponse response)
+ throws ClientProtocolException, IOException {
+ byte[] bodyBytes = EntityUtils.toByteArray(response.getEntity());
+ return Triple.newInstance(response.getStatusLine(), new ByteArrayInputStream(bodyBytes),
+ ContentType.getOrDefault(response.getEntity()));
+
+ }
+ };
+ }
+
+ /**
* Helper method to retrieve server URL including context path.
*
* @param request HttpServletRequest