Class ResponseWithBody<R,​B>

  • Type Parameters:
    R - the type of the original response body
    B - 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 for HttpResponse that allows mappi ng the response body from type R to type B.

    This class delegates all methods to the original response, except for body(), which returns the mapped body. The mapping is performed using the provided bodyMapper function 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 new ResponseWithBody by wrapping an existing HttpResponse with a pre-computed body value.
      ResponseWithBody​(java.net.http.HttpResponse<R> original, java.util.function.Function<R,​B> bodyMapper)
      Constructs a new ResponseWithBody by wrapping an existing HttpResponse and applying a mapping function to its body.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      B body()  
      java.net.http.HttpHeaders headers()  
      java.util.Optional<java.net.http.HttpResponse<B>> previousResponse()  
      java.net.http.HttpRequest request()  
      java.util.Optional<javax.net.ssl.SSLSession> sslSession()  
      int statusCode()  
      java.net.URI uri()  
      java.net.http.HttpClient.Version version()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ResponseWithBody

        public ResponseWithBody​(java.net.http.HttpResponse<R> original,
                                java.util.function.Function<R,​B> bodyMapper)
        Constructs a new ResponseWithBody by wrapping an existing HttpResponse and applying a mapping function to its body.
        Parameters:
        original - the original response to wrap
        bodyMapper - a function to map the original body to the new body type
      • ResponseWithBody

        public ResponseWithBody​(java.net.http.HttpResponse<R> original,
                                B body)
        Constructs a new ResponseWithBody by wrapping an existing HttpResponse with a pre-computed body value.
        Parameters:
        original - the original response to wrap
        body - the pre-computed body value
    • Method Detail

      • statusCode

        public int statusCode()
        Specified by:
        statusCode in interface java.net.http.HttpResponse<R>
      • request

        public java.net.http.HttpRequest request()
        Specified by:
        request in interface java.net.http.HttpResponse<R>
      • previousResponse

        public java.util.Optional<java.net.http.HttpResponse<B>> previousResponse()
        Specified by:
        previousResponse in interface java.net.http.HttpResponse<R>
      • headers

        public java.net.http.HttpHeaders headers()
        Specified by:
        headers in interface java.net.http.HttpResponse<R>
      • body

        public B body()
        Specified by:
        body in interface java.net.http.HttpResponse<R>
      • sslSession

        public java.util.Optional<javax.net.ssl.SSLSession> sslSession()
        Specified by:
        sslSession in interface java.net.http.HttpResponse<R>
      • uri

        public java.net.URI uri()
        Specified by:
        uri in interface java.net.http.HttpResponse<R>
      • version

        public java.net.http.HttpClient.Version version()
        Specified by:
        version in interface java.net.http.HttpResponse<R>