Package com.linecorp.armeria.common
Class RequestContextWrapper<T extends RequestContext>
java.lang.Object
com.linecorp.armeria.common.RequestContextWrapper<T>
- Type Parameters:
T
- the self type
- All Implemented Interfaces:
RequestContext
- Direct Known Subclasses:
ClientRequestContextWrapper
,ServiceRequestContextWrapper
public abstract class RequestContextWrapper<T extends RequestContext> extends Object implements RequestContext
Wraps an existing
RequestContext
.-
Constructor Summary
Constructors Modifier Constructor Description protected
RequestContextWrapper(T delegate)
Creates a new instance. -
Method Summary
Modifier and Type Method Description ByteBufAllocator
alloc()
Returns theByteBufAllocator
for thisRequestContext
.<V> V
attr(AttributeKey<V> key)
Returns the value mapped to the givenAttributeKey
ornull
if there's no value set byRequestContext.setAttr(AttributeKey, Object)
orRequestContext.setAttrIfAbsent(AttributeKey, Object)
.Iterator<Map.Entry<AttributeKey<?>,Object>>
attrs()
<V> V
computeAttrIfAbsent(AttributeKey<V> key, Function<? super AttributeKey<V>,? extends V> mappingFunction)
If the specifiedAttributeKey
is not already associated with a value (or is mapped tonull
), attempts to compute its value using the given mapping function and stores it into this context.String
decodedPath()
Returns the absolute path part of the currentRequest
URI, excluding the query part, decoded in UTF-8.protected T
delegate()
Returns the delegate context.EventLoop
eventLoop()
RequestId
id()
<A extends SocketAddress>
AlocalAddress()
Returns the local address of this request, ornull
if the connection is not established yet.RequestLogAccess
log()
Returns theRequestLogAccess
that provides the access to theRequestLog
, which contains the information collected while processing the currentRequest
.RequestLogBuilder
logBuilder()
Returns theRequestLogBuilder
that collects the information about the currentRequest
.MeterRegistry
meterRegistry()
Returns theMeterRegistry
that collects various stats.HttpMethod
method()
Returns the HTTP method of the currentRequest
.String
path()
String
query()
<A extends SocketAddress>
AremoteAddress()
Returns the remote address of this request, ornull
if the connection is not established yet.HttpRequest
request()
Returns theHttpRequest
associated with this context, ornull
if there's noHttpRequest
associated with this context yet.RpcRequest
rpcRequest()
Returns theRpcRequest
associated with this context, ornull
if there's noRpcRequest
associated with this context.SessionProtocol
sessionProtocol()
Returns theSessionProtocol
of the currentRequest
.<V> void
setAttr(AttributeKey<V> key, V value)
Associates the specified value with the givenAttributeKey
in this context.<V> V
setAttrIfAbsent(AttributeKey<V> key, V value)
Associates the specified value with the givenAttributeKey
in this context only if this context does not contain a mapping for theAttributeKey
.SSLSession
sslSession()
TheSSLSession
for this request if the connection is made over TLS, ornull
if the connection is not established yet or the connection is not a TLS connection.String
toString()
void
updateRequest(HttpRequest req)
Replaces theHttpRequest
associated with this context with the specified one.void
updateRpcRequest(RpcRequest rpcReq)
Replaces theRpcRequest
associated with this context with the specified one.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.linecorp.armeria.common.RequestContext
contextAwareEventLoop, contextAwareExecutor, executor, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, newDerivedContext, push, replace
-
Constructor Details
-
RequestContextWrapper
Creates a new instance.
-
-
Method Details
-
delegate
Returns the delegate context. -
request
Description copied from interface:RequestContext
Returns theHttpRequest
associated with this context, ornull
if there's noHttpRequest
associated with this context yet.- Specified by:
request
in interfaceRequestContext
-
rpcRequest
Description copied from interface:RequestContext
Returns theRpcRequest
associated with this context, ornull
if there's noRpcRequest
associated with this context.- Specified by:
rpcRequest
in interfaceRequestContext
-
updateRequest
Description copied from interface:RequestContext
Replaces theHttpRequest
associated with this context with the specified one. This method is useful to a decorator that manipulates HTTP request headers.Note that it is a bad idea to change the values of the pseudo headers (
":method"
,":path"
,":scheme"
and":authority"
) when replacing anHttpRequest
, because the properties of this context, such asRequestContext.path()
, are unaffected by such an attempt.- Specified by:
updateRequest
in interfaceRequestContext
- See Also:
HttpRequest.withHeaders(RequestHeaders)
,HttpRequest.withHeaders(RequestHeadersBuilder)
-
updateRpcRequest
Description copied from interface:RequestContext
Replaces theRpcRequest
associated with this context with the specified one. This method is useful to a decorator that manipulates an RPC call.- Specified by:
updateRpcRequest
in interfaceRequestContext
-
sessionProtocol
Description copied from interface:RequestContext
Returns theSessionProtocol
of the currentRequest
.- Specified by:
sessionProtocol
in interfaceRequestContext
-
remoteAddress
Description copied from interface:RequestContext
Returns the remote address of this request, ornull
if the connection is not established yet.- Specified by:
remoteAddress
in interfaceRequestContext
-
localAddress
Description copied from interface:RequestContext
Returns the local address of this request, ornull
if the connection is not established yet.- Specified by:
localAddress
in interfaceRequestContext
-
sslSession
Description copied from interface:RequestContext
TheSSLSession
for this request if the connection is made over TLS, ornull
if the connection is not established yet or the connection is not a TLS connection.- Specified by:
sslSession
in interfaceRequestContext
-
id
Description copied from interface:RequestContext
- Specified by:
id
in interfaceRequestContext
-
method
Description copied from interface:RequestContext
Returns the HTTP method of the currentRequest
.- Specified by:
method
in interfaceRequestContext
-
path
Description copied from interface:RequestContext
Returns the absolute path part of the currentRequest
URI, excluding the query part, as defined in RFC3986.- Specified by:
path
in interfaceRequestContext
-
decodedPath
Description copied from interface:RequestContext
Returns the absolute path part of the currentRequest
URI, excluding the query part, decoded in UTF-8.- Specified by:
decodedPath
in interfaceRequestContext
-
query
Description copied from interface:RequestContext
- Specified by:
query
in interfaceRequestContext
-
log
Description copied from interface:RequestContext
Returns theRequestLogAccess
that provides the access to theRequestLog
, which contains the information collected while processing the currentRequest
.- Specified by:
log
in interfaceRequestContext
-
logBuilder
Description copied from interface:RequestContext
Returns theRequestLogBuilder
that collects the information about the currentRequest
.- Specified by:
logBuilder
in interfaceRequestContext
-
meterRegistry
Description copied from interface:RequestContext
Returns theMeterRegistry
that collects various stats.- Specified by:
meterRegistry
in interfaceRequestContext
-
eventLoop
Description copied from interface:RequestContext
- Specified by:
eventLoop
in interfaceRequestContext
-
alloc
Description copied from interface:RequestContext
Returns theByteBufAllocator
for thisRequestContext
. Any buffers created by thisByteBufAllocator
must be reference-counted. If you don't know what this means, you should probably usebyte[]
orByteBuffer
directly instead of calling this method.- Specified by:
alloc
in interfaceRequestContext
-
attr
Description copied from interface:RequestContext
Returns the value mapped to the givenAttributeKey
ornull
if there's no value set byRequestContext.setAttr(AttributeKey, Object)
orRequestContext.setAttrIfAbsent(AttributeKey, Object)
.- Specified by:
attr
in interfaceRequestContext
-
setAttr
Description copied from interface:RequestContext
Associates the specified value with the givenAttributeKey
in this context. If this context previously contained a mapping for theAttributeKey
, the old value is replaced by the specified value. Setnull
not to iterate the mapping fromRequestContext.attrs()
.- Specified by:
setAttr
in interfaceRequestContext
-
setAttrIfAbsent
Description copied from interface:RequestContext
Associates the specified value with the givenAttributeKey
in this context only if this context does not contain a mapping for theAttributeKey
.- Specified by:
setAttrIfAbsent
in interfaceRequestContext
- Returns:
null
if there was no mapping for theAttributeKey
or the old value if there's a mapping for theAttributeKey
.
-
computeAttrIfAbsent
@Nullable public <V> V computeAttrIfAbsent(AttributeKey<V> key, Function<? super AttributeKey<V>,? extends V> mappingFunction)Description copied from interface:RequestContext
If the specifiedAttributeKey
is not already associated with a value (or is mapped tonull
), attempts to compute its value using the given mapping function and stores it into this context.If the mapping function returns
null
, no mapping is recorded.- Specified by:
computeAttrIfAbsent
in interfaceRequestContext
- Returns:
- the current (existing or computed) value associated with
the specified
AttributeKey
, ornull
if the computed value isnull
-
attrs
Description copied from interface:RequestContext
- Specified by:
attrs
in interfaceRequestContext
-
toString
-