Package com.linecorp.armeria.server
Class ServiceRequestContextWrapper
java.lang.Object
com.linecorp.armeria.common.RequestContextWrapper<ServiceRequestContext>
com.linecorp.armeria.server.ServiceRequestContextWrapper
- All Implemented Interfaces:
RequestContext
,ServiceRequestContext
public class ServiceRequestContextWrapper extends RequestContextWrapper<ServiceRequestContext> implements ServiceRequestContext
Wraps an existing
ServiceRequestContext
.-
Constructor Summary
Constructors Modifier Constructor Description protected
ServiceRequestContextWrapper(ServiceRequestContext delegate)
Creates a new instance. -
Method Summary
Modifier and Type Method Description void
addAdditionalResponseHeader(CharSequence name, Object value)
Adds a header with the specifiedname
andvalue
.void
addAdditionalResponseTrailer(CharSequence name, Object value)
Adds a trailer with the specifiedname
andvalue
.HttpHeaders
additionalResponseHeaders()
HttpHeaders
additionalResponseTrailers()
Returns theHttpHeaders
which is included along with any other trailers when aService
completes anHttpResponse
.ContextAwareScheduledExecutorService
blockingTaskExecutor()
Returns theContextAwareScheduledExecutorService
that could be used for executing a potentially long-running task.void
clearRequestTimeout()
Clears the previously scheduled request timeout, if any.InetAddress
clientAddress()
Returns the address of the client who initiated this request.ServiceConfig
config()
String
decodedMappedPath()
Returns theRequestContext.decodedPath()
with its context path removed.boolean
isTimedOut()
Returns whether thisRequestContext
has been timed-out (e.g., when the corresponding request passes a deadline).<A extends SocketAddress>
AlocalAddress()
Returns the local address of this request, ornull
if the connection is not established yet.String
mappedPath()
Returns theRequestContext.path()
with its context path removed.long
maxRequestLength()
Returns the maximum length of the currentRequest
.void
mutateAdditionalResponseHeaders(Consumer<HttpHeadersBuilder> mutator)
void
mutateAdditionalResponseTrailers(Consumer<HttpHeadersBuilder> mutator)
Mutates theHttpHeaders
which is included along with any other trailers when aService
completes anHttpResponse
.MediaType
negotiatedResponseMediaType()
Returns the negotiated producible media type.Map<String,String>
pathParams()
ProxiedAddresses
proxiedAddresses()
Returns the proxied addresses of the currentRequest
.<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.long
requestTimeoutMillis()
RoutingContext
routingContext()
Returns theRoutingContext
used to find theService
.void
setAdditionalResponseHeader(CharSequence name, Object value)
Sets a header with the specifiedname
andvalue
.void
setAdditionalResponseTrailer(CharSequence name, Object value)
Sets a trailer with the specifiedname
andvalue
.void
setMaxRequestLength(long maxRequestLength)
Sets the maximum length of the currentRequest
.void
setRequestTimeout(TimeoutMode mode, Duration requestTimeout)
Schedules the request timeout that is triggered when theRequest
is not fully received or the correspondingResponse
is not sent completely within the specifiedTimeoutMode
and the specifiedrequestTimeout
.void
setRequestTimeoutMillis(TimeoutMode mode, long requestTimeoutMillis)
Schedules the request timeout that is triggered when theRequest
is not fully received or the correspondingResponse
is not sent completely within the specifiedTimeoutMode
and the specifiedrequestTimeoutMillis
.void
timeoutNow()
Triggers the current timeout immediately if a timeout was scheduled before.CompletableFuture<Void>
whenRequestTimedOut()
Returns aCompletableFuture
which is completed afterServiceRequestContext
has been timed out (e.g., when the corresponding request passes a deadline).CompletableFuture<Void>
whenRequestTimingOut()
Returns aCompletableFuture
which is completed whenServiceRequestContext
is about to get timed out.Methods inherited from class com.linecorp.armeria.common.RequestContextWrapper
alloc, attr, attrs, computeAttrIfAbsent, decodedPath, delegate, eventLoop, id, log, logBuilder, meterRegistry, method, ownAttr, ownAttrs, path, query, root, rpcRequest, sessionProtocol, setAttr, setAttrIfAbsent, sslSession, toString, updateRequest, updateRpcRequest
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
alloc, attr, attrs, computeAttrIfAbsent, contextAwareEventLoop, contextAwareExecutor, decodedPath, eventLoop, executor, id, log, logBuilder, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, meterRegistry, method, ownAttr, ownAttrs, path, query, replace, sessionProtocol, setAttr, setAttrIfAbsent, sslSession, updateRequest, updateRpcRequest
Methods inherited from interface com.linecorp.armeria.server.ServiceRequestContext
pathParam, push, requestTimeoutHandler, root, rpcRequest, setRequestTimeout, setRequestTimeoutHandler, setRequestTimeoutMillis
-
Constructor Details
-
ServiceRequestContextWrapper
Creates a new instance.
-
-
Method Details
-
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
- Specified by:
request
in interfaceServiceRequestContext
- Overrides:
request
in classRequestContextWrapper<ServiceRequestContext>
-
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
- Specified by:
remoteAddress
in interfaceServiceRequestContext
- Overrides:
remoteAddress
in classRequestContextWrapper<ServiceRequestContext>
-
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
- Specified by:
localAddress
in interfaceServiceRequestContext
- Overrides:
localAddress
in classRequestContextWrapper<ServiceRequestContext>
-
clientAddress
Description copied from interface:ServiceRequestContext
Returns the address of the client who initiated this request.- Specified by:
clientAddress
in interfaceServiceRequestContext
-
config
Description copied from interface:ServiceRequestContext
- Specified by:
config
in interfaceServiceRequestContext
-
routingContext
Description copied from interface:ServiceRequestContext
Returns theRoutingContext
used to find theService
.- Specified by:
routingContext
in interfaceServiceRequestContext
-
pathParams
Description copied from interface:ServiceRequestContext
Returns the path parameters mapped by theRoute
associated with theService
that is handling the currentRequest
.- Specified by:
pathParams
in interfaceServiceRequestContext
-
blockingTaskExecutor
Description copied from interface:ServiceRequestContext
Returns theContextAwareScheduledExecutorService
that could be used for executing a potentially long-running task. TheContextAwareScheduledExecutorService
sets thisServiceRequestContext
as the current context before executing any submitted tasks. If you want to useScheduledExecutorService
without setting this context, callContextAwareScheduledExecutorService.withoutContext()
and use the returnedScheduledExecutorService
.- Specified by:
blockingTaskExecutor
in interfaceServiceRequestContext
-
mappedPath
Description copied from interface:ServiceRequestContext
Returns theRequestContext.path()
with its context path removed. This method can be useful for a reusable service bound at various path prefixes.- Specified by:
mappedPath
in interfaceServiceRequestContext
-
decodedMappedPath
Description copied from interface:ServiceRequestContext
Returns theRequestContext.decodedPath()
with its context path removed. This method can be useful for a reusable service bound at various path prefixes.- Specified by:
decodedMappedPath
in interfaceServiceRequestContext
-
negotiatedResponseMediaType
Description copied from interface:ServiceRequestContext
Returns the negotiated producible media type. If the media type negotiation is not used for theService
,null
would be returned.- Specified by:
negotiatedResponseMediaType
in interfaceServiceRequestContext
-
requestTimeoutMillis
public long requestTimeoutMillis()Description copied from interface:ServiceRequestContext
Returns the amount of time allowed from the start time of theRequest
until receiving the currentRequest
and sending the correspondingResponse
completely. This value is initially set fromServiceConfig.requestTimeoutMillis()
.- Specified by:
requestTimeoutMillis
in interfaceServiceRequestContext
-
clearRequestTimeout
public void clearRequestTimeout()Description copied from interface:ServiceRequestContext
Clears the previously scheduled request timeout, if any. Note that calling this will prevent the request from ever being timed out.- Specified by:
clearRequestTimeout
in interfaceServiceRequestContext
-
setRequestTimeoutMillis
Description copied from interface:ServiceRequestContext
Schedules the request timeout that is triggered when theRequest
is not fully received or the correspondingResponse
is not sent completely within the specifiedTimeoutMode
and the specifiedrequestTimeoutMillis
.Timeout mode description TimeoutMode.SET_FROM_NOW
Sets a given amount of timeout from the current time. TimeoutMode.SET_FROM_START
Sets a given amount of timeout since the current Request
began processing.TimeoutMode.EXTEND
Extends the previously scheduled timeout by the given amount of timeout. For example:
ServiceRequestContext ctx = ...; // Schedules a timeout from the start time of the request ctx.setRequestTimeoutMillis(TimeoutMode.SET_FROM_START, 2000); assert ctx.requestTimeoutMillis() == 2000; ctx.setRequestTimeoutMillis(TimeoutMode.SET_FROM_START, 1000); assert ctx.requestTimeoutMillis() == 1000; // Schedules timeout after 3 seconds from now. ctx.setRequestTimeoutMillis(TimeoutMode.SET_FROM_NOW, 3000); // Extends the previously scheduled timeout. long oldRequestTimeoutMillis = ctx.requestTimeoutMillis(); ctx.setRequestTimeoutMillis(TimeoutMode.EXTEND, 1000); assert ctx.requestTimeoutMillis() == oldRequestTimeoutMillis + 1000; ctx.extendRequestTimeoutMillis(TimeoutMode.EXTEND, -500); assert ctx.requestTimeoutMillis() == oldRequestTimeoutMillis + 500;
- Specified by:
setRequestTimeoutMillis
in interfaceServiceRequestContext
-
setRequestTimeout
Description copied from interface:ServiceRequestContext
Schedules the request timeout that is triggered when theRequest
is not fully received or the correspondingResponse
is not sent completely within the specifiedTimeoutMode
and the specifiedrequestTimeout
.Timeout mode description TimeoutMode.SET_FROM_NOW
Sets a given amount of timeout from the current time. TimeoutMode.SET_FROM_START
Sets a given amount of timeout since the current Request
began processing.TimeoutMode.EXTEND
Extends the previously scheduled timeout by the given amount of timeout. For example:
ServiceRequestContext ctx = ...; // Schedules a timeout from the start time of the request ctx.setRequestTimeout(TimeoutMode.SET_FROM_START, Duration.ofSeconds(2)); assert ctx.requestTimeoutMillis() == 2000; ctx.setRequestTimeout(TimeoutMode.SET_FROM_START, Duration.ofSeconds(1)); assert ctx.requestTimeoutMillis() == 1000; // Schedules timeout after 3 seconds from now. ctx.setRequestTimeout(TimeoutMode.SET_FROM_NOW, Duration.ofSeconds(3)); // Extends the previously scheduled timeout. long oldRequestTimeoutMillis = ctx.requestTimeoutMillis(); ctx.setRequestTimeout(TimeoutMode.EXTEND, Duration.ofSeconds(1)); assert ctx.requestTimeoutMillis() == oldRequestTimeoutMillis + 1000; ctx.setRequestTimeout(TimeoutMode.EXTEND, Duration.ofMillis(-500)); assert ctx.requestTimeoutMillis() == oldRequestTimeoutMillis + 500;
- Specified by:
setRequestTimeout
in interfaceServiceRequestContext
-
whenRequestTimingOut
Description copied from interface:ServiceRequestContext
Returns aCompletableFuture
which is completed whenServiceRequestContext
is about to get timed out.- Specified by:
whenRequestTimingOut
in interfaceServiceRequestContext
-
whenRequestTimedOut
Description copied from interface:ServiceRequestContext
Returns aCompletableFuture
which is completed afterServiceRequestContext
has been timed out (e.g., when the corresponding request passes a deadline).RequestContext.isTimedOut()
will always returntrue
when the returnedCompletableFuture
is completed.- Specified by:
whenRequestTimedOut
in interfaceServiceRequestContext
-
timeoutNow
public void timeoutNow()Description copied from interface:RequestContext
Triggers the current timeout immediately if a timeout was scheduled before. Otherwise, the currentRequest
will be timed-out immediately after a timeout scheduler is initialized.- Specified by:
timeoutNow
in interfaceRequestContext
-
isTimedOut
public boolean isTimedOut()Description copied from interface:RequestContext
Returns whether thisRequestContext
has been timed-out (e.g., when the corresponding request passes a deadline).- Specified by:
isTimedOut
in interfaceRequestContext
-
maxRequestLength
public long maxRequestLength()Description copied from interface:ServiceRequestContext
Returns the maximum length of the currentRequest
. This value is initially set fromServiceConfig.maxRequestLength()
. If 0, there is no limit on the request size.- Specified by:
maxRequestLength
in interfaceServiceRequestContext
- See Also:
ContentTooLargeException
-
setMaxRequestLength
public void setMaxRequestLength(long maxRequestLength)Description copied from interface:ServiceRequestContext
Sets the maximum length of the currentRequest
. This value is initially set fromServiceConfig.maxRequestLength()
. If 0, there is no limit on the request size.- Specified by:
setMaxRequestLength
in interfaceServiceRequestContext
- See Also:
ContentTooLargeException
-
additionalResponseHeaders
Description copied from interface:ServiceRequestContext
- Specified by:
additionalResponseHeaders
in interfaceServiceRequestContext
-
setAdditionalResponseHeader
Description copied from interface:ServiceRequestContext
Sets a header with the specifiedname
andvalue
. This will remove all previous values associated with the specifiedname
. The header will be included when aService
sends anHttpResponse
.- Specified by:
setAdditionalResponseHeader
in interfaceServiceRequestContext
-
addAdditionalResponseHeader
Description copied from interface:ServiceRequestContext
Adds a header with the specifiedname
andvalue
. The header will be included when aService
sends anHttpResponse
.- Specified by:
addAdditionalResponseHeader
in interfaceServiceRequestContext
-
mutateAdditionalResponseHeaders
Description copied from interface:ServiceRequestContext
- Specified by:
mutateAdditionalResponseHeaders
in interfaceServiceRequestContext
- Parameters:
mutator
- theConsumer
that mutates the additional response headers
-
additionalResponseTrailers
Description copied from interface:ServiceRequestContext
Returns theHttpHeaders
which is included along with any other trailers when aService
completes anHttpResponse
.- Specified by:
additionalResponseTrailers
in interfaceServiceRequestContext
-
setAdditionalResponseTrailer
Description copied from interface:ServiceRequestContext
Sets a trailer with the specifiedname
andvalue
. This will remove all previous values associated with the specifiedname
. The trailer will be included when aService
completes anHttpResponse
.- Specified by:
setAdditionalResponseTrailer
in interfaceServiceRequestContext
-
addAdditionalResponseTrailer
Description copied from interface:ServiceRequestContext
Adds a trailer with the specifiedname
andvalue
. The trailer will be included when aService
completes anHttpResponse
.- Specified by:
addAdditionalResponseTrailer
in interfaceServiceRequestContext
-
mutateAdditionalResponseTrailers
Description copied from interface:ServiceRequestContext
Mutates theHttpHeaders
which is included along with any other trailers when aService
completes anHttpResponse
.- Specified by:
mutateAdditionalResponseTrailers
in interfaceServiceRequestContext
- Parameters:
mutator
- theConsumer
that mutates the additional trailers
-
proxiedAddresses
Description copied from interface:ServiceRequestContext
Returns the proxied addresses of the currentRequest
.- Specified by:
proxiedAddresses
in interfaceServiceRequestContext
-