Package com.jcabi.http.response
Class JsoupResponse
- java.lang.Object
-
- com.jcabi.http.response.JsoupResponse
-
- All Implemented Interfaces:
Response
@Immutable public final class JsoupResponse extends Object
Jsoup response.This response decorator is able to parse HTTP response body as an HTML document. Example usage:
String body = new JdkRequest("http://my.example.com") .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON) .fetch() .as(JsoupResponse.class) .body();
body()
will try to output clean HTML even for malformed responses. For example:- Unclosed tags will be closed ("<p>Hello" will become "<p>Hello</p>")
- Implicit tags will be made explicit (e.g. a naked <td> will be wrapped in a <table><tr><td>)
- Basic structure is guaranteed (i.e. html, head, body elements)
The class is immutable and thread-safe.
- Since:
- 1.4
- See Also:
- Jsoup website
-
-
Constructor Summary
Constructors Constructor Description JsoupResponse(Response resp)
Public ctor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends Response>
Tas(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'sUTF-8
(if there is something else that can't be translated into a UTF-8 string a runtime exception will be thrown).Map<String,List<String>>
headers()
Get a collection of all headers.String
reason()
Get status line reason phrase.int
status()
Get status of the response as a positive integer number.String
toString()
-
-
-
Constructor Detail
-
JsoupResponse
public JsoupResponse(Response resp)
Public ctor.- Parameters:
resp
- Response
-
-
Method Detail
-
body
public String body()
Description copied from interface:Response
Get body as a string, assuming it'sUTF-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, useResponse.binary()
instead.
-
back
public final Request back()
Description copied from interface:Response
Get back to the request it's related to.
-
status
public final int status()
Description copied from interface:Response
Get status of the response as a positive integer number.
-
reason
public final String reason()
Description copied from interface:Response
Get status line reason phrase.
-
headers
public final Map<String,List<String>> headers()
Description copied from interface:Response
Get a collection of all headers.
-
binary
public final byte[] binary()
Description copied from interface:Response
Raw body as a an array of bytes.
-
-