public interface ServiceRequestContext extends RequestContext
ServiceRequestContext instance.| Modifier and Type | Method and Description |
|---|---|
AccessLogWriter |
accessLogWriter() |
void |
addAdditionalResponseHeader(CharSequence name,
Object value)
Adds a header with the specified
name and value. |
void |
addAdditionalResponseHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
|
void |
addAdditionalResponseTrailer(CharSequence name,
Object value)
Adds a trailer with the specified
name and value. |
void |
addAdditionalResponseTrailers(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
|
HttpHeaders |
additionalResponseHeaders()
|
HttpHeaders |
additionalResponseTrailers()
Returns the
HttpHeaders which is returned along with any other trailers when a
Service completes an HttpResponse. |
ScheduledExecutorService |
blockingTaskExecutor()
Returns the
ScheduledExecutorService that could be used for executing a potentially
long-running task. |
static ServiceRequestContextBuilder |
builder(HttpRequest request)
Returns a new
ServiceRequestContextBuilder created from the specified HttpRequest. |
default InetAddress |
clientAddress()
Returns the address of the client who initiated this request.
|
static ServiceRequestContext |
current()
Returns the server-side context of the
Request that is being handled in the current thread. |
static ServiceRequestContext |
currentOrNull()
Returns the server-side context of the
Request that is being handled in the current thread. |
String |
decodedMappedPath()
Returns the
RequestContext.decodedPath() with its context path removed. |
boolean |
isTimedOut()
Returns whether this
ServiceRequestContext has been timed-out (e.g., when the
corresponding request passes a deadline). |
<A extends SocketAddress> |
localAddress()
Returns the local address of this request.
|
org.slf4j.Logger |
logger()
Deprecated.
Use a logging framework integration such as
RequestContextExportingAppender in
armeria-logback. |
static <T> T |
mapCurrent(Function<? super ServiceRequestContext,T> mapper,
Supplier<T> defaultValueSupplier)
Maps the server-side context of the
Request that is being handled in the current thread. |
String |
mappedPath()
Returns the
RequestContext.path() with its context path removed. |
long |
maxRequestLength()
Returns the maximum length of the current
Request. |
default MediaType |
negotiatedProduceType()
Deprecated.
|
MediaType |
negotiatedResponseMediaType()
Returns the negotiated producible media type.
|
ServiceRequestContext |
newDerivedContext(RequestId id,
HttpRequest req,
RpcRequest rpcReq)
Creates a new
RequestContext whose properties and Attributes are copied from this
RequestContext, except having a different pair of HttpRequest and RpcRequest
and its own RequestLog. |
static ServiceRequestContext |
of(HttpRequest request)
Returns a new
ServiceRequestContext created from the specified HttpRequest. |
default String |
pathParam(String name)
Returns the value of the specified path parameter.
|
Map<String,String> |
pathParams()
|
ProxiedAddresses |
proxiedAddresses()
Returns the proxied addresses of the current
Request. |
<A extends SocketAddress> |
remoteAddress()
Returns the remote address of this request.
|
boolean |
removeAdditionalResponseHeader(CharSequence name)
Removes all headers with the specified
name. |
boolean |
removeAdditionalResponseTrailer(CharSequence name)
Removes all trailers with the specified
name. |
HttpRequest |
request()
Returns the
HttpRequest associated with this context. |
Runnable |
requestTimeoutHandler()
Returns
Request timeout handler which is executed when
receiving the current Request and sending the corresponding Response
is not completely received within the allowed requestTimeoutMillis(). |
long |
requestTimeoutMillis()
|
Route |
route()
|
RoutingContext |
routingContext()
Returns the
RoutingContext used to find the Service. |
RpcRequest |
rpcRequest()
Returns the
RpcRequest associated with this context, or null if there's no
RpcRequest associated with this context. |
Server |
server()
|
HttpService |
service()
Returns the
HttpService that is handling the current Request. |
void |
setAdditionalResponseHeader(CharSequence name,
Object value)
Sets a header with the specified
name and value. |
void |
setAdditionalResponseHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
Clears the current header and sets the specified
HttpHeaders which is included when a
Service sends an HttpResponse. |
void |
setAdditionalResponseTrailer(CharSequence name,
Object value)
Sets a trailer with the specified
name and value. |
void |
setAdditionalResponseTrailers(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
Clears the current trailer and sets the specified
HttpHeaders which is included when a
Service completes an HttpResponse. |
void |
setMaxRequestLength(long maxRequestLength)
Sets the maximum length of the current
Request. |
void |
setRequestTimeout(Duration requestTimeout)
|
void |
setRequestTimeoutHandler(Runnable requestTimeoutHandler)
Sets a handler to run when the request times out.
|
void |
setRequestTimeoutMillis(long requestTimeoutMillis)
|
boolean |
verboseResponses()
Returns whether the verbose response mode is enabled.
|
VirtualHost |
virtualHost()
Returns the
VirtualHost that is handling the current Request. |
alloc, attrs, contextAwareEventLoop, contextAwareExecutor, decodedPath, eventLoop, executor, id, invokeOnChildCallbacks, invokeOnEnterCallbacks, invokeOnExitCallbacks, log, logBuilder, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, mapCurrent, meterRegistry, method, onChild, onEnter, onEnter, onExit, onExit, path, push, push, push, push, pushIfAbsent, query, rejectPromise, resolvePromise, sessionProtocol, sslSession, updateRequest, updateRpcRequeststatic ServiceRequestContext current()
Request that is being handled in the current thread.current in interface RequestContextIllegalStateException - if the context is unavailable in the current thread or
the current context is not a ServiceRequestContext.@Nullable static ServiceRequestContext currentOrNull()
Request that is being handled in the current thread.currentOrNull in interface RequestContextServiceRequestContext available in the current thread,
or null if unavailable.IllegalStateException - if the current context is not a ServiceRequestContext.@Nullable static <T> T mapCurrent(Function<? super ServiceRequestContext,T> mapper, @Nullable Supplier<T> defaultValueSupplier)
Request that is being handled in the current thread.mapper - the Function that maps the ServiceRequestContextdefaultValueSupplier - the Supplier that provides the value when the context is unavailable
in the current thread. If null, the null will be returned
when the context is unavailable in the current thread.IllegalStateException - if the current context is not a ServiceRequestContext.static ServiceRequestContext of(HttpRequest request)
ServiceRequestContext created from the specified HttpRequest.
Note that it is not usually required to create a new context by yourself, because Armeria
will always provide a context object for you. However, it may be useful in some cases such as
unit testing.ServiceRequestContextBuilderstatic ServiceRequestContextBuilder builder(HttpRequest request)
ServiceRequestContextBuilder created from the specified HttpRequest.@Nonnull HttpRequest request()
HttpRequest associated with this context.request in interface RequestContext@Nullable RpcRequest rpcRequest()
RpcRequest associated with this context, or null if there's no
RpcRequest associated with this context. For example, this method will return null when the request being handled is
1) not an RPC request or 2) not decoded into an RPC request yet.rpcRequest in interface RequestContext@Nonnull <A extends SocketAddress> A remoteAddress()
remoteAddress in interface RequestContext@Nonnull <A extends SocketAddress> A localAddress()
localAddress in interface RequestContextdefault InetAddress clientAddress()
ServiceRequestContext newDerivedContext(RequestId id, @Nullable HttpRequest req, @Nullable RpcRequest rpcReq)
RequestContextRequestContext whose properties and Attributes are copied from this
RequestContext, except having a different pair of HttpRequest and RpcRequest
and its own RequestLog.newDerivedContext in interface RequestContextServer server()
VirtualHost virtualHost()
VirtualHost that is handling the current Request.Route route()
RoutingContext routingContext()
RoutingContext used to find the Service.@Nullable default String pathParam(String name)
HttpService service()
HttpService that is handling the current Request.ScheduledExecutorService blockingTaskExecutor()
ScheduledExecutorService that could be used for executing a potentially
long-running task. The ScheduledExecutorService will propagate the ServiceRequestContext
automatically when running a task.
Note that performing a long-running task in Service.serve(ServiceRequestContext, Request)
may block the Server's I/O event loop and thus should be executed in other threads.
String mappedPath()
RequestContext.path() with its context path removed. This method can be useful for a reusable
service bound at various path prefixes.String decodedMappedPath()
RequestContext.decodedPath() with its context path removed. This method can be useful for
a reusable service bound at various path prefixes.@Nullable MediaType negotiatedResponseMediaType()
Service, null would be returned.@Deprecated @Nullable default MediaType negotiatedProduceType()
negotiatedResponseMediaType().Service, null would be returned.@Deprecated org.slf4j.Logger logger()
RequestContextExportingAppender in
armeria-logback.Logger of the Service.long requestTimeoutMillis()
Request and sending
the corresponding Response completely.
This value is initially set from ServiceConfig.requestTimeoutMillis().void setRequestTimeoutMillis(long requestTimeoutMillis)
Request and sending
the corresponding Response completely.
This value is initially set from ServiceConfig.requestTimeoutMillis().void setRequestTimeout(Duration requestTimeout)
Request and sending
the corresponding Response completely.
This value is initially set from ServiceConfig.requestTimeoutMillis().@Nullable Runnable requestTimeoutHandler()
Request timeout handler which is executed when
receiving the current Request and sending the corresponding Response
is not completely received within the allowed requestTimeoutMillis().void setRequestTimeoutHandler(Runnable requestTimeoutHandler)
requestTimeoutHandler must close the response,
e.g., by calling StreamWriter.close(). If not set, the response will be closed with
HttpStatus.SERVICE_UNAVAILABLE.
For example,
HttpResponseWriter res = HttpResponse.streaming();
ctx.setRequestTimeoutHandler(() -> {
res.write(ResponseHeaders.of(HttpStatus.OK,
HttpHeaderNames.CONTENT_TYPE, MediaType.PLAIN_TEXT_UTF_8));
res.write(HttpData.ofUtf8("Request timed out."));
res.close();
});
...
boolean isTimedOut()
ServiceRequestContext has been timed-out (e.g., when the
corresponding request passes a deadline).isTimedOut in interface RequestContextlong maxRequestLength()
Request.
This value is initially set from ServiceConfig.maxRequestLength().
If 0, there is no limit on the request size.ContentTooLargeExceptionvoid setMaxRequestLength(long maxRequestLength)
Request.
This value is initially set from ServiceConfig.maxRequestLength().
If 0, there is no limit on the request size.ContentTooLargeExceptionboolean verboseResponses()
AccessLogWriter accessLogWriter()
HttpHeaders additionalResponseHeaders()
void setAdditionalResponseHeader(CharSequence name, Object value)
name and value. This will remove all previous values
associated with the specified name.
The header will be included when a Service sends an HttpResponse.void setAdditionalResponseHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
HttpHeaders which is included when a
Service sends an HttpResponse.void addAdditionalResponseHeader(CharSequence name, Object value)
name and value. The header will be included when
a Service sends an HttpResponse.void addAdditionalResponseHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
boolean removeAdditionalResponseHeader(CharSequence name)
name.true if at least one entry has been removedHttpHeaders additionalResponseTrailers()
HttpHeaders which is returned along with any other trailers when a
Service completes an HttpResponse.void setAdditionalResponseTrailer(CharSequence name, Object value)
name and value. This will remove all previous values
associated with the specified name.
The trailer will be included when a Service completes an HttpResponse.void setAdditionalResponseTrailers(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
HttpHeaders which is included when a
Service completes an HttpResponse.void addAdditionalResponseTrailer(CharSequence name, Object value)
name and value. The trailer will be included when
a Service completes an HttpResponse.void addAdditionalResponseTrailers(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
boolean removeAdditionalResponseTrailer(CharSequence name)
name.true if at least one entry has been removedProxiedAddresses proxiedAddresses()
Request.Copyright © 2020 LeanCloud. All rights reserved.