I - The type of objects received as content from a request to this server.O - The type of objects written as content from a response from this server.II - The type of objects received as content from a request to this server after applying these interceptors.OO - The type of objects written as content from a response from this server after applying these
interceptors.@Beta
public final class HttpServerInterceptorChain<I,O,II,OO>
extends java.lang.Object
HttpServer to modify behavior of requests
processed by that server.
RequestHandler
and returns another RequestHandler instance. With this low level abstraction, any use-case pertaining to
connection instrumentation can be achieved.
------- ------- ------- ------- -------
| | | | | | | | | |
| | ---> | | ---> | | ---> | | ---> | |
| | | | | | | | | |
------- ------- ------- ------- -------
Interceptor Interceptor Interceptor Interceptor Request
1 2 3 4 Handler
An interceptor chain always starts with an interceptor and ends with a RequestHandler and any number of
other interceptors can exist between the start and end.
A chain can be created by using the various start*() methods available in this class, eg:
start(), startRaw().
After starting a chain, any number of other interceptors can be added by using the various next*() methods
available in this class, eg: next(Interceptor), nextWithTransform(TransformingInterceptor),
nextWithRequestTransform(TransformingInterceptor) and
nextWithResponseTransform(TransformingInterceptor)
After adding the required interceptors, by providing a RequestHandler via the
end(RequestHandler) method, the chain can be ended and the returned RequestHandler can be used
with any HttpServer
So, a typical interaction with this class would look like:
HttpServer.newServer().start(HttpServerInterceptorChain.start(first).next(second).next(third).end(handler))
HttpServerInterceptorChain.Interceptor defines the interceptor contract.
HttpServer. For such cases, the interface HttpServerInterceptorChain.TransformingInterceptor
defines the interceptor contract. Since, this included 4 generic arguments to the interceptor, this is not the base
type for all interceptors and should be used only when the types of the request/response are actually to be
changed.
------- ------- ------- ------- ------- ------- -------
| | | | | | | | | | | | | |
| | ---> | | ---> | | ---> | | ---> | | ---> | | ---> | |
| | | | | | | | | | | | | |
------- ------- ------- ------- ------- ------- -------
Http Request Interceptor Interceptor Interceptor Interceptor Request
Server Handler 1 2 3 4 Handler
(Internal) (User)
The above diagram depicts the execution order of interceptors. The first request handler (internal) is created by
this class and as is returned by end(RequestHandler) method by providing a RequestHandler that
does the actual processing of the connection. HttpServer with which this interceptor chain is used, will
invoke the internal request handler provided by this class. The interceptors are invoked in the order that they are added to this chain.
| Modifier and Type | Class and Description |
|---|---|
static interface |
HttpServerInterceptorChain.Interceptor<I,O>
An interceptor that preserves the type of content of request and response.
|
static interface |
HttpServerInterceptorChain.TransformingInterceptor<I,O,II,OO>
An interceptor that changes the type of content of request and response.
|
| Modifier and Type | Method and Description |
|---|---|
RequestHandler<I,O> |
end(RequestHandler<II,OO> handler)
Terminates this chain with the passed
RequestHandler and returns a RequestHandler to be
used by a HttpServer |
HttpServerInterceptorChain<I,O,II,OO> |
next(HttpServerInterceptorChain.Interceptor<II,OO> next)
Add the next interceptor to this chain.
|
<III> HttpServerInterceptorChain<I,O,III,OO> |
nextWithRequestTransform(HttpServerInterceptorChain.TransformingInterceptor<II,OO,III,OO> next)
Add the next interceptor to this chain, which changes the type of objects read from the request accepted by
the associated
HttpServer. |
<OOO> HttpServerInterceptorChain<I,O,II,OOO> |
nextWithResponseTransform(HttpServerInterceptorChain.TransformingInterceptor<II,OO,II,OOO> next)
Add the next interceptor to this chain, which changes the type of objects written to the response sent by
the associated
HttpServer. |
<RRR,WWW> HttpServerInterceptorChain<I,O,RRR,WWW> |
nextWithTransform(HttpServerInterceptorChain.TransformingInterceptor<II,OO,RRR,WWW> next)
Add the next interceptor to this chain, which changes the type of objects read read from the request and written
to the response sent by the associated
HttpServer. |
static <R,W> HttpServerInterceptorChain<R,W,R,W> |
start()
Starts a new interceptor chain.
|
static HttpServerInterceptorChain<io.netty.buffer.ByteBuf,io.netty.buffer.ByteBuf,io.netty.buffer.ByteBuf,io.netty.buffer.ByteBuf> |
startRaw()
Starts a new interceptor chain with
ByteBuf read and written from request and to responses. |
public HttpServerInterceptorChain<I,O,II,OO> next(HttpServerInterceptorChain.Interceptor<II,OO> next)
next - Next interceptor to add.public <III> HttpServerInterceptorChain<I,O,III,OO> nextWithRequestTransform(HttpServerInterceptorChain.TransformingInterceptor<II,OO,III,OO> next)
HttpServer.next - Next interceptor to add.public <OOO> HttpServerInterceptorChain<I,O,II,OOO> nextWithResponseTransform(HttpServerInterceptorChain.TransformingInterceptor<II,OO,II,OOO> next)
HttpServer.next - Next interceptor to add.public <RRR,WWW> HttpServerInterceptorChain<I,O,RRR,WWW> nextWithTransform(HttpServerInterceptorChain.TransformingInterceptor<II,OO,RRR,WWW> next)
HttpServer.next - Next interceptor to add.public RequestHandler<I,O> end(RequestHandler<II,OO> handler)
RequestHandler and returns a RequestHandler to be
used by a HttpServerhandler - Request handler to use.HttpServer instead of
directly using the passed handlerpublic static <R,W> HttpServerInterceptorChain<R,W,R,W> start()
public static HttpServerInterceptorChain<io.netty.buffer.ByteBuf,io.netty.buffer.ByteBuf,io.netty.buffer.ByteBuf,io.netty.buffer.ByteBuf> startRaw()
ByteBuf read and written from request and to responses.