@Immutable public final class WebLinkingResponse extends Object
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.
Modifier and Type | Class and Description |
---|---|
static interface |
WebLinkingResponse.Link
Single link.
|
Constructor and Description |
---|
WebLinkingResponse(Response resp)
Public ctor.
|
Modifier and Type | Method and Description |
---|---|
<T> T |
as(Class<T> type)
Convert it to another type, by encapsulation.
|
Request |
back()
Get back to the request it's related to.
|
byte[] |
binary()
Raw body as a an array of bytes.
|
String |
body()
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). |
Request |
follow(String rel)
Follow link by REL.
|
Map<String,List<String>> |
headers()
Get a collection of all headers.
|
Map<String,WebLinkingResponse.Link> |
links()
Get all links provided.
|
String |
reason()
Get status line reason phrase.
|
int |
status()
Get status of the response as a positive integer number.
|
String |
toString() |
public WebLinkingResponse(@NotNull(message="response can\'t be NULL") Response resp)
resp
- Response@NotNull(message="response is never NULL") public Request follow(@NotNull(message="rel can\'t be NULL") String rel) throws IOException
rel
- Relation nameIOException
- If fails@NotNull(message="list of links is never NULL") public Map<String,WebLinkingResponse.Link> links() throws IOException
IOException
- If failspublic final Request back()
Response
public final int status()
Response
public final String reason()
Response
public final Map<String,List<String>> headers()
Response
public final String body()
Response
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.
public final byte[] binary()
Response
Copyright © 2012–2014 jcabi.com. All rights reserved.