summaryrefslogtreecommitdiff
path: root/eaaf_core_utils/src/main
diff options
context:
space:
mode:
authorThomas Lenz <thomas.lenz@egiz.gv.at>2021-01-07 18:43:44 +0100
committerThomas Lenz <thomas.lenz@egiz.gv.at>2021-01-07 18:43:44 +0100
commit6be8d86f14011d6437b138f16b2a44062af10139 (patch)
tree7cd8ebb90235ed0016e32543df91aa10b52d0579 /eaaf_core_utils/src/main
parent013febf9435d0aa3536897b3636787ae3ba15935 (diff)
downloadEAAF-Components-6be8d86f14011d6437b138f16b2a44062af10139.tar.gz
EAAF-Components-6be8d86f14011d6437b138f16b2a44062af10139.tar.bz2
EAAF-Components-6be8d86f14011d6437b138f16b2a44062af10139.zip
add a second Apache Http-Client response-handler as default implementation
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