public class RoutingContextDecorator extends Object implements RoutingContext
RoutingContext and simply delegate all method calls to the decorated handler| Constructor and Description |
|---|
RoutingContextDecorator(Route currentRoute,
RoutingContext decoratedContext) |
| Modifier and Type | Method and Description |
|---|---|
List<Locale> |
acceptableLocales()
Returns the locales for the current request.
|
int |
addBodyEndHandler(Handler<Void> handler)
Provides a handler that will be called after the last part of the body is written to the wire.
|
RoutingContext |
addCookie(Cookie cookie)
Add a cookie.
|
RoutingContext |
addCookie(Cookie cookie)
Add a cookie.
|
int |
addHeadersEndHandler(Handler<Void> handler)
Add a handler that will be called just before headers are written to the response.
|
void |
clearUser()
Clear the current user object in the context.
|
int |
cookieCount() |
Map<String,Cookie> |
cookieMap() |
Set<Cookie> |
cookies() |
Route |
currentRoute() |
Map<String,Object> |
data() |
void |
fail(int statusCode)
Fail the context with the specified status code.
|
void |
fail(int statusCode,
Throwable throwable)
Fail the context with the specified throwable and the specified the status code.
|
void |
fail(Throwable throwable)
Fail the context with the specified throwable and 500 status code.
|
boolean |
failed() |
Throwable |
failure()
If the context is being routed to failure handlers after a failure has been triggered by calling
RoutingContext.fail(Throwable) then this will return that throwable. |
Set<FileUpload> |
fileUploads() |
<T> T |
get(String key)
Get some data from the context.
|
String |
getAcceptableContentType()
If the route specifies produces matches, e.g.
|
Buffer |
getBody() |
JsonObject |
getBodyAsJson() |
JsonArray |
getBodyAsJsonArray() |
String |
getBodyAsString() |
String |
getBodyAsString(String encoding)
Get the entire HTTP request body as a string, assuming the specified encoding.
|
Cookie |
getCookie(String name)
Get the cookie with the specified name.
|
String |
mountPoint() |
void |
next()
Tell the router to route this context to the next matching route (if any).
|
String |
normalisedPath()
Return the normalised path for the request.
|
ParsedHeaderValues |
parsedHeaders()
The headers:
Accept
Accept-Charset
Accept-Encoding
Accept-Language
Content-Type
Parsed into
ParsedHeaderValue |
String |
pathParam(String name)
Gets the value of a single path parameter
|
Map<String,String> |
pathParams()
Returns a map of named parameters as defined in path declaration with their actual values
|
RoutingContext |
put(String key,
Object obj)
Put some arbitrary data in the context.
|
List<String> |
queryParam(String query)
Gets the value of a single query parameter.
|
MultiMap |
queryParams()
Returns a map of all query parameters inside the query string
The query parameters are lazily decoded: the decoding happens on the first time this method is called. |
<T> T |
remove(String key)
Remove some data from the context.
|
boolean |
removeBodyEndHandler(int handlerID)
Remove a body end handler
|
Cookie |
removeCookie(String name,
boolean invalidate)
Remove a cookie from the cookie set.
|
boolean |
removeHeadersEndHandler(int handlerID)
Remove a headers end handler
|
HttpServerRequest |
request() |
void |
reroute(HttpMethod method,
String path)
Restarts the current router with a new method and path.
|
HttpServerResponse |
response() |
Session |
session()
Get the session.
|
void |
setAcceptableContentType(String contentType)
Set the acceptable content type.
|
void |
setBody(Buffer body)
Set the body.
|
void |
setSession(Session session)
Set the session.
|
void |
setUser(User user)
Set the user.
|
int |
statusCode()
If the context is being routed to failure handlers after a failure has been triggered by calling
RoutingContext.fail(int) then this will return that status code. |
User |
user()
Get the authenticated user (if any).
|
Vertx |
vertx() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitacceptableLanguages, preferredLanguage, preferredLocale, removeCookie, reroutepublic RoutingContextDecorator(Route currentRoute, RoutingContext decoratedContext)
public int addBodyEndHandler(Handler<Void> handler)
RoutingContextaddBodyEndHandler in interface RoutingContexthandler - the handlerpublic RoutingContext addCookie(Cookie cookie)
RoutingContextaddCookie in interface RoutingContextcookie - the cookiepublic RoutingContext addCookie(Cookie cookie)
RoutingContextaddCookie in interface RoutingContextcookie - the cookiepublic int addHeadersEndHandler(Handler<Void> handler)
RoutingContextaddHeadersEndHandler in interface RoutingContexthandler - the handlerpublic int cookieCount()
cookieCount in interface RoutingContextpublic Set<Cookie> cookies()
cookies in interface RoutingContextpublic Map<String,Cookie> cookieMap()
cookieMap in interface RoutingContextpublic Route currentRoute()
currentRoute in interface RoutingContextpublic Map<String,Object> data()
data in interface RoutingContextpublic void fail(int statusCode)
RoutingContext
This will cause the router to route the context to any matching failure handlers for the request. If no failure handlers
match It will trigger the error handler matching the status code. You can define such error handler with
Router.errorHandler(int, Handler). If no error handler is not defined, It will send a default failure response with provided status code.
fail in interface RoutingContextstatusCode - the HTTP status codepublic void fail(Throwable throwable)
RoutingContext
This will cause the router to route the context to any matching failure handlers for the request. If no failure handlers
match It will trigger the error handler matching the status code. You can define such error handler with
Router.errorHandler(int, Handler). If no error handler is not defined, It will send a default failure response with 500 status code.
fail in interface RoutingContextthrowable - a throwable representing the failurepublic void fail(int statusCode,
Throwable throwable)
RoutingContext
This will cause the router to route the context to any matching failure handlers for the request. If no failure handlers
match It will trigger the error handler matching the status code. You can define such error handler with
Router.errorHandler(int, Handler). If no error handler is not defined, It will send a default failure response with provided status code.
fail in interface RoutingContextstatusCode - the HTTP status codethrowable - a throwable representing the failurepublic boolean failed()
failed in interface RoutingContextpublic Throwable failure()
RoutingContextRoutingContext.fail(Throwable) then this will return that throwable. It can be used by failure handlers to render a response,
e.g. create a failure response page.failure in interface RoutingContextpublic Set<FileUpload> fileUploads()
fileUploads in interface RoutingContextBodyHandler for this to work.public <T> T get(String key)
RoutingContextget in interface RoutingContextT - the type of the datakey - the key for the datapublic <T> T remove(String key)
RoutingContextremove in interface RoutingContextT - the type of the datakey - the key for the datapublic String getAcceptableContentType()
RoutingContextgetAcceptableContentType in interface RoutingContextpublic Buffer getBody()
getBody in interface RoutingContextBuffer. The context must have first been routed to a
BodyHandler for this to be populated.public JsonObject getBodyAsJson()
getBodyAsJson in interface RoutingContextJsonObject. The context must have first been routed to a
BodyHandler for this to be populated.
null or the "null" JSON literal then null is returned.public JsonArray getBodyAsJsonArray()
getBodyAsJsonArray in interface RoutingContextJsonArray. The context must have first been routed to a
BodyHandler for this to be populated.
null or the "null" JSON literal then null is returned.public String getBodyAsString()
getBodyAsString in interface RoutingContextBodyHandler for this to be populated.public String getBodyAsString(String encoding)
RoutingContextBodyHandler for this to be populated.getBodyAsString in interface RoutingContextencoding - the encoding, e.g. "UTF-16"public Cookie getCookie(String name)
RoutingContextgetCookie in interface RoutingContextname - the cookie namepublic String mountPoint()
mountPoint in interface RoutingContextpublic void next()
RoutingContextIf next is not called for a handler then the handler should make sure it ends the response or no response will be sent.
next in interface RoutingContextpublic String normalisedPath()
RoutingContextThe normalised path is where the URI path has been decoded, i.e. any unicode or other illegal URL characters that were encoded in the original URL with `%` will be returned to their original form. E.g. `%20` will revert to a space. Also `+` reverts to a space in a query.
The normalised path will also not contain any `..` character sequences to prevent resources being accessed outside of the permitted area.
It's recommended to always use the normalised path as opposed to HttpServerRequest.path()
if accessing server resources requested by a client.
normalisedPath in interface RoutingContextpublic RoutingContext put(String key, Object obj)
RoutingContextput in interface RoutingContextkey - the key for the dataobj - the datapublic boolean removeBodyEndHandler(int handlerID)
RoutingContextremoveBodyEndHandler in interface RoutingContexthandlerID - the id as returned from RoutingContext.addBodyEndHandler(Handler).public Cookie removeCookie(String name, boolean invalidate)
RoutingContextremoveCookie in interface RoutingContextname - the name of the cookiepublic boolean removeHeadersEndHandler(int handlerID)
RoutingContextremoveHeadersEndHandler in interface RoutingContexthandlerID - the id as returned from RoutingContext.addHeadersEndHandler(Handler).public HttpServerRequest request()
request in interface RoutingContextpublic HttpServerResponse response()
response in interface RoutingContextpublic User user()
RoutingContextuser in interface RoutingContextpublic Session session()
RoutingContextSessionHandler
for this to be populated.
Sessions live for a browser session, and are maintained by session cookies.session in interface RoutingContextpublic ParsedHeaderValues parsedHeaders()
RoutingContextParsedHeaderValueparsedHeaders in interface RoutingContextpublic void setAcceptableContentType(String contentType)
RoutingContextsetAcceptableContentType in interface RoutingContextcontentType - the content typepublic void reroute(HttpMethod method, String path)
RoutingContextreroute in interface RoutingContextmethod - the new http requestpath - the new http path.public List<Locale> acceptableLocales()
RoutingContextacceptableLocales in interface RoutingContextpublic Map<String,String> pathParams()
RoutingContextpathParams in interface RoutingContextpublic String pathParam(String name)
RoutingContextpathParam in interface RoutingContextname - the name of parameter as defined in path declarationpublic MultiMap queryParams()
RoutingContextqueryParams in interface RoutingContextpublic List<String> queryParam(String query)
RoutingContextRoutingContext.queryParams()queryParam in interface RoutingContextquery - The name of query parametername was foundpublic void setBody(Buffer body)
RoutingContextBodyHandler. You will not normally call this method.setBody in interface RoutingContextbody - the bodypublic void setSession(Session session)
RoutingContextSessionHandler. You will not normally call this method.setSession in interface RoutingContextsession - the sessionpublic void setUser(User user)
RoutingContextsetUser in interface RoutingContextuser - the userpublic void clearUser()
RoutingContextclearUser in interface RoutingContextpublic int statusCode()
RoutingContextRoutingContext.fail(int) then this will return that status code. It can be used by failure handlers to render a response,
e.g. create a failure response page.
When the status code has not been set yet (it is undefined) its value will be -1.statusCode in interface RoutingContextpublic Vertx vertx()
vertx in interface RoutingContextRouter for this contextCopyright © 2020. All rights reserved.