Package be.wegenenverkeer.rxhttpclient
Class ServerResponse
- java.lang.Object
-
- be.wegenenverkeer.rxhttpclient.ServerResponse
-
- All Implemented Interfaces:
ServerResponseBodyPart,ServerResponseElement,ServerResponseHeaders,ServerResponseStatus
public class ServerResponse extends java.lang.Object implements ServerResponseStatus, ServerResponseHeaders, ServerResponseBodyPart
Wraps an Async Response delegate.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 Summary
Constructors Constructor Description ServerResponse(org.asynchttpclient.Response response)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 otherwisejava.util.List<io.netty.handler.codec.http.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 headersjava.util.List<java.lang.String>getHeaders(java.lang.String name)Returns the HTTP Response header values for the specified header name.java.lang.StringgetResponseBody()java.lang.StringgetResponseBody(java.nio.charset.Charset charset)java.nio.ByteBuffergetResponseBodyAsByteBuffer()byte[]getResponseBodyAsBytes()java.io.InputStreamgetResponseBodyAsStream()java.lang.StringgetResponseBodyExcerpt(int maxLength)java.lang.StringgetResponseBodyExcerpt(int maxLength, java.lang.String charset)intgetStatusCode()Returns the status code of the responsejava.util.Optional<java.lang.String>getStatusText()Returns the option status textorg.asynchttpclient.uri.UrigetUri()booleanhasResponseBody()booleanhasResponseHeaders()booleanhasResponseStatus()booleanisEmpty()booleanisLast()booleanisRedirected()<T> Tmatch(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 ServerResponsewrap(org.asynchttpclient.Response response)
-
-
-
Method Detail
-
wrap
public static ServerResponse wrap(org.asynchttpclient.Response response)
-
getStatusCode
public int getStatusCode()
Description copied from interface:ServerResponseStatusReturns the status code of the response- Specified by:
getStatusCodein interfaceServerResponseStatus- Returns:
- the status code of the response
-
getStatusText
public java.util.Optional<java.lang.String> getStatusText()
Description copied from interface:ServerResponseStatusReturns the option status text- Specified by:
getStatusTextin interfaceServerResponseStatus- Returns:
- the option status text
-
getResponseBody
public java.lang.String getResponseBody(java.nio.charset.Charset charset)
-
getResponseBody
public java.lang.String getResponseBody()
-
getResponseBodyAsBytes
public byte[] getResponseBodyAsBytes()
-
getResponseBodyAsStream
public java.io.InputStream getResponseBodyAsStream()
-
getHeaders
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaders()
Description copied from interface:ServerResponseHeadersReturns all response headers- Specified by:
getHeadersin interfaceServerResponseHeaders- Returns:
- all response headers
-
hasResponseHeaders
public boolean hasResponseHeaders()
-
hasResponseStatus
public boolean hasResponseStatus()
-
getCookies
public java.util.List<io.netty.handler.codec.http.cookie.Cookie> getCookies()
-
isRedirected
public boolean isRedirected()
-
getResponseBodyAsByteBuffer
public java.nio.ByteBuffer getResponseBodyAsByteBuffer()
-
getContentType
public java.util.Optional<java.lang.String> getContentType()
Description copied from interface:ServerResponseHeadersReturns some Content-Type if present in response header, None otherwise- Specified by:
getContentTypein interfaceServerResponseHeaders- Returns:
- some Content-Type if present in response header, None otherwise
-
getHeaders
public java.util.List<java.lang.String> getHeaders(java.lang.String name)
Description copied from interface:ServerResponseHeadersReturns the HTTP Response header values for the specified header name.- Specified by:
getHeadersin interfaceServerResponseHeaders- Parameters:
name- the header name- Returns:
- the HTTP Response header values for the specified header name.
-
hasResponseBody
public boolean hasResponseBody()
-
getUri
public org.asynchttpclient.uri.Uri getUri()
-
getResponseBodyExcerpt
public java.lang.String getResponseBodyExcerpt(int maxLength)
-
getResponseBodyExcerpt
public java.lang.String getResponseBodyExcerpt(int maxLength, java.lang.String charset)
-
getHeader
public java.util.Optional<java.lang.String> getHeader(java.lang.String name)
Description copied from interface:ServerResponseHeadersReturns some value for the specified header name, or None if not present in the response headers.- Specified by:
getHeaderin interfaceServerResponseHeaders- Parameters:
name- header name to look up.- Returns:
- some value for the specified header name, or None if not present in the response headers.
-
getBodyPartBytes
public byte[] getBodyPartBytes()
Description copied from interface:ServerResponseBodyPartReturns the bytes of the response body.- Specified by:
getBodyPartBytesin interfaceServerResponseBodyPart- Returns:
- the bytes of the response body.
-
isLast
public boolean isLast()
- Specified by:
isLastin interfaceServerResponseBodyPart
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceServerResponseBodyPart
-
match
public <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)
Description copied from interface:ServerResponseStatusApply a function on this instance, depending on its type.This uses a condensed form of the Visitor pattern.
- Specified by:
matchin interfaceServerResponseBodyPart- Specified by:
matchin interfaceServerResponseElement- Specified by:
matchin interfaceServerResponseHeaders- Specified by:
matchin interfaceServerResponseStatus- Type Parameters:
T- the return type of all matcher functions- Parameters:
matchStatus- the function to invoke when this instance is aServerResponseStatusmatchHeaders- the function to invoke when this instance is aServerResponseHeadersmatchBodyPart- the function to invoke when this instance is aServerResponseBodyPartmatchServerResponse- the function to invoke when this instance is aServerResponse- Returns:
- the result of the matcher function that matches this instance type
-
-