Package pl.gsmservice.gateway.utils
Class ResponseWithBody<R,B>
- java.lang.Object
-
- pl.gsmservice.gateway.utils.ResponseWithBody<R,B>
-
- Type Parameters:
R- the type of the original response bodyB- the type of the mapped response body
- All Implemented Interfaces:
java.net.http.HttpResponse<B>
public class ResponseWithBody<R,B> extends java.lang.Object implements java.net.http.HttpResponse<B>A wrapper forHttpResponsethat allows mappi ng the response body from typeRto typeB.This class delegates all methods to the original response, except for
body(), which returns the mapped body. The mapping is performed using the providedbodyMapperfunction at construction time.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface java.net.http.HttpResponse
java.net.http.HttpResponse.BodyHandler<T extends java.lang.Object>, java.net.http.HttpResponse.BodyHandlers, java.net.http.HttpResponse.BodySubscriber<T extends java.lang.Object>, java.net.http.HttpResponse.BodySubscribers, java.net.http.HttpResponse.PushPromiseHandler<T extends java.lang.Object>, java.net.http.HttpResponse.ResponseInfo
-
-
Constructor Summary
Constructors Constructor Description ResponseWithBody(java.net.http.HttpResponse<R> original, B body)Constructs a newResponseWithBodyby wrapping an existingHttpResponsewith a pre-computed body value.ResponseWithBody(java.net.http.HttpResponse<R> original, java.util.function.Function<R,B> bodyMapper)Constructs a newResponseWithBodyby wrapping an existingHttpResponseand applying a mapping function to its body.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Bbody()java.net.http.HttpHeadersheaders()java.util.Optional<java.net.http.HttpResponse<B>>previousResponse()java.net.http.HttpRequestrequest()java.util.Optional<javax.net.ssl.SSLSession>sslSession()intstatusCode()java.net.URIuri()java.net.http.HttpClient.Versionversion()
-
-
-
Constructor Detail
-
ResponseWithBody
public ResponseWithBody(java.net.http.HttpResponse<R> original, java.util.function.Function<R,B> bodyMapper)
Constructs a newResponseWithBodyby wrapping an existingHttpResponseand applying a mapping function to its body.- Parameters:
original- the original response to wrapbodyMapper- a function to map the original body to the new body type
-
-
Method Detail
-
statusCode
public int statusCode()
- Specified by:
statusCodein interfacejava.net.http.HttpResponse<R>
-
request
public java.net.http.HttpRequest request()
- Specified by:
requestin interfacejava.net.http.HttpResponse<R>
-
previousResponse
public java.util.Optional<java.net.http.HttpResponse<B>> previousResponse()
- Specified by:
previousResponsein interfacejava.net.http.HttpResponse<R>
-
headers
public java.net.http.HttpHeaders headers()
- Specified by:
headersin interfacejava.net.http.HttpResponse<R>
-
sslSession
public java.util.Optional<javax.net.ssl.SSLSession> sslSession()
- Specified by:
sslSessionin interfacejava.net.http.HttpResponse<R>
-
uri
public java.net.URI uri()
- Specified by:
uriin interfacejava.net.http.HttpResponse<R>
-
version
public java.net.http.HttpClient.Version version()
- Specified by:
versionin interfacejava.net.http.HttpResponse<R>
-
-