T - the type of message that will be written by instances of
this class; see createOutputStream(long,
ContainerResponse)public abstract class AbstractContainerRequestHandlingResponseWriter<T> extends ChannelInboundHandlerAdapter implements ContainerResponseWriter
ChannelInboundHandlerAdapter that is also a
ContainerResponseWriter that processes incoming ContainerRequest events, such as those dispatched by an AbstractContainerRequestDecoder, by supplying them to the ApplicationHandler.handle(ContainerRequest) method.
Instances of this class are in charge of properly invoking
ApplicationHandler.handle(ContainerRequest), thus adapting
Jersey to Netty's constraints and vice versa.
ContainerResponseWriter.TimeoutHandlerChannelHandler.Sharable| Modifier | Constructor and Description |
|---|---|
protected |
AbstractContainerRequestHandlingResponseWriter(ApplicationHandler applicationHandler)
Creates a new
AbstractContainerRequestHandlingResponseWriter. |
protected |
AbstractContainerRequestHandlingResponseWriter(ApplicationHandler applicationHandler,
int flushThreshold,
AbstractByteBufBackedChannelOutboundInvokingOutputStream.ByteBufCreator byteBufCreator)
Creates a new
AbstractContainerRequestHandlingResponseWriter. |
protected |
AbstractContainerRequestHandlingResponseWriter(Supplier<? extends ApplicationHandler> applicationHandlerSupplier)
Creates a new
AbstractContainerRequestHandlingResponseWriter. |
protected |
AbstractContainerRequestHandlingResponseWriter(Supplier<? extends ApplicationHandler> applicationHandlerSupplier,
int flushThreshold,
AbstractByteBufBackedChannelOutboundInvokingOutputStream.ByteBufCreator byteBufCreator)
Creates a new
AbstractContainerRequestHandlingResponseWriter. |
| Modifier and Type | Method and Description |
|---|---|
void |
channelActive(ChannelHandlerContext channelHandlerContext)
Overrides
ChannelInboundHandlerAdapter.channelActive(ChannelHandlerContext)
to ensure that a channel read is performed one way or another. |
void |
channelRead(ChannelHandlerContext channelHandlerContext,
Object message)
If the supplied
message is a ContainerRequest
then this method will install
itself as that request's ContainerResponseWriter
and will invoke ApplicationHandler.handle(ContainerRequest). |
void |
channelReadComplete(ChannelHandlerContext channelHandlerContext)
Overrides the
ChannelInboundHandlerAdapter.channelReadComplete(ChannelHandlerContext)
method to call channelHandlerContext.flush() before calling the superclass
implementation. |
void |
commit()
Invoked by Jersey when a
ContainerRequest has been fully
handled
successfully. |
protected static void |
copyHeaders(Map<? extends String,? extends List<String>> headersSource,
UnaryOperator<String> keyTransformer,
BiConsumer<? super String,? super List<String>> headersTarget)
A utility function that copies entries from a source
Map
by passing each entry to the supplied BiConsumer,
transforming the keys beforehand using the supplied UnaryOperator and that is intended in this framework to be used
to copy HTTP or HTTP/2 headers to and from the proper places. |
protected abstract AbstractChannelOutboundInvokingOutputStream<? extends T> |
createOutputStream(long contentLength,
ContainerResponse containerResponse)
Creates and returns a new
AbstractChannelOutboundInvokingOutputStream, or returns null if it is determined that no AbstractChannelOutboundInvokingOutputStream is required given
the supplied contentLength parameter value. |
boolean |
enableResponseBuffering()
Returns
true when invoked to indicate that buffering of
entity content is supported and can be configured to be on or
off. |
void |
failure(Throwable failureCause)
Handles any failure case encountered by the logic encapsulated by
the
ApplicationHandler.handle(ContainerRequest) method. |
protected AbstractByteBufBackedChannelOutboundInvokingOutputStream.ByteBufCreator |
getByteBufCreator()
Returns a
AbstractByteBufBackedChannelOutboundInvokingOutputStream.ByteBufCreator that may be used to create the
AbstractChannelOutboundInvokingOutputStream
implementation that must be returned by an implementation of the
createOutputStream(long, ContainerResponse) method. |
protected ChannelHandlerContext |
getChannelHandlerContext()
|
protected int |
getFlushThreshold()
Returns the minimum number of bytes that an
AbstractChannelOutboundInvokingOutputStream returned by the
createOutputStream(long, ContainerResponse) method must
write before an automatic flush may
take place. |
void |
setSuspendTimeout(long timeout,
TimeUnit timeUnit) |
boolean |
suspend(long timeout,
TimeUnit timeUnit,
ContainerResponseWriter.TimeoutHandler timeoutHandler) |
protected abstract void |
writeFailureMessage(Throwable failureCause)
Writes an appropriate message, possibly using the
ChannelHandlerContext to do so. |
OutputStream |
writeResponseStatusAndHeaders(long contentLength,
ContainerResponse containerResponse)
Writes the status and headers portion of the response present in
the supplied
ContainerResponse by calling the writeStatusAndHeaders(long, ContainerResponse) method, and, if
the supplied contentLength is not 0L and that
method returns true indicating that output will be
forthcoming, returns the result of invoking createOutputStream(long, ContainerResponse). |
protected abstract boolean |
writeStatusAndHeaders(long contentLength,
ContainerResponse containerResponse)
Writes the status and headers portion of the response present in
the supplied
ContainerResponse and returns true
if further output is forthcoming. |
channelInactive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredensureNotSharable, handlerAdded, handlerRemoved, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waithandlerAdded, handlerRemovedprotected AbstractContainerRequestHandlingResponseWriter(ApplicationHandler applicationHandler)
AbstractContainerRequestHandlingResponseWriter.applicationHandler - an ApplicationHandler
representing a Jakarta RESTful Web Services application
whose ApplicationHandler.handle(ContainerRequest) method
will serve as the bridge between Netty and Jersey; may be null somewhat pathologically but normally is notAbstractContainerRequestHandlingResponseWriter(Supplier,
int,
AbstractByteBufBackedChannelOutboundInvokingOutputStream.ByteBufCreator),
ApplicationHandler,
ApplicationHandler.handle(ContainerRequest),
channelRead(ChannelHandlerContext, Object)protected AbstractContainerRequestHandlingResponseWriter(ApplicationHandler applicationHandler, int flushThreshold, AbstractByteBufBackedChannelOutboundInvokingOutputStream.ByteBufCreator byteBufCreator)
AbstractContainerRequestHandlingResponseWriter.applicationHandler - an ApplicationHandler
representing a Jakarta RESTful Web Services application
whose ApplicationHandler.handle(ContainerRequest) method
will serve as the bridge between Netty and Jersey; may be null somewhat pathologically but normally is notflushThreshold - the minimum number of bytes that an AbstractByteBufBackedChannelOutboundInvokingOutputStream
returned by the createOutputStream(long,
ContainerResponse) method must write before an automatic
flush may take place; if less than 0 0 will be
used instead; if Integer#MAX_VALUE then it is suggested
that no automatic flushing will occurbyteBufCreator - a AbstractByteBufBackedChannelOutboundInvokingOutputStream.ByteBufCreator that may be used
(but does not have to be used) by the implementation of the
createOutputStream(long, ContainerResponse) method; may
be nullAbstractContainerRequestHandlingResponseWriter(Supplier,
int,
AbstractByteBufBackedChannelOutboundInvokingOutputStream.ByteBufCreator),
ApplicationHandler,
ApplicationHandler.handle(ContainerRequest),
channelRead(ChannelHandlerContext, Object),
getFlushThreshold(),
getByteBufCreator(),
createOutputStream(long, ContainerResponse)protected AbstractContainerRequestHandlingResponseWriter(Supplier<? extends ApplicationHandler> applicationHandlerSupplier)
AbstractContainerRequestHandlingResponseWriter.applicationHandlerSupplier - a Supplier of an ApplicationHandler representing a Jakarta RESTful Web Services application
whose ApplicationHandler.handle(ContainerRequest) method
will serve as the bridge between Netty and Jersey; may be null somewhat pathologically but normally is notAbstractContainerRequestHandlingResponseWriter(Supplier,
int,
AbstractByteBufBackedChannelOutboundInvokingOutputStream.ByteBufCreator),
ApplicationHandler,
ApplicationHandler.handle(ContainerRequest),
channelRead(ChannelHandlerContext, Object)protected AbstractContainerRequestHandlingResponseWriter(Supplier<? extends ApplicationHandler> applicationHandlerSupplier, int flushThreshold, AbstractByteBufBackedChannelOutboundInvokingOutputStream.ByteBufCreator byteBufCreator)
AbstractContainerRequestHandlingResponseWriter.applicationHandlerSupplier - a Supplier of an ApplicationHandler representing a Jakarta RESTful Web Services application
whose ApplicationHandler.handle(ContainerRequest) method
will serve as the bridge between Netty and Jersey; may be null somewhat pathologically but normally is notflushThreshold - the minimum number of bytes that an AbstractByteBufBackedChannelOutboundInvokingOutputStream
returned by the createOutputStream(long,
ContainerResponse) method must write before an automatic
flush may take place; if less than 0 0 will be
used instead; if Integer#MAX_VALUE then it is suggested
that no automatic flushing will occurbyteBufCreator - a AbstractByteBufBackedChannelOutboundInvokingOutputStream.ByteBufCreator that may be used
(but does not have to be used) by the implementation of the
createOutputStream(long, ContainerResponse) method; may
be nullApplicationHandler,
ApplicationHandler.handle(ContainerRequest),
channelRead(ChannelHandlerContext, Object),
getFlushThreshold(),
getByteBufCreator(),
createOutputStream(long, ContainerResponse)public final void channelActive(ChannelHandlerContext channelHandlerContext) throws Exception
ChannelInboundHandlerAdapter.channelActive(ChannelHandlerContext)
to ensure that a channel read is performed one way or another.
If autoread is active,
then the superclass' version of this method is executed with no
changes. If autoread is
inactive, then a call is made to ChannelHandlerContext.read().
channelActive in interface ChannelInboundHandlerchannelActive in class ChannelInboundHandlerAdapterchannelHandlerContext - the ChannelHandlerContext in
effect; must not be nullNullPointerException - if channelHandlerContext
is nullException - if an error occursChannelConfig.isAutoRead(),
Channel.read(),
ChannelHandlerContext.read(),
channelRead(ChannelHandlerContext, Object)public final void channelRead(ChannelHandlerContext channelHandlerContext, Object message) throws Exception
message is a ContainerRequest
then this method will install
itself as that request's ContainerResponseWriter
and will invoke ApplicationHandler.handle(ContainerRequest).
In all other cases this method will simply call ChannelInboundHandlerAdapter.channelRead(ChannelHandlerContext,
Object) with the supplied message.
channelRead in interface ChannelInboundHandlerchannelRead in class ChannelInboundHandlerAdapterchannelHandlerContext - the ChannelHandlerContext in
effect; must not be nullmessage - the incoming message, or event; may be nullNullPointerException - if channelHandlerContext
is null, or if the Supplier of ApplicationHandler instances supplied at construction time
returns nullException - if message is not an instance of
ContainerRequest and ChannelInboundHandlerAdapter.channelRead(ChannelHandlerContext,
Object) throws an ExceptionApplicationHandler.handle(ContainerRequest),
ContainerResponseWriter,
ContainerRequest.setWriter(ContainerResponseWriter)public final void channelReadComplete(ChannelHandlerContext channelHandlerContext) throws Exception
ChannelInboundHandlerAdapter.channelReadComplete(ChannelHandlerContext)
method to call channelHandlerContext.flush() before calling the superclass
implementation.channelReadComplete in interface ChannelInboundHandlerchannelReadComplete in class ChannelInboundHandlerAdapterchannelHandlerContext - the ChannelHandlerContext in
effect; must not be nullNullPointerException - if channelHandlerContext is nullException - if ChannelInboundHandlerAdapter.channelReadComplete(ChannelHandlerContext)
throws an Exceptionprotected final ChannelHandlerContext getChannelHandlerContext()
ChannelHandlerContext in effect, or null if there is no such ChannelHandlerContext.
This method may return null.
ChannelHandlerContext in effect, or null if there is no such ChannelHandlerContextpublic final boolean enableResponseBuffering()
true when invoked to indicate that buffering of
entity content is supported and can be configured to be on or
off.
Note that the return value of this method is a default value
indicating that the concept of response buffering is
enabled. The actual configuration of response buffering
is a property of the application. Specifically, an application's
response buffering policy can be configured: if the application's
configuration sets the jersey.config.contentLength.buffer property to a positive int, then buffering will occur, and if the application's
configuration sets the jersey.config.contentLength.buffer property to a negative int, then buffering will not occur. If the application's
configuration does nothing in this regard, response buffering
will be enabled with a default buffer size of 8192.
(If, instead, this method had been written to return false, then no matter what configuration settings an application
might specify in the realm of response buffering settings,
response buffering of any kind would never be possible.)
enableResponseBuffering in interface ContainerResponseWritertrue when invoked; never falseContainerResponseWriter.enableResponseBuffering(),
ServerRuntime.java,
ContainerResponse.java,
OutboundMessageContext.javapublic final OutputStream writeResponseStatusAndHeaders(long contentLength, ContainerResponse containerResponse)
ContainerResponse by calling the writeStatusAndHeaders(long, ContainerResponse) method, and, if
the supplied contentLength is not 0L and that
method returns true indicating that output will be
forthcoming, returns the result of invoking createOutputStream(long, ContainerResponse).
In all other cases, this method returns null.
writeResponseStatusAndHeaders in interface ContainerResponseWritercontentLength - the content length as determined by the
logic encapsulated by the ApplicationHandler.handle(ContainerRequest) method; a value less
than zero indicates an unknown content lengthcontainerResponse - the ContainerResponse containing
status and headers information; must not be nullOutputStream returned by the createOutputStream(long, ContainerResponse) method, or nullNullPointerException - if containerResponse is
nullwriteStatusAndHeaders(long, ContainerResponse),
createOutputStream(long, ContainerResponse),
ApplicationHandler.handle(ContainerRequest)protected abstract boolean writeStatusAndHeaders(long contentLength, ContainerResponse containerResponse)
ContainerResponse and returns true
if further output is forthcoming.
Implementations of this method must not call the writeResponseStatusAndHeaders(long, ContainerResponse) method
or an infinite loop may result.
Implementations of this method must not call the createOutputStream(long, ContainerResponse) method or undefined
behavior may result.
contentLength - the content length as determined by the
logic encapsulated by the ApplicationHandler.handle(ContainerRequest) method; a value less
than zero indicates an unknown content lengthcontainerResponse - the ContainerResponse containing
status and headers information; must not be nulltrue if the createOutputStream(long,
ContainerResponse) method should be invoked, i.e. if
further output is forthcomingNullPointerException - if containerResponse is
nullApplicationHandler.handle(ContainerRequest),
createOutputStream(long, ContainerResponse)protected abstract AbstractChannelOutboundInvokingOutputStream<? extends T> createOutputStream(long contentLength, ContainerResponse containerResponse)
AbstractChannelOutboundInvokingOutputStream, or returns null if it is determined that no AbstractChannelOutboundInvokingOutputStream is required given
the supplied contentLength parameter value.
Implementations of this method may return null.
contentLength - the content length as determined by the
logic encapsulated by the ApplicationHandler.handle(ContainerRequest) method; a value less
than zero indicates an unknown content length; must not be equal
to 0LcontainerResponse - the ContainerResponse containing
status and headers information; must not be null; may be
(and often is) ignored by implementationsAbstractChannelOutboundInvokingOutputStream
implementation, or nullNullPointerException - if containerResponse is
nullIllegalArgumentException - if contentLength is
equal to 0Lprotected final int getFlushThreshold()
AbstractChannelOutboundInvokingOutputStream returned by the
createOutputStream(long, ContainerResponse) method must
write before an automatic flush may
take place.
Note: Implementations of the createOutputStream(long, ContainerResponse) method may choose
to ignore the return value of this method. It is supplied for
convenience only for use by implementors of the createOutputStream(long, ContainerResponse) method.
AbstractChannelOutboundInvokingOutputStream returned by the
createOutputStream(long, ContainerResponse) method must
write before an automatic flush may
take place; always 0L or a positive int; if
0 it is suggested that automatic flushing occur after
every write; if Integer#MAX_VALUE it is suggested that no
automatic flushing should occurcreateOutputStream(long, ContainerResponse),
AbstractContainerRequestHandlingResponseWriter(ApplicationHandler,
int,
AbstractByteBufBackedChannelOutboundInvokingOutputStream.ByteBufCreator),
AbstractByteBufBackedChannelOutboundInvokingOutputStream.AbstractByteBufBackedChannelOutboundInvokingOutputStream(ChannelOutboundInvoker,
int, boolean, ByteBufCreator)protected final AbstractByteBufBackedChannelOutboundInvokingOutputStream.ByteBufCreator getByteBufCreator()
AbstractByteBufBackedChannelOutboundInvokingOutputStream.ByteBufCreator that may be used to create the
AbstractChannelOutboundInvokingOutputStream
implementation that must be returned by an implementation of the
createOutputStream(long, ContainerResponse) method.
This method may return null.
Note: Implementations of the createOutputStream(long, ContainerResponse) method may choose
to ignore the return value of this method. It is supplied for
convenience only for use by implementors of the createOutputStream(long, ContainerResponse) method.
AbstractByteBufBackedChannelOutboundInvokingOutputStream.ByteBufCreator, or nullcreateOutputStream(long, ContainerResponse),
AbstractContainerRequestHandlingResponseWriter(ApplicationHandler,
int, AbstractByteBufBackedChannelOutboundInvokingOutputStream.ByteBufCreator),
AbstractByteBufBackedChannelOutboundInvokingOutputStream.AbstractByteBufBackedChannelOutboundInvokingOutputStream(ChannelOutboundInvoker,
int, boolean, ByteBufCreator)public void commit()
ContainerRequest has been fully
handled
successfully.
Either commit() or failure(Throwable) will
be called by Jersey as the logically final operation in the logic
encapsulated by the ApplicationHandler.handle(ContainerRequest) method, but not
both.
This implementation does nothing.
commit in interface ContainerResponseWriterContainerResponseWriter.commit(),
failure(Throwable)public final boolean suspend(long timeout, TimeUnit timeUnit, ContainerResponseWriter.TimeoutHandler timeoutHandler)
suspend in interface ContainerResponseWriterpublic final void setSuspendTimeout(long timeout, TimeUnit timeUnit)
setSuspendTimeout in interface ContainerResponseWriterpublic final void failure(Throwable failureCause)
ApplicationHandler.handle(ContainerRequest) method.
Either commit() or failure(Throwable) will
be called by Jersey as the logically final operation in the logic
encapsulated by the ApplicationHandler.handle(ContainerRequest) method, but not
both.
This method calls the writeFailureMessage(Throwable)
method and takes great care to ensure that any Throwables
encountered along the way are properly recorded and suppressed.
This implementation never returns. A ContainerException is always thrown by this method.
failure in interface ContainerResponseWriterfailureCause - the Throwable encountered by the
ApplicationHandler.handle(ContainerRequest) method; may
be nullContainerException - when this method is invoked; it
will have the supplied failureCause as its causecommit(),
ContainerResponseWriter.failure(Throwable)protected abstract void writeFailureMessage(Throwable failureCause)
ChannelHandlerContext to do so.
Implementations of this method must not call the failure(Throwable) method or an infinite loop may result.
failureCause - the Throwable responsible for this
method's invocation; may be null in pathological casesprotected static final void copyHeaders(Map<? extends String,? extends List<String>> headersSource, UnaryOperator<String> keyTransformer, BiConsumer<? super String,? super List<String>> headersTarget)
Map
by passing each entry to the supplied BiConsumer,
transforming the keys beforehand using the supplied UnaryOperator and that is intended in this framework to be used
to copy HTTP or HTTP/2 headers to and from the proper places.headersSource - the source of the headers to copy; may be
null in which case no action will be takenkeyTransformer - a UnaryOperator that transforms a
header name; if null then the return value of UnaryOperator.identity() will be used insteadheadersTarget - where the headers will be copied to; may be
null in which case no action will be takenCopyright © 2019–2020, microBean™. All rights reserved.