diff options
Diffstat (limited to 'eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java')
-rw-r--r-- | eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java | 43 |
1 files changed, 23 insertions, 20 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 dd6f69ee..caa73e04 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 @@ -31,24 +31,25 @@ import java.security.UnrecoverableKeyException; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.net.ssl.SSLContext; -import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang3.StringUtils; -import org.apache.http.HttpRequest; -import org.apache.http.HttpResponse; -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.TrustStrategy; -import org.apache.http.util.EntityUtils; +import org.apache.hc.client5.http.ClientProtocolException; +import org.apache.hc.client5.http.ssl.TrustAllStrategy; +import org.apache.hc.core5.http.ClassicHttpResponse; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.HttpException; +import org.apache.hc.core5.http.HttpRequest; +import org.apache.hc.core5.http.io.HttpClientResponseHandler; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.hc.core5.http.message.StatusLine; +import org.apache.hc.core5.ssl.TrustStrategy; 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 jakarta.servlet.http.HttpServletRequest; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; @@ -62,13 +63,13 @@ public class HttpUtils { * * @return Status-Code of http response */ - public static ResponseHandler<StatusLine> simpleStatusCodeResponseHandler() { - return new ResponseHandler<StatusLine>() { + public static HttpClientResponseHandler<StatusLine> simpleStatusCodeResponseHandler() { + return new HttpClientResponseHandler<StatusLine>() { + @Override - public StatusLine handleResponse(HttpResponse response) throws ClientProtocolException, IOException { + public StatusLine handleResponse(ClassicHttpResponse response) throws HttpException, IOException { EntityUtils.consumeQuietly(response.getEntity()); - return response.getStatusLine(); - + return new StatusLine(response); } }; } @@ -80,15 +81,17 @@ public class HttpUtils { * @return {@link Triple} of http response {@link StatusLine}, http body as {@link InputStream}, * and {@link ContentType} */ - public static ResponseHandler<Triple<StatusLine, ByteArrayInputStream, ContentType>> + public static HttpClientResponseHandler<Triple<StatusLine, ByteArrayInputStream, ContentType>> bodyStatusCodeResponseHandler() { - return new ResponseHandler<Triple<StatusLine, ByteArrayInputStream, ContentType>>() { + return new HttpClientResponseHandler<Triple<StatusLine, ByteArrayInputStream, ContentType>>() { @Override - public Triple<StatusLine, ByteArrayInputStream, ContentType> handleResponse(HttpResponse response) + public Triple<StatusLine, ByteArrayInputStream, ContentType> handleResponse( + ClassicHttpResponse response) throws ClientProtocolException, IOException { byte[] bodyBytes = EntityUtils.toByteArray(response.getEntity()); - return Triple.newInstance(response.getStatusLine(), new ByteArrayInputStream(bodyBytes), - ContentType.getOrDefault(response.getEntity())); + + return Triple.newInstance(new StatusLine(response), new ByteArrayInputStream(bodyBytes), + ContentType.parse(response.getEntity().getContentType())); } }; |