class RoutingContext extends AnyRef
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 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 io.vertx.scala.ext.web.Session, cookies and body for the request, given the correct handlers in the application.
- Alphabetic
- By Inheritance
- RoutingContext
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new RoutingContext(_asJava: AnyRef)
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
acceptableLanguages(): Buffer[LanguageHeader]
Returns the languages for the current request.
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. * @return The best matched language for the request
-
def
acceptableLocales(): Buffer[Locale]
Returns the locales for the current request.
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. * @return the best matched locale for the request
-
def
addBodyEndHandler(handler: Handler[Unit]): Int
Provides a handler that will be called after the last part of the body is written to the wire.
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). * @param handler the handler
- returns
the id of the handler. This can be used if you later want to remove the handler.
-
def
addCookie(cookie: Cookie): RoutingContext
Add a cookie.
Add a cookie. This will be sent back to the client in the response. The context must have first been routed to a io.vertx.scala.ext.web.handler.CookieHandler for this to work. * @param cookie the cookie
- returns
a reference to this, so the API can be used fluently
-
def
addHeadersEndHandler(handler: Handler[Unit]): Int
Add a handler that will be called just before headers are written to the response.
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. * @param handler the handler
- returns
the id of the handler. This can be used if you later want to remove the handler.
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
- def asJava: AnyRef
-
def
clearUser(): Unit
Clear the current user object in the context.
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.
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
cookieCount(): Int
- returns
the number of cookies. The context must have first been routed to a io.vertx.scala.ext.web.handler.CookieHandler for this to work.
-
def
cookies(): Set[Cookie]
- returns
a set of all the cookies. The context must have first been routed to a io.vertx.scala.ext.web.handler.CookieHandler for this to be populated.
-
def
currentRoute(): Route
- returns
the current route this context is being routed through.
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
fail(throwable: Throwable): Unit
Fail the context with the specified 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. * @param throwable a throwable representing the failure
-
def
fail(statusCode: Int): Unit
Fail the context with the specified status code.
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. * @param statusCode the HTTP status code
-
def
failed(): Boolean
- returns
true if the context is being routed to failure handlers.
-
def
failure(): Throwable
If the context is being routed to failure handlers after a failure has been triggered by calling io.vertx.scala.ext.web.RoutingContext#fail then this will return that throwable.
If the context is being routed to failure handlers after a failure has been triggered by calling io.vertx.scala.ext.web.RoutingContext#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. * @return the throwable used when signalling failure
-
def
fileUploads(): Set[FileUpload]
- returns
a set of fileuploads (if any) for the request. The context must have first been routed to a io.vertx.scala.ext.web.handler.BodyHandler for this to work.
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
get[T](key: String)(implicit arg0: scala.reflect.api.JavaUniverse.TypeTag[T]): T
Get some data from the context.
Get some data from the context. The data is available in any handlers that receive the context. * @param key the key for the data
- returns
the data
-
def
getAcceptableContentType(): Option[String]
If the route specifies produces matches, e.g.
If the route specifies produces matches, e.g. produces
text/html
andtext/plain
, and theaccept
header matches one or more of these then this returns the most acceptable match. * @return the most acceptable content type. -
def
getBody(): Option[Buffer]
- returns
Get the entire HTTP request body as a Buffer. The context must have first been routed to a io.vertx.scala.ext.web.handler.BodyHandler for this to be populated.
-
def
getBodyAsJson(): Option[JsonObject]
- returns
Get the entire HTTP request body as a JsonObject. The context must have first been routed to a io.vertx.scala.ext.web.handler.BodyHandler for this to be populated.
-
def
getBodyAsJsonArray(): Option[JsonArray]
- returns
Get the entire HTTP request body as a JsonArray. The context must have first been routed to a io.vertx.scala.ext.web.handler.BodyHandler for this to be populated.
-
def
getBodyAsString(encoding: String): Option[String]
Get the entire HTTP request body as a string, assuming the specified encoding.
Get the entire HTTP request body as a string, assuming the specified encoding. The context must have first been routed to a io.vertx.scala.ext.web.handler.BodyHandler for this to be populated. * @param encoding the encoding, e.g. "UTF-16"
- returns
the body
-
def
getBodyAsString(): Option[String]
- returns
the entire HTTP request body as a string, assuming UTF-8 encoding. The context must have first been routed to a io.vertx.scala.ext.web.handler.BodyHandler for this to be populated.
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
getCookie(name: String): Option[Cookie]
Get the cookie with the specified name.
Get the cookie with the specified name. The context must have first been routed to a io.vertx.scala.ext.web.handler.CookieHandler for this to work. * @param name the cookie name
- returns
the cookie
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
mountPoint(): Option[String]
- returns
the mount point for this router. It will be null for a top level router. For a sub-router it will be the path at which the subrouter was mounted.
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
next(): Unit
Tell the router to route this context to the next matching route (if any).
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.
-
def
normalisedPath(): String
Return the normalised path for the request.
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. * @return the normalised path
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
parsedHeaders(): ParsedHeaderValues
The headers:
The headers:
- Accept
- Accept-Charset
- Accept-Encoding
- Accept-Language
- Content-Type
Parsed into io.vertx.scala.ext.web.ParsedHeaderValue * @return A container with the parsed headers.
-
def
pathParam(name: String): Option[String]
Gets the value of a single path parameter * @param name the name of parameter as defined in path declaration
Gets the value of a single path parameter * @param name the name of parameter as defined in path declaration
- returns
the actual value of the parameter or null if it doesn't exist
-
def
pathParams(): Map[String, String]
Returns a map of named parameters as defined in path declaration with their actual values * @return the map of named parameters
-
def
preferredLanguage(): LanguageHeader
Helper to return the user preferred language.
Helper to return the user preferred language. It is the same action as returning the first element of the acceptable languages. * @return the users preferred locale.
-
def
preferredLocale(): Locale
Helper to return the user preferred locale.
Helper to return the user preferred locale. It is the same action as returning the first element of the acceptable locales. * @return the users preferred locale.
-
def
put(key: String, obj: AnyRef): RoutingContext
Put some arbitrary data in the context.
Put some arbitrary data in the context. This will be available in any handlers that receive the context. * @param key the key for the data
- obj
the data
- returns
a reference to this, so the API can be used fluently
-
def
queryParam(query: String): Option[Buffer[String]]
Gets the value of a single query parameter * @param query The name of query parameter
Gets the value of a single query parameter * @param query The name of query parameter
- returns
The list of all elements inside query parameter
-
def
queryParams(): MultiMap
Returns a map of all query parameters inside the query string * @return the multimap of query parameters
-
def
remove[T](key: String)(implicit arg0: scala.reflect.api.JavaUniverse.TypeTag[T]): T
Remove some data from the context.
Remove some data from the context. The data is available in any handlers that receive the context. * @param key the key for the data
- returns
the previous data associated with the key
-
def
removeBodyEndHandler(handlerID: Int): Boolean
Remove a body end handler * @param handlerID the id as returned from io.vertx.scala.ext.web.RoutingContext#addBodyEndHandler(Handler).
Remove a body end handler * @param handlerID the id as returned from io.vertx.scala.ext.web.RoutingContext#addBodyEndHandler(Handler).
- returns
true if the handler existed and was removed, false otherwise
-
def
removeCookie(name: String, invalidate: Boolean): Option[Cookie]
Remove a cookie from the cookie set.
Remove a cookie from the cookie set. If invalidate is true then it will expire a cookie, notifying a User Agent to remove it from its cookie jar. The context must have first been routed to a io.vertx.scala.ext.web.handler.CookieHandler for this to work. * @param name the name of the cookie
- returns
the cookie, if it existed, or null
-
def
removeCookie(name: String): Option[Cookie]
Expire a cookie, notifying a User Agent to remove it from its cookie jar.
Expire a cookie, notifying a User Agent to remove it from its cookie jar. The context must have first been routed to a io.vertx.scala.ext.web.handler.CookieHandler for this to work. * @param name the name of the cookie
- returns
the cookie, if it existed, or null
-
def
removeHeadersEndHandler(handlerID: Int): Boolean
Remove a headers end handler * @param handlerID the id as returned from io.vertx.scala.ext.web.RoutingContext#addHeadersEndHandler(Handler).
Remove a headers end handler * @param handlerID the id as returned from io.vertx.scala.ext.web.RoutingContext#addHeadersEndHandler(Handler).
- returns
true if the handler existed and was removed, false otherwise
-
def
request(): HttpServerRequest
- returns
the HTTP request object
-
def
reroute(method: HttpMethod, path: String): Unit
Restarts the current router with a new method and path.
Restarts the current router with a new method and path. All path parameters are then parsed and available on the params list. * @param method the new http request
- path
the new http path.
-
def
reroute(path: String): Unit
Restarts the current router with a new path and reusing the original method.
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. * @param path the new http path.
-
def
response(): HttpServerResponse
- returns
the HTTP response object
-
def
session(): Option[Session]
Get the session.
Get the session. The context must have first been routed to a io.vertx.scala.ext.web.handler.SessionHandler for this to be populated. Sessions live for a browser session, and are maintained by session cookies. * @return the session.
-
def
setAcceptableContentType(contentType: Option[String]): Unit
Set the acceptable content type.
Set the acceptable content type. Used by * @param contentType the content type
-
def
setBody(body: Buffer): Unit
Set the body.
Set the body. Used by the io.vertx.scala.ext.web.handler.BodyHandler. You will not normally call this method. * @param body the body
-
def
setSession(session: Session): Unit
Set the session.
Set the session. Used by the io.vertx.scala.ext.web.handler.SessionHandler. You will not normally call this method. * @param session the session
-
def
setUser(user: User): Unit
Set the user.
Set the user. Usually used by auth handlers to inject a User. You will not normally call this method. * @param user the user
-
def
statusCode(): Int
If the context is being routed to failure handlers after a failure has been triggered by calling io.vertx.scala.ext.web.RoutingContext#fail then this will return that status code.
If the context is being routed to failure handlers after a failure has been triggered by calling io.vertx.scala.ext.web.RoutingContext#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. * @return the status code used when signalling failure
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
user(): Option[User]
Get the authenticated user (if any).
Get the authenticated user (if any). This will usually be injected by an auth handler if authentication if successful. * @return the user, or null if the current user is not authenticated.
-
def
vertx(): Vertx
- returns
the Vert.x instance associated to the initiating Router for this context
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )