vertx-lang-scala-docs_2.12 3.9.1 API < Back
 

# Packages

-  package root
  Definition Classes
    root
-  package io
  Definition Classes
    root
-  package vertx
  Definition Classes
    io
-  package scala
  Definition Classes
    vertx
-  package ext
  Definition Classes
    scala
-  package web
  Definition Classes
    ext
-  package client
  Definition Classes
    web
-  package codec
  Definition Classes
    web
-  package common
  Definition Classes
    web
-  package handler
  Definition Classes
    web
-  package multipart
  Definition Classes
    web
-  package sstore
  Definition Classes
    web
-  package templ
  Definition Classes
    web
- FileUpload
- Http2PushMapping
- LanguageHeader
- Locale
- MIMEHeader
- ParsedHeaderValue
- ParsedHeaderValues
- Route
- Router
- RoutingContext
- Session

c

io.vertx.scala.ext.web

# RoutingContext 

###
Companion object RoutingContext

#### 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 io.vertx.scala.core.Handler#handle 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.

If you use the internal error handler

Linear Supertypes
AnyRef, Any
 
Ordering

1. Alphabetic
2. By Inheritance

Inherited

1. RoutingContext
2. AnyRef
3. Any

1. Hide All
2. Show All

Visibility

1. Public
2. All

### Instance Constructors

1.  new RoutingContext(_asJava: AnyRef)

### Value Members

1.  final def !=(arg0: Any): Boolean
   Definition Classes
     AnyRef → Any
2.  final def ##(): Int
   Definition Classes
     AnyRef → Any
3.  final def ==(arg0: Any): Boolean
   Definition Classes
     AnyRef → Any
4.  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

5.  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

6.  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.

7.  def addCookie(cookie: Cookie): RoutingContext

   Add a cookie.

   Add a cookie. This will be sent back to the client in the response. * @param cookie the cookie

   returns

     a reference to this, so the API can be used fluently

8.  def addEndFuture(): Future[Unit]

   Like addEndHandler but returns a scala.concurrent.Future instead of taking an AsyncResultHandler.

9.  def addEndHandler(handler: Handler[AsyncResult[Unit]]): Int

   Add an end handler for the request/response context.

   Add an end handler for the request/response context. This will be called when the response is disposed or an exception has been encountered to allow consistent cleanup. The handler is called asynchronously of when the response has been received by the client. * @param handler the handler that will be called with either a success or failure result.

   returns

     the id of the handler. This can be used if you later want to remove the handler.

10.  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.

11.  final def asInstanceOf[T0]: T0
    Definition Classes
      Any
12.  def asJava: AnyRef
13.  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.

14.  def clone(): AnyRef
    Attributes
      protected[java.lang]
    Definition Classes
      AnyRef
    Annotations
      @native() @throws( ... )
15.  def cookieCount(): Int

    returns

      the number of cookies.

16.  def cookies(): Set[Cookie]

    returns

      a set of all the cookies.

17.  def currentRoute(): Route

    returns

      the current route this context is being routed through.

18.  final def eq(arg0: AnyRef): Boolean
    Definition Classes
      AnyRef
19.  def equals(arg0: Any): Boolean
    Definition Classes
      AnyRef → Any
20.  def fail(statusCode: Int, throwable: Throwable): Unit

    Fail the context with the specified throwable and the specified the status code.

    Fail the context with the specified throwable and the specified the status code.

    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 io.vertx.scala.ext.web.Router#errorHandler. If no error handler is not defined, It will send a default failure response with provided status code. * @param statusCode the HTTP status code

    throwable

      a throwable representing the failure

21.  def fail(throwable: Throwable): Unit

    Fail the context with the specified throwable and 500 status code.

    Fail the context with the specified throwable and 500 status code.

    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 io.vertx.scala.ext.web.Router#errorHandler. If no error handler is not defined, It will send a default failure response with 500 status code. * @param throwable a throwable representing the failure

22.  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 It will trigger the error handler matching the status code. You can define such error handler with io.vertx.scala.ext.web.Router#errorHandler. If no error handler is not defined, It will send a default failure response with provided status code. * @param statusCode the HTTP status code

23.  def failed(): Boolean

    returns

      true if the context is being routed to failure handlers.

24.  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

25.  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.

26.  def finalize(): Unit
    Attributes
      protected[java.lang]
    Definition Classes
      AnyRef
    Annotations
      @throws( classOf[java.lang.Throwable] )
27.  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

28.  def getAcceptableContentType(): Option[String]

    If the route specifies produces matches, e.g.

    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. * @return the most acceptable content type.

29.  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.

30.  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.
      When the body is `null` or the `"null"` JSON literal then `null` is returned.

31.  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.
      When the body is `null` or the `"null"` JSON literal then `null` is returned.

32.  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

33.  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.

34.  final def getClass(): Class[_]
    Definition Classes
      AnyRef → Any
    Annotations
      @native()
35.  def getCookie(name: String): Option[Cookie]

    Get the cookie with the specified name.

    Get the cookie with the specified name. * @param name the cookie name

    returns

      the cookie

36.  def hashCode(): Int
    Definition Classes
      AnyRef → Any
    Annotations
      @native()
37.  final def isInstanceOf[T0]: Boolean
    Definition Classes
      Any
38.  def isSessionAccessed(): Boolean

    Whether the io.vertx.scala.ext.web.RoutingContext#session has been already called or not.

    Whether the io.vertx.scala.ext.web.RoutingContext#session has been already called or not. This is usually used by the io.vertx.scala.ext.web.handler.SessionHandler. * @return true if the session has been accessed.

39.  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.

40.  final def ne(arg0: AnyRef): Boolean
    Definition Classes
      AnyRef
41.  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.

42.  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

43.  final def notify(): Unit
    Definition Classes
      AnyRef
    Annotations
      @native()
44.  final def notifyAll(): Unit
    Definition Classes
      AnyRef
    Annotations
      @native()
45.  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.

46.  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

47.  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

48.  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.

49.  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.

50.  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

51.  def queryParam(name: String): Buffer[String]

    Gets the value of a single query parameter.

    Gets the value of a single query parameter. For more info io.vertx.scala.ext.web.RoutingContext#queryParams * @param name The name of query parameter

    returns

      The list of all parameters matching the parameter name. It returns an empty list if no query parameter with `name` was found

52.  def queryParams(): MultiMap

    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.

    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. If the query string is invalid it fails the context * @return the multimap of query parameters

53.  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

54.  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

55.  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. * @param name the name of the cookie

    returns

      the cookie, if it existed, or null

56.  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. * @param name the name of the cookie

    returns

      the cookie, if it existed, or null

57.  def removeEndHandler(handlerID: Int): Boolean

    Remove an end handler * @param handlerID the id as returned from io.vertx.scala.ext.web.RoutingContext#addEndHandler(Handler).

    Remove an end handler * @param handlerID the id as returned from io.vertx.scala.ext.web.RoutingContext#addEndHandler(Handler).

    returns

      true if the handler existed and was removed, false otherwise

58.  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

59.  def request(): HttpServerRequest

    returns

      the HTTP request object

60.  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. Query params will also be allowed and available. * @param method the new http request

    path

      the new http path.

61.  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. Query params will also be allowed and available. * @param path the new http path.

62.  def response(): HttpServerResponse

    returns

      the HTTP response object

63.  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.

64.  def setAcceptableContentType(contentType: Option[String]): Unit

    Set the acceptable content type.

    Set the acceptable content type. Used by * @param contentType the content type

65.  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

66.  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

67.  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

68.  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

69.  final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
      AnyRef
70.  def toString(): String
    Definition Classes
      AnyRef → Any
71.  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.

72.  def vertx(): Vertx

    returns

      the Vert.x instance associated to the initiating Router for this context

73.  final def wait(): Unit
    Definition Classes
      AnyRef
    Annotations
      @throws( ... )
74.  final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
      AnyRef
    Annotations
      @throws( ... )
75.  final def wait(arg0: Long): Unit
    Definition Classes
      AnyRef
    Annotations
      @native() @throws( ... )

### Inherited from AnyRef

### Inherited from Any

### Ungrouped