Package org.restheart.exchange
Class ProxyResponse<T>
java.lang.Object
org.restheart.exchange.Exchange<T>
org.restheart.exchange.Response<T>
org.restheart.exchange.ProxyResponse<T>
- Type Parameters:
T
- generic type
- All Implemented Interfaces:
AutoCloseable
,BufferedExchange<T>
- Direct Known Subclasses:
ByteArrayProxyResponse
,JsonProxyResponse
public abstract class ProxyResponse<T>
extends Response<T>
implements BufferedExchange<T>, AutoCloseable
Base class for Response implementation that can be used in proxied requests.
It stores the response content in the BUFFERED_RESPONSE_DATA_KEY attachment
of the HttpServerExchange.
- Author:
- Andrea Di Cesare <[email protected]>
-
Field Summary
Modifier and TypeFieldDescriptionstatic final io.undertow.util.AttachmentKey<io.undertow.connector.PooledByteBuffer[]>
Fields inherited from class org.restheart.exchange.Exchange
APP_FORM_URLENCODED_TYPE, APPLICATION_PDF_TYPE, HAL_JSON_MEDIA_TYPE, IN_ERROR_KEY, JSON_MEDIA_TYPE, LOGGER, MAX_BUFFERS, MAX_CONTENT_SIZE, MULTIPART_FORM_DATA_TYPE, wrapped
-
Constructor Summary
ModifierConstructorDescriptionprotected
ProxyResponse
(io.undertow.server.HttpServerExchange exchange) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this resource, relinquishing any underlying PooledByteBuffer.io.undertow.connector.PooledByteBuffer[]
protected abstract T
getErrorContent
(int code, String httpStatusText, String message, Throwable t, boolean includeStackTrace) io.undertow.util.AttachmentKey<io.undertow.connector.PooledByteBuffer[]>
boolean
abstract T
reads data from the buffer converting it to Tvoid
setBuffer
(io.undertow.connector.PooledByteBuffer[] raw) protected void
setContentLength
(int length) void
setInError
(int code, String message, Throwable t) abstract void
writeContent
(T content) writes data the buffer from TMethods inherited from class org.restheart.exchange.Response
getContentType, getContentType, getHeader, getHeader, getHeaders, getMDCContext, getStatusCode, of, setContentType, setContentTypeAsJson, setHeader, setHeader, setInError, setMDCContext, setStatusCode, type
Methods inherited from class org.restheart.exchange.Exchange
getExchange, getWrappedExchange, isAccountInRole, isAuthenticated, isAuthenticated, isContentTypeJson, isContentTypeText, isContentTypeXml, isInError, isInError, responseInterceptorsExecuted, setInError, setInError, setResponseInterceptorsExecuted, updateBufferSize
-
Field Details
-
BUFFERED_RESPONSE_DATA_KEY
public static final io.undertow.util.AttachmentKey<io.undertow.connector.PooledByteBuffer[]> BUFFERED_RESPONSE_DATA_KEY
-
-
Constructor Details
-
ProxyResponse
protected ProxyResponse(io.undertow.server.HttpServerExchange exchange)
-
-
Method Details
-
readContent
Description copied from interface:BufferedExchange
reads data from the buffer converting it to T- Specified by:
readContent
in interfaceBufferedExchange<T>
- Returns:
- Throws:
IOException
-
writeContent
Description copied from interface:BufferedExchange
writes data the buffer from T- Specified by:
writeContent
in interfaceBufferedExchange<T>
- Throws:
IOException
-
getRawContentKey
public io.undertow.util.AttachmentKey<io.undertow.connector.PooledByteBuffer[]> getRawContentKey() -
getBuffer
public io.undertow.connector.PooledByteBuffer[] getBuffer()- Specified by:
getBuffer
in interfaceBufferedExchange<T>
-
setBuffer
public void setBuffer(io.undertow.connector.PooledByteBuffer[] raw) - Specified by:
setBuffer
in interfaceBufferedExchange<T>
-
isContentAvailable
public boolean isContentAvailable()- Specified by:
isContentAvailable
in interfaceBufferedExchange<T>
-
setContentLength
protected void setContentLength(int length) -
setInError
- Specified by:
setInError
in classResponse<T>
- Parameters:
code
-message
-t
-
-
getErrorContent
protected abstract T getErrorContent(int code, String httpStatusText, String message, Throwable t, boolean includeStackTrace) throws IOException - Parameters:
code
-httpStatusText
-message
-t
-includeStackTrace
-- Returns:
- the content descibing the error
- Throws:
IOException
-
close
public void close()Closes this resource, relinquishing any underlying PooledByteBuffer.- Specified by:
close
in interfaceAutoCloseable
-