public class ServerResponse extends java.lang.Object implements ServerResponseStatus, ServerResponseHeaders, ServerResponseBodyPart
This wrapper makes it easier to work with lambda expressions because the checked IOExceptions are wrapped in RuntimeExceptions.
Created by Karel Maesen, Geovise BVBA on 06/12/14.| Constructor and Description |
|---|
ServerResponse(com.ning.http.client.Response response) |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
getBodyPartBytes()
Returns the bytes of the response body.
|
java.util.Optional<java.lang.String> |
getContentType()
Returns some Content-Type if present in response header, None otherwise
|
java.util.List<com.ning.http.client.cookie.Cookie> |
getCookies() |
java.util.Optional<java.lang.String> |
getHeader(java.lang.String name)
Returns some value for the specified header name, or None if not present in the response headers.
|
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getHeaders()
Returns all response headers
|
java.util.List<java.lang.String> |
getHeaders(java.lang.String name)
Returns the HTTP Response header values for the specified header name.
|
java.lang.String |
getResponseBody() |
java.lang.String |
getResponseBody(java.lang.String charset) |
java.nio.ByteBuffer |
getResponseBodyAsByteBuffer() |
byte[] |
getResponseBodyAsBytes() |
java.io.InputStream |
getResponseBodyAsStream() |
java.lang.String |
getResponseBodyExcerpt(int maxLength) |
java.lang.String |
getResponseBodyExcerpt(int maxLength,
java.lang.String charset) |
int |
getStatusCode()
Returns the status code of the response
|
java.util.Optional<java.lang.String> |
getStatusText()
Returns the option status text
|
com.ning.http.client.uri.Uri |
getUri() |
boolean |
hasResponseBody() |
boolean |
hasResponseHeaders() |
boolean |
hasResponseStatus() |
boolean |
isRedirected() |
<T> T |
match(java.util.function.Function<ServerResponseStatus,T> matchStatus,
java.util.function.Function<ServerResponseHeaders,T> matchHeaders,
java.util.function.Function<ServerResponseBodyPart,T> matchBodyPart,
java.util.function.Function<ServerResponse,T> matchServerResponse)
Apply a function on this instance, depending on its type.
|
static ServerResponse |
wrap(com.ning.http.client.Response response) |
public static ServerResponse wrap(com.ning.http.client.Response response)
public int getStatusCode()
ServerResponseStatusgetStatusCode in interface ServerResponseStatuspublic java.util.Optional<java.lang.String> getStatusText()
ServerResponseStatusgetStatusText in interface ServerResponseStatuspublic java.lang.String getResponseBody(java.lang.String charset)
public java.lang.String getResponseBody()
public byte[] getResponseBodyAsBytes()
public java.io.InputStream getResponseBodyAsStream()
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaders()
ServerResponseHeadersgetHeaders in interface ServerResponseHeaderspublic boolean hasResponseHeaders()
public boolean hasResponseStatus()
public java.util.List<com.ning.http.client.cookie.Cookie> getCookies()
public boolean isRedirected()
public java.nio.ByteBuffer getResponseBodyAsByteBuffer()
public java.util.Optional<java.lang.String> getContentType()
ServerResponseHeadersgetContentType in interface ServerResponseHeaderspublic java.util.List<java.lang.String> getHeaders(java.lang.String name)
ServerResponseHeadersgetHeaders in interface ServerResponseHeadersname - the header namepublic boolean hasResponseBody()
public com.ning.http.client.uri.Uri getUri()
public java.lang.String getResponseBodyExcerpt(int maxLength)
public java.lang.String getResponseBodyExcerpt(int maxLength,
java.lang.String charset)
public java.util.Optional<java.lang.String> getHeader(java.lang.String name)
ServerResponseHeadersgetHeader in interface ServerResponseHeadersname - header name to look up.public byte[] getBodyPartBytes()
ServerResponseBodyPartgetBodyPartBytes in interface ServerResponseBodyPartpublic <T> T match(java.util.function.Function<ServerResponseStatus,T> matchStatus, java.util.function.Function<ServerResponseHeaders,T> matchHeaders, java.util.function.Function<ServerResponseBodyPart,T> matchBodyPart, java.util.function.Function<ServerResponse,T> matchServerResponse)
ServerResponseStatusThis uses a condensed form of the Visitor pattern.
match in interface ServerResponseBodyPartmatch in interface ServerResponseElementmatch in interface ServerResponseHeadersmatch in interface ServerResponseStatusT - the return type of all matcher functionsmatchStatus - the function to invoke when this instance is a ServerResponseStatusmatchHeaders - the function to invoke when this instance is a ServerResponseHeadersmatchBodyPart - the function to invoke when this instance is a ServerResponseBodyPartmatchServerResponse - the function to invoke when this instance is a ServerResponse