Class WebLinkingResponse

java.lang.Object
com.jcabi.http.response.WebLinkingResponse
All Implemented Interfaces:
Response

@Immutable public final class WebLinkingResponse extends Object
Web Linking response.

This response decorator is able to understand and parse Link HTTP header according to RFC 5988 "Web Linking", for example:

 String name = new JdkRequest("http://my.example.com")
   .fetch()
   .as(WebLinkingResponse.class)
   .follow("next")
   .fetch();

The class is immutable and thread-safe.

Since:
0.9
See Also:
  • Constructor Details

    • WebLinkingResponse

      public WebLinkingResponse(Response resp)
      Public ctor.
      Parameters:
      resp - Response
  • Method Details

    • follow

      public Request follow(String rel) throws IOException
      Follow link by REL.
      Parameters:
      rel - Relation name
      Returns:
      The same object
      Throws:
      IOException - If fails
    • links

      Get all links provided.
      Returns:
      List of all links found
      Throws:
      IOException - If fails
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • back

      public final Request back()
      Description copied from interface: Response
      Get back to the request it's related to.
      Specified by:
      back in interface Response
      Returns:
      The request we're in
    • status

      public final int status()
      Description copied from interface: Response
      Get status of the response as a positive integer number.
      Specified by:
      status in interface Response
      Returns:
      The status code
    • reason

      public final String reason()
      Description copied from interface: Response
      Get status line reason phrase.
      Specified by:
      reason in interface Response
      Returns:
      The status line reason phrase
    • headers

      public final Map<String,List<String>> headers()
      Description copied from interface: Response
      Get a collection of all headers.
      Specified by:
      headers in interface Response
      Returns:
      The headers
    • body

      public String body()
      Description copied from interface: Response
      Get body as a string, assuming it's UTF-8 (if there is something else that can't be translated into a UTF-8 string a runtime exception will be thrown).

      DISCLAIMER: The only encoding supported here is UTF-8. If the body of response contains any chars that can't be used and should be replaced with a "replacement character", a RuntimeException will be thrown. If you need to use some other encodings, use Response.binary() instead.

      Specified by:
      body in interface Response
      Returns:
      The body, as a UTF-8 string
    • binary

      public final byte[] binary()
      Description copied from interface: Response
      Raw body as an array of bytes.
      Specified by:
      binary in interface Response
      Returns:
      The body, as a UTF-8 string
    • as

      public final <T extends Response> T as(Class<T> type)
      Description copied from interface: Response
      Convert it to another type, by encapsulation.
      Specified by:
      as in interface Response
      Type Parameters:
      T - Type to use
      Parameters:
      type - Type to use
      Returns:
      New response