public class DefaultServiceRequestContext extends NonWrappingRequestContext implements ServiceRequestContext
ServiceRequestContext implementation.| Constructor and Description |
|---|
DefaultServiceRequestContext(ServiceConfig cfg,
io.netty.channel.Channel ch,
MeterRegistry meterRegistry,
SessionProtocol sessionProtocol,
RequestId id,
RoutingContext routingContext,
RoutingResult routingResult,
HttpRequest request,
SSLSession sslSession,
ProxiedAddresses proxiedAddresses,
InetAddress clientAddress)
Creates a new instance.
|
DefaultServiceRequestContext(ServiceConfig cfg,
io.netty.channel.Channel ch,
MeterRegistry meterRegistry,
SessionProtocol sessionProtocol,
RequestId id,
RoutingContext routingContext,
RoutingResult routingResult,
HttpRequest request,
SSLSession sslSession,
ProxiedAddresses proxiedAddresses,
InetAddress clientAddress,
long requestStartTimeNanos,
long requestStartTimeMicros)
Creates a new 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. |
io.netty.buffer.ByteBufAllocator |
alloc()
Returns the
ByteBufAllocator for this RequestContext. |
ScheduledExecutorService |
blockingTaskExecutor()
Returns the
ScheduledExecutorService that could be used for executing a potentially
long-running task. |
protected io.netty.channel.Channel |
channel()
Returns the
Channel that is handling this request, or null if the connection is not
established yet. |
InetAddress |
clientAddress()
Returns the address of the client who initiated this request.
|
String |
decodedMappedPath()
Returns the
RequestContext.decodedPath() with its context path removed. |
io.netty.channel.EventLoop |
eventLoop()
Returns the
EventLoop that is handling the current Request. |
<A extends SocketAddress> |
localAddress()
Returns the local address of this request, or
null if the connection is not established yet. |
RequestLog |
log()
Returns the
RequestLog that contains the information about the current Request. |
RequestLogBuilder |
logBuilder()
Returns the
RequestLogBuilder that collects the information about the current Request. |
org.slf4j.Logger |
logger()
Returns the
Logger of the Service. |
String |
mappedPath()
Returns the
RequestContext.path() with its context path removed. |
long |
maxRequestLength()
Returns the maximum length of the current
Request. |
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. |
Map<String,String> |
pathParams()
Returns the path parameters mapped by the
ServiceRequestContext.route() associated with the Service
that is handling the current Request. |
ProxiedAddresses |
proxiedAddresses()
Returns the proxied addresses of the current
Request. |
<A extends SocketAddress> |
remoteAddress()
Returns the remote address of this request, or
null if the connection is not established yet. |
boolean |
removeAdditionalResponseHeader(CharSequence name)
Removes all headers with the specified
name. |
boolean |
removeAdditionalResponseTrailer(CharSequence name)
Removes all trailers with the specified
name. |
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 ServiceRequestContext.requestTimeoutMillis(). |
long |
requestTimeoutMillis()
|
Route |
route()
|
RoutingContext |
routingContext()
Returns the
RoutingContext used to find the Service. |
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 |
setRequestTimeoutChangeListener(RequestTimeoutChangeListener listener)
Sets the listener that is notified when the requestTimeoutMillis() request timeout} of
the request is changed.
|
void |
setRequestTimeoutHandler(Runnable requestTimeoutHandler)
Sets a handler to run when the request times out.
|
void |
setRequestTimeoutMillis(long requestTimeoutMillis)
|
void |
setTimedOut()
Marks this
ServiceRequestContext as having been timed out. |
SSLSession |
sslSession()
The
SSLSession for this request if the connection is made over TLS, or null if
the connection is not established yet or the connection is not a TLS connection. |
String |
toString() |
boolean |
verboseResponses()
Returns whether the verbose response mode is enabled.
|
VirtualHost |
virtualHost()
Returns the
VirtualHost that is handling the current Request. |
attr, attrs, decodedPath, hasAttr, id, invokeOnChildCallbacks, invokeOnEnterCallbacks, invokeOnExitCallbacks, meterRegistry, method, onChild, onEnter, onExit, path, query, request, rpcRequest, sessionProtocol, unsafeUpdateRequest, updateRequest, updateRpcRequest, validateHeaderscontextAwareEventLoop, contextAwareExecutor, equals, executor, hashCode, isTimedOut, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, onEnter, onExit, push, push, pushIfAbsent, rejectPromise, resolvePromiseclone, finalize, getClass, notify, notifyAll, wait, wait, waitbuilder, current, currentOrNull, isTimedOut, mapCurrent, negotiatedProduceType, of, pathParam, request, rpcRequestattrs, contextAwareEventLoop, contextAwareExecutor, decodedPath, executor, id, invokeOnChildCallbacks, invokeOnEnterCallbacks, invokeOnExitCallbacks, 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, updateRequest, updateRpcRequestpublic DefaultServiceRequestContext(ServiceConfig cfg, io.netty.channel.Channel ch, MeterRegistry meterRegistry, SessionProtocol sessionProtocol, RequestId id, RoutingContext routingContext, RoutingResult routingResult, HttpRequest request, @Nullable SSLSession sslSession, ProxiedAddresses proxiedAddresses, InetAddress clientAddress)
cfg - the ServiceConfigch - the Channel that handles the invocationmeterRegistry - the MeterRegistry that collects various statssessionProtocol - the SessionProtocol of the invocationid - the RequestId that represents the identifier of the current Request
and Response pair.routingContext - the parameters which are used when finding a matched RouteroutingResult - the result of finding a matched Routerequest - the request associated with this contextsslSession - the SSLSession for this invocation if it is over TLSproxiedAddresses - source and destination addresses delivered through proxy serversclientAddress - the address of a client who initiated the requestpublic DefaultServiceRequestContext(ServiceConfig cfg, io.netty.channel.Channel ch, MeterRegistry meterRegistry, SessionProtocol sessionProtocol, RequestId id, RoutingContext routingContext, RoutingResult routingResult, HttpRequest request, @Nullable SSLSession sslSession, ProxiedAddresses proxiedAddresses, InetAddress clientAddress, long requestStartTimeNanos, long requestStartTimeMicros)
cfg - the ServiceConfigch - the Channel that handles the invocationmeterRegistry - the MeterRegistry that collects various statssessionProtocol - the SessionProtocol of the invocationid - the RequestId that represents the identifier of the current Request
and Response pair.routingContext - the parameters which are used when finding a matched RouteroutingResult - the result of finding a matched Routerequest - the request associated with this contextsslSession - the SSLSession for this invocation if it is over TLSproxiedAddresses - source and destination addresses delivered through proxy serversclientAddress - the address of a client who initiated the requestrequestStartTimeNanos - System.nanoTime() value when the request started.requestStartTimeMicros - the number of microseconds since the epoch,
e.g. System.currentTimeMillis() * 1000.@Nonnull public <A extends SocketAddress> A remoteAddress()
RequestContextnull if the connection is not established yet.remoteAddress in interface RequestContextremoteAddress in interface ServiceRequestContextremoteAddress in class NonWrappingRequestContext@Nonnull public <A extends SocketAddress> A localAddress()
RequestContextnull if the connection is not established yet.localAddress in interface RequestContextlocalAddress in interface ServiceRequestContextlocalAddress in class NonWrappingRequestContextpublic InetAddress clientAddress()
ServiceRequestContextclientAddress in interface ServiceRequestContextpublic 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 RequestContextnewDerivedContext in interface ServiceRequestContextprotected io.netty.channel.Channel channel()
NonWrappingRequestContextChannel that is handling this request, or null if the connection is not
established yet.channel in class NonWrappingRequestContextpublic Server server()
ServiceRequestContextserver in interface ServiceRequestContextpublic VirtualHost virtualHost()
ServiceRequestContextVirtualHost that is handling the current Request.virtualHost in interface ServiceRequestContextpublic Route route()
ServiceRequestContextroute in interface ServiceRequestContextpublic RoutingContext routingContext()
ServiceRequestContextRoutingContext used to find the Service.routingContext in interface ServiceRequestContextpublic Map<String,String> pathParams()
ServiceRequestContextServiceRequestContext.route() associated with the Service
that is handling the current Request.pathParams in interface ServiceRequestContextpublic HttpService service()
ServiceRequestContextHttpService that is handling the current Request.service in interface ServiceRequestContextpublic ScheduledExecutorService blockingTaskExecutor()
ServiceRequestContextScheduledExecutorService 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.
blockingTaskExecutor in interface ServiceRequestContextpublic String mappedPath()
ServiceRequestContextRequestContext.path() with its context path removed. This method can be useful for a reusable
service bound at various path prefixes.mappedPath in interface ServiceRequestContextpublic String decodedMappedPath()
ServiceRequestContextRequestContext.decodedPath() with its context path removed. This method can be useful for
a reusable service bound at various path prefixes.decodedMappedPath in interface ServiceRequestContext@Nullable public MediaType negotiatedResponseMediaType()
ServiceRequestContextService, null would be returned.negotiatedResponseMediaType in interface ServiceRequestContextpublic io.netty.channel.EventLoop eventLoop()
RequestContextEventLoop that is handling the current Request.eventLoop in interface RequestContextpublic org.slf4j.Logger logger()
ServiceRequestContextLogger of the Service.logger in interface ServiceRequestContext@Nullable public SSLSession sslSession()
RequestContextSSLSession for this request if the connection is made over TLS, or null if
the connection is not established yet or the connection is not a TLS connection.sslSession in interface RequestContextpublic long requestTimeoutMillis()
ServiceRequestContextRequest and sending
the corresponding Response completely.
This value is initially set from ServiceConfig.requestTimeoutMillis().requestTimeoutMillis in interface ServiceRequestContextpublic void setRequestTimeoutMillis(long requestTimeoutMillis)
ServiceRequestContextRequest and sending
the corresponding Response completely.
This value is initially set from ServiceConfig.requestTimeoutMillis().setRequestTimeoutMillis in interface ServiceRequestContextpublic void setRequestTimeout(Duration requestTimeout)
ServiceRequestContextRequest and sending
the corresponding Response completely.
This value is initially set from ServiceConfig.requestTimeoutMillis().setRequestTimeout in interface ServiceRequestContext@Nullable public Runnable requestTimeoutHandler()
ServiceRequestContextRequest timeout handler which is executed when
receiving the current Request and sending the corresponding Response
is not completely received within the allowed ServiceRequestContext.requestTimeoutMillis().requestTimeoutHandler in interface ServiceRequestContextpublic void setRequestTimeoutHandler(Runnable requestTimeoutHandler)
ServiceRequestContextrequestTimeoutHandler 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();
});
...
setRequestTimeoutHandler in interface ServiceRequestContextpublic void setTimedOut()
ServiceRequestContext as having been timed out. Any callbacks created with
makeContextAware that are run after this will be failed with CancellationException.setTimedOut in class AbstractRequestContextpublic long maxRequestLength()
ServiceRequestContextRequest.
This value is initially set from ServiceConfig.maxRequestLength().
If 0, there is no limit on the request size.maxRequestLength in interface ServiceRequestContextContentTooLargeExceptionpublic void setMaxRequestLength(long maxRequestLength)
ServiceRequestContextRequest.
This value is initially set from ServiceConfig.maxRequestLength().
If 0, there is no limit on the request size.setMaxRequestLength in interface ServiceRequestContextContentTooLargeExceptionpublic boolean verboseResponses()
ServiceRequestContextverboseResponses in interface ServiceRequestContextpublic AccessLogWriter accessLogWriter()
accessLogWriter in interface ServiceRequestContextpublic HttpHeaders additionalResponseHeaders()
ServiceRequestContextadditionalResponseHeaders in interface ServiceRequestContextpublic void setAdditionalResponseHeader(CharSequence name, Object value)
ServiceRequestContextname and value. This will remove all previous values
associated with the specified name.
The header will be included when a Service sends an HttpResponse.setAdditionalResponseHeader in interface ServiceRequestContextpublic void setAdditionalResponseHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
ServiceRequestContextHttpHeaders which is included when a
Service sends an HttpResponse.setAdditionalResponseHeaders in interface ServiceRequestContextpublic void addAdditionalResponseHeader(CharSequence name, Object value)
ServiceRequestContextname and value. The header will be included when
a Service sends an HttpResponse.addAdditionalResponseHeader in interface ServiceRequestContextpublic void addAdditionalResponseHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
ServiceRequestContextaddAdditionalResponseHeaders in interface ServiceRequestContextpublic boolean removeAdditionalResponseHeader(CharSequence name)
ServiceRequestContextname.removeAdditionalResponseHeader in interface ServiceRequestContexttrue if at least one entry has been removedpublic HttpHeaders additionalResponseTrailers()
ServiceRequestContextHttpHeaders which is returned along with any other trailers when a
Service completes an HttpResponse.additionalResponseTrailers in interface ServiceRequestContextpublic void setAdditionalResponseTrailer(CharSequence name, Object value)
ServiceRequestContextname and value. This will remove all previous values
associated with the specified name.
The trailer will be included when a Service completes an HttpResponse.setAdditionalResponseTrailer in interface ServiceRequestContextpublic void setAdditionalResponseTrailers(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
ServiceRequestContextHttpHeaders which is included when a
Service completes an HttpResponse.setAdditionalResponseTrailers in interface ServiceRequestContextpublic void addAdditionalResponseTrailer(CharSequence name, Object value)
ServiceRequestContextname and value. The trailer will be included when
a Service completes an HttpResponse.addAdditionalResponseTrailer in interface ServiceRequestContextpublic void addAdditionalResponseTrailers(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
ServiceRequestContextaddAdditionalResponseTrailers in interface ServiceRequestContextpublic boolean removeAdditionalResponseTrailer(CharSequence name)
ServiceRequestContextname.removeAdditionalResponseTrailer in interface ServiceRequestContexttrue if at least one entry has been removedpublic ProxiedAddresses proxiedAddresses()
ServiceRequestContextRequest.proxiedAddresses in interface ServiceRequestContextpublic RequestLog log()
RequestContextRequestLog that contains the information about the current Request.log in interface RequestContextpublic RequestLogBuilder logBuilder()
RequestContextRequestLogBuilder that collects the information about the current Request.logBuilder in interface RequestContextpublic io.netty.buffer.ByteBufAllocator alloc()
RequestContextByteBufAllocator for this RequestContext. Any buffers created by this
ByteBufAllocator must be
reference-counted. If you don't know
what this means, you should probably use byte[] or ByteBuffer directly instead
of calling this method.alloc in interface RequestContextpublic void setRequestTimeoutChangeListener(RequestTimeoutChangeListener listener)
Note: This method is meant for internal use by server-side protocol implementation to reschedule a timeout task when a user updates the request timeout configuration.
Copyright © 2020 LeanCloud. All rights reserved.