T
- the common supertype of messages that can be decodedH
- the type of "headers" messagesD
- the type of "data" messagespublic abstract class AbstractContainerRequestDecoder<T,H extends T,D extends T> extends MessageToMessageDecoder<T>
MessageToMessageDecoder
that decodes messages of a
specific type into ContainerRequest
s.
Instances of this class are normally followed in a ChannelPipeline
by instances of the AbstractContainerRequestHandlingResponseWriter
class.
ChannelHandler.Sharable
Modifier | Constructor and Description |
---|---|
protected |
AbstractContainerRequestDecoder(URI baseUri,
Class<H> headersClass,
Class<D> dataClass)
Deprecated.
Please use the
AbstractContainerRequestDecoder(URI, Configuration, Class,
Class) constructor instead. |
protected |
AbstractContainerRequestDecoder(URI baseUri,
Configuration configuration,
Class<H> headersClass,
Class<D> dataClass)
Creates a new
AbstractContainerRequestDecoder implementation. |
protected |
AbstractContainerRequestDecoder(URI baseUri,
Supplier<? extends Configuration> configurationSupplier,
Class<H> headersClass,
Class<D> dataClass)
Creates a new
AbstractContainerRequestDecoder implementation. |
Modifier and Type | Method and Description |
---|---|
boolean |
acceptInboundMessage(Object message)
Returns
true if the supplied message is an
instance of either the headers type
or data type supplied at construction time, and false in
all other cases. |
void |
channelReadComplete(ChannelHandlerContext channelHandlerContext)
Overrides the
ChannelInboundHandlerAdapter.channelReadComplete(ChannelHandlerContext)
method to request a
read when necessary, taking the auto-read status of the associated
Channel into account. |
protected PropertiesDelegate |
createPropertiesDelegate(H message)
Creates and returns a
PropertiesDelegate appropriate for the
supplied message, which is guaranteed to be a "headers" message. |
protected SecurityContext |
createSecurityContext(H message)
Creates and returns a
SecurityContext appropriate for the
supplied message, which is guaranteed to be a "headers" message. |
protected TerminableByteBufInputStream |
createTerminableByteBufInputStream(ByteBufAllocator byteBufAllocator)
Creates and returns a new
TerminableByteBufInputStream . |
protected void |
decode(ChannelHandlerContext channelHandlerContext,
T message,
List<Object> out)
|
protected ByteBuf |
getContent(D message)
Extracts any content from the supplied "data" message as a
ByteBuf , or returns
null if there is no such content. |
protected abstract String |
getMethod(H message)
Extracts and returns a
String representing a request
method from the supplied message, which is guaranteed to be a
"headers" message. |
protected abstract String |
getRequestUriString(H message)
Extracts and returns a
String representing a request URI
from the supplied message, which is guaranteed to be a
"headers" message. |
protected void |
installMessage(ChannelHandlerContext channelHandlerContext,
H message,
ContainerRequest containerRequest)
Installs the supplied
message into the supplied ContainerRequest in some way. |
protected boolean |
isData(T message)
Returns
true if the supplied message represents a
"data" message (as distinguished from a "headers" message). |
protected boolean |
isHeaders(T message)
Returns
true if the supplied message represents a
"headers" message (as distinguished from a "data" message). |
protected abstract boolean |
isLast(T message)
Returns
true if there will be no further message
components in an overall larger message after the supplied one. |
channelRead
channelActive, channelInactive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
handlerAdded, handlerRemoved
@Deprecated protected AbstractContainerRequestDecoder(URI baseUri, Class<H> headersClass, Class<D> dataClass)
AbstractContainerRequestDecoder(URI, Configuration, Class,
Class)
constructor instead.AbstractContainerRequestDecoder
implementation.baseUri
- the base URI
against which relative
request URIs will be resolved; may be null
in which case
the return value of URI.create("/")
will be used insteadheadersClass
- the type representing a "headers" message;
must not be null
dataClass
- the type representing a "data" message; must not
be null
NullPointerException
- if either headersClass
or
dataClass
is null
AbstractContainerRequestDecoder(URI, Configuration, Class,
Class)
protected AbstractContainerRequestDecoder(URI baseUri, Configuration configuration, Class<H> headersClass, Class<D> dataClass)
AbstractContainerRequestDecoder
implementation.baseUri
- the base URI
against which relative
request URIs will be resolved; may be null
in which case
the return value of URI.create("/")
will be used insteadconfiguration
- a Configuration
describing how the
container is configured; may be null
headersClass
- the type representing a "headers" message;
must not be null
dataClass
- the type representing a "data" message; must not
be null
NullPointerException
- if either headersClass
or
dataClass
is null
protected AbstractContainerRequestDecoder(URI baseUri, Supplier<? extends Configuration> configurationSupplier, Class<H> headersClass, Class<D> dataClass)
AbstractContainerRequestDecoder
implementation.baseUri
- the base URI
against which relative
request URIs will be resolved; may be null
in which case
the return value of URI.create("/")
will be used insteadconfigurationSupplier
- a Supplier
of Configuration
instances describing how the container is
configured; may be null
headersClass
- the type representing a "headers" message;
must not be null
dataClass
- the type representing a "data" message; must not
be null
NullPointerException
- if either headersClass
or
dataClass
is null
public void channelReadComplete(ChannelHandlerContext channelHandlerContext) throws Exception
ChannelInboundHandlerAdapter.channelReadComplete(ChannelHandlerContext)
method to request a
read when necessary, taking the auto-read status of the associated
Channel
into account.channelReadComplete
in interface ChannelInboundHandler
channelReadComplete
in class ChannelInboundHandlerAdapter
channelHandlerContext
- the ChannelHandlerContext
in
effect; must not be null
NullPointerException
- if channelHandlerContext
is null
Exception
ChannelConfig.isAutoRead()
,
ChannelInboundHandlerAdapter.channelReadComplete(ChannelHandlerContext)
public boolean acceptInboundMessage(Object message)
true
if the supplied message
is an
instance of either the headers type
or data type supplied at construction time, and false
in
all other cases.acceptInboundMessage
in class MessageToMessageDecoder<T>
message
- the message to interrogate; may be null
in
which case false
will be returnedtrue
if the supplied message
is an
instance of either the headers type
or data type supplied at construction time; false
in all
other casesAbstractContainerRequestDecoder(URI, Class, Class)
protected boolean isHeaders(T message)
true
if the supplied message represents a
"headers" message (as distinguished from a "data" message).message
- the message to interrogate; will not be null
true
if the supplied message represents a
"headers" message; false
otherwiseisData(Object)
protected abstract String getRequestUriString(H message)
String
representing a request URI
from the supplied message, which is guaranteed to be a
"headers" message.
Implementations of this method may return null
but
normally will not.
message
- the message to interrogate; will not be null
String
representing a request URI from the
supplied message, or null
protected abstract String getMethod(H message)
String
representing a request
method from the supplied message, which is guaranteed to be a
"headers" message.
Implementations of this method may return null
but
normally will not.
message
- the message to interrogate; will not be null
String
representing a request method from the
supplied message, or null
protected SecurityContext createSecurityContext(H message)
SecurityContext
appropriate for the
supplied message, which is guaranteed to be a "headers" message.
Implementations of this method must not return null
.
message
- the "headers"
message for which a new SecurityContext
is to be
returned; will not be null
null
SecurityContext
protected PropertiesDelegate createPropertiesDelegate(H message)
PropertiesDelegate
appropriate for the
supplied message, which is guaranteed to be a "headers" message.
Implementations of this method must not return null
.
message
- the "headers"
message for which a new PropertiesDelegate
is to be
returned; will not be null
null
PropertiesDelegate
protected void installMessage(ChannelHandlerContext channelHandlerContext, H message, ContainerRequest containerRequest)
message
into the supplied ContainerRequest
in some way.
This implementation calls ContainerRequest.setProperty(String, Object)
with the
fully-qualified class name of the
headers class supplied at construction time as the key, and the
supplied message
as the value.
channelHandlerContext
- the ChannelHandlerContext
in
effect; will not be null
; supplied for convenience;
overrides may (and often do) ignore this parametermessage
- the message to install; will not be null
and is guaranteed to be a "headers" messagecontainerRequest
- the just-constructed ContainerRequest
into which to install the supplied message
; will not be null
protected boolean isData(T message)
true
if the supplied message represents a
"data" message (as distinguished from a "headers" message).message
- the message to interrogate; will not be null
true
if the supplied message represents a
"data" message; false
otherwiseisHeaders(Object)
protected ByteBuf getContent(D message)
ByteBuf
, or returns
null
if there is no such content.message
- the "data" message
from which a ByteBuf
is to be extracted; will not be
null
ByteBuf
representing the message's content, or
null
protected abstract boolean isLast(T message)
true
if there will be no further message
components in an overall larger message after the supplied one.protected final void decode(ChannelHandlerContext channelHandlerContext, T message, List<Object> out)
decode
in class MessageToMessageDecoder<T>
channelHandlerContext
- the ChannelHandlerContext
in
effect; must not be null
message
- the message to decode; must not be null
and must be acceptableout
- a List
of Object
s that result from
decoding the supplied message
; must not be null
and must be mutableNullPointerException
- if channelHandlerContext
or out
is null
IllegalArgumentException
- if message
is null
or otherwise unacceptableIllegalStateException
- if there is an internal problem
with state managementprotected TerminableByteBufInputStream createTerminableByteBufInputStream(ByteBufAllocator byteBufAllocator)
TerminableByteBufInputStream
.byteBufAllocator
- a ByteBufAllocator
that may be
used or ignored; will not be null
null
TerminableByteBufInputStream
Copyright © 2019–2020, microBean™. All rights reserved.