public class ServiceRequestContextWrapper extends RequestContextWrapper<ServiceRequestContext> implements ServiceRequestContext
ServiceRequestContext.| Modifier | Constructor and Description |
|---|---|
protected |
ServiceRequestContextWrapper(ServiceRequestContext delegate)
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
AccessLogWriter |
accessLogWriter()
Returns the
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. |
void |
clearRequestTimeout()
Clears the previously scheduled request timeout, if any.
|
InetAddress |
clientAddress()
Returns the address of the client who initiated this request.
|
String |
decodedMappedPath()
Returns the
RequestContext.decodedPath() with its context path removed. |
void |
extendRequestTimeout(Duration requestTimeout)
Extends the previously scheduled request timeout by the specified amount of
adjustment. |
void |
extendRequestTimeoutMillis(long requestTimeoutMillis)
Extends the previously scheduled request timeout by the specified amount of
adjustmentMillis. |
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, or
null if the connection is not established yet. |
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 RequestContext.attrs() 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. |
HttpRequest |
request()
Returns the
HttpRequest associated with this context, or null if there's no
HttpRequest associated with this context yet. |
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)
Deprecated.
|
void |
setRequestTimeoutAfter(Duration requestTimeout)
|
void |
setRequestTimeoutAfterMillis(long requestTimeoutMillis)
|
void |
setRequestTimeoutAt(Instant requestTimeoutAt)
Schedules the request timeout that is triggered at the specified time represented
as the number since the epoch (
1970-01-01T00:00:00Z). |
void |
setRequestTimeoutAtMillis(long requestTimeoutAtMillis)
Schedules the request timeout that is triggered at the specified time represented
as the number since the epoch (
1970-01-01T00:00:00Z). |
void |
setRequestTimeoutHandler(Runnable requestTimeoutHandler)
Sets a handler to run when the request times out.
|
void |
setRequestTimeoutMillis(long requestTimeoutMillis)
Deprecated.
|
boolean |
verboseResponses()
Returns whether the verbose response mode is enabled.
|
VirtualHost |
virtualHost()
Returns the
VirtualHost that is handling the current Request. |
alloc, attr, attrs, computeAttrIfAbsent, decodedPath, delegate, eventLoop, id, log, logBuilder, meterRegistry, method, path, query, rpcRequest, sessionProtocol, setAttr, setAttrIfAbsent, sslSession, updateRequest, updateRpcRequestclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbuilder, current, currentOrNull, mapCurrent, negotiatedProduceType, of, pathParam, push, rpcRequestalloc, attr, attrs, computeAttrIfAbsent, contextAwareEventLoop, contextAwareExecutor, decodedPath, eventLoop, executor, id, log, logBuilder, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, mapCurrent, meterRegistry, method, path, push, push, push, pushIfAbsent, query, rejectPromise, replace, resolvePromise, sessionProtocol, setAttr, setAttrIfAbsent, sslSession, updateRequest, updateRpcRequestprotected ServiceRequestContextWrapper(ServiceRequestContext delegate)
public HttpRequest request()
RequestContextHttpRequest associated with this context, or null if there's no
HttpRequest associated with this context yet.request in interface RequestContextrequest in interface ServiceRequestContextrequest in class RequestContextWrapper<ServiceRequestContext>public <A extends SocketAddress> A remoteAddress()
RequestContextnull if the connection is not established yet.remoteAddress in interface RequestContextremoteAddress in interface ServiceRequestContextremoteAddress in class RequestContextWrapper<ServiceRequestContext>public <A extends SocketAddress> A localAddress()
RequestContextnull if the connection is not established yet.localAddress in interface RequestContextlocalAddress in interface ServiceRequestContextlocalAddress in class RequestContextWrapper<ServiceRequestContext>public boolean isTimedOut()
ServiceRequestContextServiceRequestContext has been timed-out (e.g., when the
corresponding request passes a deadline).isTimedOut in interface ServiceRequestContextpublic InetAddress clientAddress()
ServiceRequestContextclientAddress in interface ServiceRequestContextpublic ServiceRequestContext newDerivedContext(RequestId id, HttpRequest req, RpcRequest rpcReq)
RequestContextRequestContext whose properties and RequestContext.attrs() are copied from this
RequestContext, except having a different pair of HttpRequest and RpcRequest
and its own RequestLog.newDerivedContext in interface RequestContextnewDerivedContext in interface ServiceRequestContextpublic 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 ServiceRequestContextpublic MediaType negotiatedResponseMediaType()
ServiceRequestContextService, null would be returned.negotiatedResponseMediaType in interface ServiceRequestContextpublic long requestTimeoutMillis()
ServiceRequestContextRequest until receiving
the current Request and sending the corresponding Response completely.
This value is initially set from ServiceConfig.requestTimeoutMillis().requestTimeoutMillis in interface ServiceRequestContextpublic void clearRequestTimeout()
ServiceRequestContextclearRequestTimeout in interface ServiceRequestContext@Deprecated public void setRequestTimeoutMillis(long requestTimeoutMillis)
ServiceRequestContextRequest is not fully received or
the corresponding Response is not sent completely since the Request started.
This value is initially set from ServiceConfig.requestTimeoutMillis().
For example:
ServiceRequestContext ctx = ...;
ctx.setRequestTimeoutMillis(1000);
assert ctx.requestTimeoutMillis() == 1000;
ctx.setRequestTimeoutMillis(2000);
assert ctx.requestTimeoutMillis() == 2000;
setRequestTimeoutMillis in interface ServiceRequestContextrequestTimeoutMillis - the amount of time in milliseconds from the start time of the request@Deprecated public void setRequestTimeout(Duration requestTimeout)
ServiceRequestContextRequest is not fully received or
the corresponding Response is not sent completely since the Request started.
This value is initially set from ServiceConfig.requestTimeoutMillis().
For example:
ServiceRequestContext ctx = ...;
ctx.setRequestTimeout(Duration.ofSeconds(1));
assert ctx.requestTimeoutMillis() == 1000;
ctx.setRequestTimeout(Duration.ofSeconds(2));
assert ctx.requestTimeoutMillis() == 2000;
setRequestTimeout in interface ServiceRequestContextrequestTimeout - the amount of time from the start time of the requestpublic void extendRequestTimeoutMillis(long requestTimeoutMillis)
ServiceRequestContextadjustmentMillis.
This method does nothing if no request timeout was scheduled previously.
Note that a negative adjustment reduces the current timeout.
The initial timeout is set from ServiceConfig.requestTimeoutMillis().
For example:
ServiceRequestContext ctx = ...;
long oldRequestTimeoutMillis = ctx.requestTimeoutMillis();
ctx.extendRequestTimeoutMillis(1000);
assert ctx.requestTimeoutMillis() == oldRequestTimeoutMillis + 1000;
ctx.extendRequestTimeoutMillis(-500);
assert ctx.requestTimeoutMillis() == oldRequestTimeoutMillis + 500;
extendRequestTimeoutMillis in interface ServiceRequestContextrequestTimeoutMillis - the amount of time in milliseconds to extend the current timeout bypublic void extendRequestTimeout(Duration requestTimeout)
ServiceRequestContextadjustment.
This method does nothing if no response timeout was scheduled previously.
Note that a negative adjustment reduces the current timeout.
The initial timeout is set from ServiceConfig.requestTimeoutMillis().
For example:
ServiceRequestContext ctx = ...;
long oldRequestTimeoutMillis = ctx.requestTimeoutMillis();
ctx.extendRequestTimeout(Duration.ofSeconds(1));
assert ctx.requestTimeoutMillis() == oldRequestTimeoutMillis + 1000;
ctx.extendRequestTimeout(Duration.ofMillis(-500));
assert ctx.requestTimeoutMillis() == oldRequestTimeoutMillis + 500;
extendRequestTimeout in interface ServiceRequestContextrequestTimeout - the amount of time to extend the current timeout bypublic void setRequestTimeoutAfterMillis(long requestTimeoutMillis)
ServiceRequestContextRequest is not fully received or
the corresponding Response is not sent completely within the specified amount of time from now.
Note that the specified requestTimeoutMillis must be positive.
The initial timeout is set from ServiceConfig.requestTimeoutMillis().
For example:
ServiceRequestContext ctx = ...;
// Schedules timeout after 1 seconds from now.
ctx.setRequestTimeoutAfterMillis(1000);
setRequestTimeoutAfterMillis in interface ServiceRequestContextrequestTimeoutMillis - the amount of time allowed in milliseconds from nowpublic void setRequestTimeoutAfter(Duration requestTimeout)
ServiceRequestContextRequest is not fully received or
the corresponding Response is not sent completely within the specified amount time from now.
Note that the specified requestTimeout must be positive.
The initial timeout is set from ServiceConfig.requestTimeoutMillis().
For example:
ServiceRequestContext ctx = ...;
// Schedules timeout after 1 seconds from now.
ctx.setRequestTimeoutAfter(Duration.ofSeconds(1));
setRequestTimeoutAfter in interface ServiceRequestContextrequestTimeout - the amount of time allowed from nowpublic void setRequestTimeoutAtMillis(long requestTimeoutAtMillis)
ServiceRequestContext1970-01-01T00:00:00Z).
Note that the request will be timed out immediately if the specified time is before now.
The initial timeout is set from ServiceConfig.requestTimeoutMillis().
For example:
ServiceRequestContext ctx = ...;
// Schedules timeout after 1 seconds from now.
long responseTimeoutAt = Instant.now().plus(1, ChronoUnit.SECONDS).toEpochMilli();
ctx.setRequestTimeoutAtMillis(responseTimeoutAt);
setRequestTimeoutAtMillis in interface ServiceRequestContextrequestTimeoutAtMillis - the request timeout represented as the number of milliseconds
since the epoch (1970-01-01T00:00:00Z)public void setRequestTimeoutAt(Instant requestTimeoutAt)
ServiceRequestContext1970-01-01T00:00:00Z).
Note that the request will be timed out immediately if the specified time is before now.
The initial timeout is set from ServiceConfig.requestTimeoutMillis().
For example:
ServiceRequestContext ctx = ...;
// Schedules timeout after 1 seconds from now.
ctx.setRequestTimeoutAt(Instant.now().plus(1, ChronoUnit.SECONDS));
setRequestTimeoutAt in interface ServiceRequestContextrequestTimeoutAt - the request timeout represented as the number of milliseconds
since the epoch (1970-01-01T00:00:00Z)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 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()
ServiceRequestContextAccessLogWriter.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 ServiceRequestContextCopyright © 2020 LeanCloud. All rights reserved.