Represents the context for the handling of a request in Vert.x-Web.

A new instance is created for each HTTP request that is received in the accept of the router.

The same instance is passed to any matching request or failure handlers during the routing of the request or failure.

The context provides access to the and and allows you to maintain arbitrary data that lives for the lifetime of the context. Contexts are discarded once they have been routed to the handler for the request.

The context also provides access to the Session, cookies and body for the request, given the correct handlers in the application.

no subtypes hierarchy

Initializer
RoutingContext(RoutingContext unknown)
Inherited Attributes
Attributes inherited from: Object
hash, string
Methods
acceptableLanguagesshared default List<LanguageHeader> acceptableLanguages()

Returns the languages for the current request. The languages are determined from the Accept-Language header and sorted on quality.

When 2 or more entries have the same quality then the order used to return the best match is based on the lowest index on the original list. For example if a user has en-US and en-GB with same quality and this order the best match will be en-US because it was declared as first entry by the client.

acceptableLocalesshared default List<Locale> acceptableLocales()

Returns the locales for the current request. The locales are determined from the accept-languages header and sorted on quality.

When 2 or more entries have the same quality then the order used to return the best match is based on the lowest index on the original list. For example if a user has en-US and en-GB with same quality and this order the best match will be en-US because it was declared as first entry by the client.

addBodyEndHandlershared default Integer addBodyEndHandler(Anything() handler)

Provides a handler that will be called after the last part of the body is written to the wire. The handler is called asynchronously of when the response has been received by the client. This provides a hook allowing you to do more operations once the request has been sent over the wire. Do not use this for resource cleanup as this handler might never get called (e.g. if the connection is reset).

Parameters:
  • handler

    the handler

addCookieshared default RoutingContext addCookie(Cookie cookie)

Add a cookie. This will be sent back to the client in the response. The context must have first been routed to a CookieHandler for this to work.

Parameters:
  • cookie

    the cookie

addHeadersEndHandlershared default Integer addHeadersEndHandler(Anything() handler)

Add a handler that will be called just before headers are written to the response. This gives you a hook where you can write any extra headers before the response has been written when it will be too late.

Parameters:
  • handler

    the handler

clearUsershared default void clearUser()

Clear the current user object in the context. This usually is used for implementing a log out feature, since the current user is unbounded from the routing context.

cookieCountshared default Integer cookieCount()
cookiesshared default Set<Cookie> cookies()
currentRouteshared default Route currentRoute()
failshared default void fail(Integer statusCode)

Fail the context with the specified status code.

This will cause the router to route the context to any matching failure handlers for the request. If no failure handlers match a default failure response will be sent.

Parameters:
  • statusCode

    the HTTP status code

failshared default void fail(Throwable throwable)

Fail the context with the specified throwable.

This will cause the router to route the context to any matching failure handlers for the request. If no failure handlers match a default failure response with status code 500 will be sent.

Parameters:
  • throwable

    a throwable representing the failure

failedshared default Boolean failed()
failureshared default Throwable? failure()

If the context is being routed to failure handlers after a failure has been triggered by calling fail then this will return that throwable. It can be used by failure handlers to render a response, e.g. create a failure response page.

fileUploadsshared default Set<FileUpload> fileUploads()
getshared default T? get<T>(String key)

Get some data from the context. The data is available in any handlers that receive the context.

Parameters:
  • key

    the key for the data

getAcceptableContentTypeshared default String? getAcceptableContentType()

If the route specifies produces matches, e.g. produces text/html and text/plain, and the accept header matches one or more of these then this returns the most acceptable match.

getBodyshared default Buffer? getBody()
getBodyAsJsonshared default Object? getBodyAsJson()
getBodyAsJsonArrayshared default Array? getBodyAsJsonArray()
getBodyAsStringshared default String? getBodyAsString()
getBodyAsStringshared default String? getBodyAsString(String encoding)

Get the entire HTTP request body as a string, assuming the specified encoding. The context must have first been routed to a BodyHandler for this to be populated.

Parameters:
  • encoding

    the encoding, e.g. “UTF-16”

getCookieshared default Cookie? getCookie(String name)

Get the cookie with the specified name. The context must have first been routed to a CookieHandler for this to work.

Parameters:
  • name

    the cookie name

mountPointshared default String? mountPoint()
nextshared default void next()

Tell the router to route this context to the next matching route (if any). This method, if called, does not need to be called during the execution of the handler, it can be called some arbitrary time later, if required.

If next is not called for a handler then the handler should make sure it ends the response or no response will be sent.

normalisedPathshared default String normalisedPath()

Return the normalised path for the request.

The 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 if accessing server resources requested by a client.

parsedHeadersshared default ParsedHeaderValues parsedHeaders()

The headers:

  1. Accept
  2. Accept-Charset
  3. Accept-Encoding
  4. Accept-Language
  5. Content-Type

Parsed into ParsedHeaderValue

pathParamshared default String? pathParam(String name)

Gets the value of a single path parameter

Parameters:
  • name

    the name of parameter as defined in path declaration

pathParamsshared default Map<String,String> pathParams()

Returns a map of named parameters as defined in path declaration with their actual values

preferredLanguageshared default LanguageHeader preferredLanguage()

Helper to return the user preferred language. It is the same action as returning the first element of the acceptable languages.

preferredLocaleshared default Locale preferredLocale()

Helper to return the user preferred locale. It is the same action as returning the first element of the acceptable locales.

putshared default RoutingContext put(String key, Object? obj)

Put some arbitrary data in the context. This will be available in any handlers that receive the context.

Parameters:
  • key

    the key for the data

  • obj

    the data

queryParamshared default List<String>? queryParam(String query)

Gets the value of a single query parameter

Parameters:
  • query

    The name of query parameter

queryParamsshared default MultiMap queryParams()

Returns a map of all query parameters inside the query string

removeshared default T? remove<T>(String key)

Remove some data from the context. The data is available in any handlers that receive the context.

Parameters:
  • key

    the key for the data

removeBodyEndHandlershared default Boolean removeBodyEndHandler(Integer handlerID)

Remove a body end handler

Parameters:
removeCookieshared default Cookie? removeCookie(String name)

Expire a cookie, notifying a User Agent to remove it from its cookie jar. The context must have first been routed to a CookieHandler for this to work.

Parameters:
  • name

    the name of the cookie

removeHeadersEndHandlershared default Boolean removeHeadersEndHandler(Integer handlerID)

Remove a headers end handler

Parameters:
requestshared default HttpServerRequest request()
rerouteshared default void reroute(String path)

Restarts the current router with a new path and reusing the original method. All path parameters are then parsed and available on the params list.

Parameters:
  • path

    the new http path.

rerouteshared default void reroute(HttpMethod method, String path)

Restarts the current router with a new method and path. All path parameters are then parsed and available on the params list.

Parameters:
  • method

    the new http request

  • path

    the new http path.

responseshared default HttpServerResponse response()
sessionshared default Session? session()

Get the session. The context must have first been routed to a SessionHandler for this to be populated. Sessions live for a browser session, and are maintained by session cookies.

setAcceptableContentTypeshared default void setAcceptableContentType(String? contentType)

Set the acceptable content type. Used by

Parameters:
  • contentType

    the content type

setBodyshared default void setBody(Buffer body)

Set the body. Used by the BodyHandler. You will not normally call this method.

Parameters:
  • body

    the body

setSessionshared default void setSession(Session session)

Set the session. Used by the SessionHandler. You will not normally call this method.

Parameters:
  • session

    the session

setUsershared default void setUser(User user)

Set the user. Usually used by auth handlers to inject a User. You will not normally call this method.

Parameters:
  • user

    the user

statusCodeshared default Integer statusCode()

If the context is being routed to failure handlers after a failure has been triggered by calling fail 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.

usershared default User? user()

Get the authenticated user (if any). This will usually be injected by an auth handler if authentication if successful.

vertxshared default Vertx vertx()
Inherited Methods
Methods inherited from: Object
equals