io.vertx.rxjava.ext.web

## Class RoutingContext

- java.lang.Object
- - io.vertx.rxjava.ext.web.RoutingContext

-     public class RoutingContext
      extends Object

  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 `Router.accept(io.vertx.rxjava.core.http.HttpServerRequest)` 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 `HttpServerRequest` and `HttpServerResponse` 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.

  NOTE: This class has been automatically generated from the `original` non RX-ified interface using Vert.x codegen.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `RoutingContext(RoutingContext delegate)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `addBodyEndHandler(Handler<Void> handler)` Add a handler that will be called just before the response body has been completely written.
    `RoutingContext` | `addCookie(Cookie cookie)` Add a cookie.
    `int` | `addHeadersEndHandler(Handler<Future> 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()`
    `Set<Cookie>` | `cookies()`
    `Route` | `currentRoute()`
    `void` | `fail(int statusCode)` Fail the context with the specified status code.
    `boolean` | `failed()`
    `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()`
    `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.
    `Object` | `getDelegate()`
    `String` | `mountPoint()`
    `static RoutingContext` | `newInstance(RoutingContext arg)`
    `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.
    `RoutingContext` | `put(String key, Object obj)` Put some arbitrary data in the context.
    `boolean` | `removeBodyEndHandler(int handlerID)` Remove a body end handler
    `Cookie` | `removeCookie(String name)` Remove a cookie.
    `boolean` | `removeHeadersEndHandler(int handlerID)` Remove a headers end handler
    `HttpServerRequest` | `request()`
    `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 `fail(int)` then this will return that status code.
    `User` | `user()` Get the authenticated user (if any).
    `Vertx` | `vertx()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### RoutingContext

          public RoutingContext(RoutingContext delegate)

  - ### Method Detail

    - #### getDelegate

          public Object getDelegate()

    - #### request

          public HttpServerRequest request()

      Returns:
        the HTTP request object

    - #### response

          public HttpServerResponse response()

      Returns:
        the HTTP response object

    - #### next

          public 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.

    - #### fail

          public void fail(int 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

    - #### put

          public 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
      Returns:
        a reference to this, so the API can be used fluently

    - #### get

          public <T> T get(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
      Returns:
        the data

    - #### vertx

          public Vertx vertx()

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

    - #### mountPoint

          public String mountPoint()

      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.

    - #### currentRoute

          public Route currentRoute()

      Returns:
        the current route this context is being routed through.

    - #### normalisedPath

          public 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 `HttpServerRequest.path()` if accessing server resources requested by a client.

      Returns:
        the normalised path

    - #### getCookie

          public 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
      Returns:
        the cookie

    - #### addCookie

          public 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
      Returns:
        a reference to this, so the API can be used fluently

    - #### removeCookie

          public Cookie removeCookie(String name)

      Remove a cookie. The context must have first been routed to a `CookieHandler` for this to work.
      Parameters:
        `name` - the name of the cookie
      Returns:
        the cookie, if it existed, or null

    - #### cookieCount

          public int cookieCount()

      Returns:
        the number of cookies. The context must have first been routed to a `CookieHandler` for this to work.

    - #### cookies

          public Set<Cookie> cookies()

      Returns:
        a set of all the cookies. The context must have first been routed to a `CookieHandler` for this to be populated.

    - #### getBodyAsString

          public String getBodyAsString()

      Returns:
        the entire HTTP request body as a string, assuming UTF-8 encoding. The context must have first been routed to a `BodyHandler` for this to be populated.

    - #### getBodyAsString

          public 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"
      Returns:
        the body

    - #### getBodyAsJson

          public JsonObject getBodyAsJson()

      Returns:
        Get the entire HTTP request body as a `JsonObject`. The context must have first been routed to a `BodyHandler` for this to be populated.

    - #### getBody

          public Buffer getBody()

      Returns:
        Get the entire HTTP request body as a `Buffer`. The context must have first been routed to a `BodyHandler` for this to be populated.

    - #### fileUploads

          public Set<FileUpload> fileUploads()

      Returns:
        a set of fileuploads (if any) for the request. The context must have first been routed to a `BodyHandler` for this to work.

    - #### session

          public 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.
      Returns:
        the session.

    - #### user

          public User user()

      Get the authenticated user (if any). This will usually be injected by an auth handler if authentication if successful.
      Returns:
        the user, or null if the current user is not authenticated.

    - #### statusCode

          public int statusCode()

      If the context is being routed to failure handlers after a failure has been triggered by calling `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.
      Returns:
        the status code used when signalling failure

    - #### getAcceptableContentType

          public 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.
      Returns:
        the most acceptable content type.

    - #### addHeadersEndHandler

          public int addHeadersEndHandler(Handler<Future> 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. The handler will be passed a future, when you've completed the work you want to do you should complete (or fail) the future. This can be done after the handler has returned.
      Parameters:
        `handler` - the handler
      Returns:
        the id of the handler. This can be used if you later want to remove the handler.

    - #### removeHeadersEndHandler

          public boolean removeHeadersEndHandler(int handlerID)

      Remove a headers end handler
      Parameters:
        `handlerID` - the id as returned from `RoutingContext`.
      Returns:
        true if the handler existed and was removed, false otherwise

    - #### addBodyEndHandler

          public int addBodyEndHandler(Handler<Void> handler)

      Add a handler that will be called just before the response body has been completely written. This gives you a hook where you can write any extra data to the response before it has ended when it will be too late.
      Parameters:
        `handler` - the handler
      Returns:
        the id of the handler. This can be used if you later want to remove the handler.

    - #### removeBodyEndHandler

          public boolean removeBodyEndHandler(int handlerID)

      Remove a body end handler
      Parameters:
        `handlerID` - the id as returned from `RoutingContext`.
      Returns:
        true if the handler existed and was removed, false otherwise

    - #### failed

          public boolean failed()

      Returns:
        true if the context is being routed to failure handlers.

    - #### setBody

          public void setBody(Buffer body)

      Set the body. Used by the `BodyHandler`. You will not normally call this method.
      Parameters:
        `body` - the body

    - #### setSession

          public void setSession(Session session)

      Set the session. Used by the `SessionHandler`. You will not normally call this method.
      Parameters:
        `session` - the session

    - #### setUser

          public 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

    - #### clearUser

          public 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.

    - #### setAcceptableContentType

          public void setAcceptableContentType(String contentType)

      Set the acceptable content type. Used by
      Parameters:
        `contentType` - the content type

    - #### newInstance

          public static RoutingContext newInstance(RoutingContext arg)

Copyright © 2015. All Rights Reserved.