Class RoutingContext

java.lang.Object
io.vertx.mutiny.ext.web.RoutingContext
All Implemented Interfaces:
MutinyDelegate

public class RoutingContext extends Object implements MutinyDelegate
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 Handler 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.

If you use the internal error handler

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

  • Field Details

  • Constructor Details

    • RoutingContext

      public RoutingContext(io.vertx.ext.web.RoutingContext delegate)
    • RoutingContext

      public RoutingContext(Object delegate)
  • Method Details

    • getDelegate

      public io.vertx.ext.web.RoutingContext getDelegate()
      Specified by:
      getDelegate in interface MutinyDelegate
      Returns:
      the delegate used by this Mutiny object of generated type
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • request

      public HttpServerRequest request()
      Returns:
      the HTTP request object
    • response

      public HttpServerResponse response()
      Returns:
      the HTTP response object
    • next

      public void next()
    • fail

      public void fail(int statusCode)
      Parameters:
      statusCode - the HTTP status code
    • fail

      public void fail(Throwable throwable)
      Parameters:
      throwable - a throwable representing the failure
    • fail

      public void fail(int statusCode, Throwable throwable)
      Parameters:
      statusCode - the HTTP status code
      throwable - a throwable representing the failure
    • put

      public RoutingContext put(String key, Object obj)
      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)
      Parameters:
      key - the key for the data
      Returns:
      the data
    • get

      public <T> T get(String key, T defaultValue)
      Parameters:
      key - the key for the data
      defaultValue - when the underlying data doesn't contain the key this will be the return value.
      Returns:
      the data
    • remove

      public <T> T remove(String key)
      Parameters:
      key - the key for the data
      Returns:
      the previous data associated with the key
    • 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

      @Deprecated public String normalisedPath()
      Deprecated.
      Returns:
    • normalizedPath

      public String normalizedPath()
      Returns:
      normalized path
    • getCookie

      @Deprecated public Cookie getCookie(String name)
      Deprecated.
      Use HttpServerRequest#getCookie(String) Get the cookie with the specified name.
      Parameters:
      name - the cookie name
      Returns:
      the cookie
    • addCookie

      @Deprecated public RoutingContext addCookie(Cookie cookie)
      Deprecated.
      Use HttpServerResponse#addCookie(Cookie) Add a cookie. This will be sent back to the client in the response.
      Parameters:
      cookie - the cookie
      Returns:
      a reference to this, so the API can be used fluently
    • removeCookie

      @Deprecated public Cookie removeCookie(String name)
      Deprecated.
      Use HttpServerResponse#removeCookie(String) Expire a cookie, notifying a User Agent to remove it from its cookie jar.
      Parameters:
      name - the name of the cookie
      Returns:
      the cookie, if it existed, or null
    • removeCookie

      @Deprecated public Cookie removeCookie(String name, boolean invalidate)
      Deprecated.
      Use HttpServerResponse#removeCookie(String, boolean) 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.
      Parameters:
      name - the name of the cookie
      invalidate -
      Returns:
      the cookie, if it existed, or null
    • cookieCount

      @Deprecated public int cookieCount()
      Deprecated.
      Use HttpServerRequest#cookieCount()
      Returns:
      the number of cookies.
    • cookieMap

      @Deprecated public Map<String,Cookie> cookieMap()
      Deprecated.
      Use HttpServerRequest#cookieMap()
      Returns:
      a map of all the cookies.
    • getBodyAsString

      @Deprecated public String getBodyAsString()
      Deprecated.
      Use body() instead.
      Returns:
      the entire HTTP request body as a string, assuming UTF-8 encoding if the request does not provide the content type charset attribute. If a charset is provided in the request that it shall be respected. The context must have first been routed to a BodyHandler for this to be populated.
    • getBodyAsString

      @Deprecated public String getBodyAsString(String encoding)
      Deprecated.
      Use body() instead. 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

      @Deprecated public io.vertx.core.json.JsonObject getBodyAsJson(int maxAllowedLength)
      Deprecated.
      Use body() instead. Gets the current body buffer as a JsonObject. If a positive limit is provided the parsing will only happen if the buffer length is smaller or equal to the limit. Otherwise an IllegalStateException is thrown. When the application is only handling uploads in JSON format, it is recommended to set a limit on BodyHandler.setBodyLimit(long) as this will avoid the upload to be parsed and loaded into the application memory.
      Parameters:
      maxAllowedLength - if the current buffer length is greater than the limit an IllegalStateException is thrown. This can be used to avoid DDoS attacks on very long JSON payloads that could take over the CPU while attempting to parse the data.
      Returns:
      Get the entire HTTP request body as a . The context must have first been routed to a BodyHandler for this to be populated.
      When the body is null or the "null" JSON literal then null is returned.
    • getBodyAsJsonArray

      @Deprecated public io.vertx.core.json.JsonArray getBodyAsJsonArray(int maxAllowedLength)
      Deprecated.
      Use body() instead. Gets the current body buffer as a JsonArray. If a positive limit is provided the parsing will only happen if the buffer length is smaller or equal to the limit. Otherwise an IllegalStateException is thrown. When the application is only handling uploads in JSON format, it is recommended to set a limit on BodyHandler.setBodyLimit(long) as this will avoid the upload to be parsed and loaded into the application memory.
      Parameters:
      maxAllowedLength - if the current buffer length is greater than the limit an IllegalStateException is thrown. This can be used to avoid DDoS attacks on very long JSON payloads that could take over the CPU while attempting to parse the data.
      Returns:
      Get the entire HTTP request body as a . The context must have first been routed to a BodyHandler for this to be populated.
      When the body is null or the "null" JSON literal then null is returned.
    • getBodyAsJson

      @Deprecated public io.vertx.core.json.JsonObject getBodyAsJson()
      Deprecated.
      Use body() instead.
      Returns:
      Get the entire HTTP request body as a . The context must have first been routed to a BodyHandler for this to be populated.
      When the body is null or the "null" JSON literal then null is returned.
    • getBodyAsJsonArray

      @Deprecated public io.vertx.core.json.JsonArray getBodyAsJsonArray()
      Deprecated.
      Use body() instead.
      Returns:
      Get the entire HTTP request body as a . The context must have first been routed to a BodyHandler for this to be populated.
      When the body is null or the "null" JSON literal then null is returned.
    • getBody

      @Deprecated public Buffer getBody()
      Deprecated.
      Use body() instead.
      Returns:
      Get the entire HTTP request body as a . The context must have first been routed to a BodyHandler for this to be populated.
    • body

      public RequestBody body()
    • fileUploads

      public List<FileUpload> fileUploads()
      Returns:
      a list of FileUpload (if any) for the request. The context must have first been routed to a BodyHandler for this to work.
    • cancelAndCleanupFileUploads

      public void cancelAndCleanupFileUploads()
    • session

      public Session session()
      Returns:
      the session.
    • isSessionAccessed

      public boolean isSessionAccessed()
      Returns:
      true if the session has been accessed.
    • user

      public User user()
      Returns:
      the user, or null if the current user is not authenticated.
    • userContext

      public UserContext userContext()
      Returns:
      the user context
    • failure

      public Throwable failure()
      Returns:
      the throwable used when signalling failure
    • statusCode

      public int statusCode()
      Returns:
      the status code used when signalling failure
    • getAcceptableContentType

      public String getAcceptableContentType()
      Returns:
      the most acceptable content type.
    • parsedHeaders

      public ParsedHeaderValues parsedHeaders()
      Returns:
      A container with the parsed headers.
    • addHeadersEndHandler

      public int addHeadersEndHandler(Runnable handler)
      Parameters:
      handler - the handler
      Returns:
    • removeHeadersEndHandler

      public boolean removeHeadersEndHandler(int handlerID)
      Parameters:
      handlerID - the id as returned from addHeadersEndHandler(java.lang.Runnable).
      Returns:
      true if the handler existed and was removed, false otherwise
    • addBodyEndHandler

      public int addBodyEndHandler(Runnable handler)
      Parameters:
      handler - the handler
      Returns:
    • removeBodyEndHandler

      public boolean removeBodyEndHandler(int handlerID)
      Parameters:
      handlerID - the id as returned from addBodyEndHandler(java.lang.Runnable).
      Returns:
      true if the handler existed and was removed, false otherwise
    • addEndHandler

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> addEndHandler()
      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.

      Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

      Returns:
      the uni firing the result of the operation when completed, or a failure if the operation failed.
    • addEndHandlerAndAwait

      public Void addEndHandlerAndAwait()
      Blocking variant of addEndHandler().

      This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Returns:
      the Void instance produced by the operation.
    • addEndHandlerAndForget

      public void addEndHandlerAndForget()
      Variant of addEndHandler() that ignores the result of the operation.

      This method subscribes on the result of addEndHandler(), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from addEndHandler() but you don't need to compose it with other operations.

    • removeEndHandler

      public boolean removeEndHandler(int handlerID)
      Parameters:
      handlerID - the id as returned from addEndHandler().
      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

      @Deprecated public void setBody(Buffer body)
      Deprecated.
      This method is internal. Users that really need to use it should refer to RoutingContextInternal.setBody(Buffer) Set the body. Used by the BodyHandler. You will not normally call this method.
      Parameters:
      body - the body
    • setSession

      @Deprecated public void setSession(Session session)
      Deprecated.
      This method is internal. Users that really need to use it should refer to io.vertx.ext.web.impl.RoutingContextInternal#setSession(Session) Set the session. Used by the SessionHandler. You will not normally call this method.
      Parameters:
      session - the session
    • setUser

      @Deprecated public void setUser(User user)
      Deprecated.
      this method should not be called, application authentication should rely on AuthenticationHandler implementations.
      Parameters:
      user - the user
    • clearUser

      @Deprecated public void clearUser()
      Deprecated.
    • setAcceptableContentType

      public void setAcceptableContentType(String contentType)
      Parameters:
      contentType - the content type
    • reroute

      public void reroute(String path)
      Parameters:
      path - the new http path.
    • reroute

      public void reroute(io.vertx.core.http.HttpMethod method, String path)
      Parameters:
      method - the new http request
      path - the new http path.
    • acceptableLanguages

      public List<LanguageHeader> acceptableLanguages()
      Returns:
      The best matched language for the request
    • preferredLanguage

      public LanguageHeader preferredLanguage()
      Returns:
      the users preferred locale.
    • pathParams

      public Map<String,String> pathParams()
      Returns:
      the map of named parameters
    • pathParam

      public String pathParam(String name)
      Parameters:
      name - the name of parameter as defined in path declaration
      Returns:
      the actual value of the parameter or null if it doesn't exist
    • queryParams

      public MultiMap queryParams()
      Returns:
      the multimap of query parameters
    • queryParam

      public List<String> queryParam(String name)
      Parameters:
      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
    • attachment

      public RoutingContext attachment(String filename)
      Parameters:
      filename - the filename for the attachment
      Returns:
      the instance of RoutingContext to chain method calls.
    • redirect

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> redirect(String url)
      See redirect(java.lang.String).

      Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

      Parameters:
      url -
      Returns:
      the uni firing the result of the operation when completed, or a failure if the operation failed.
    • redirectAndAwait

      public Void redirectAndAwait(String url)
      Blocking variant of redirect(String).

      This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Parameters:
      url -
      Returns:
      the Void instance produced by the operation.
    • redirectAndForget

      public RoutingContext redirectAndForget(String url)
      Variant of redirect(String) that ignores the result of the operation.

      This method subscribes on the result of redirect(String), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from redirect(String) but you don't need to compose it with other operations.

      Parameters:
      url -
      Returns:
      the instance of RoutingContext to chain method calls.
    • json

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> json(Object json)
      See json(java.lang.Object).

      Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

      Parameters:
      json -
      Returns:
      the uni firing the result of the operation when completed, or a failure if the operation failed.
    • jsonAndAwait

      public Void jsonAndAwait(Object json)
      Blocking variant of json(Object).

      This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Parameters:
      json -
      Returns:
      the Void instance produced by the operation.
    • jsonAndForget

      public RoutingContext jsonAndForget(Object json)
      Variant of json(Object) that ignores the result of the operation.

      This method subscribes on the result of json(Object), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from json(Object) but you don't need to compose it with other operations.

      Parameters:
      json -
      Returns:
      the instance of RoutingContext to chain method calls.
    • is

      public boolean is(String type)
      Parameters:
      type - content type
      Returns:
      The most close value
    • isFresh

      public boolean isFresh()
      Returns:
      true if content is fresh according to the cache.
    • etag

      public RoutingContext etag(String etag)
      Parameters:
      etag - the etag value
      Returns:
      the instance of RoutingContext to chain method calls.
    • lastModified

      public RoutingContext lastModified(String instant)
      Parameters:
      instant - the last modified instant
      Returns:
      the instance of RoutingContext to chain method calls.
    • end

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> end(String chunk)
      See end(java.lang.String)

      Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

      Parameters:
      chunk -
      Returns:
      the uni firing the result of the operation when completed, or a failure if the operation failed.
    • endAndAwait

      public Void endAndAwait(String chunk)
      Blocking variant of end(String).

      This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Parameters:
      chunk -
      Returns:
      the Void instance produced by the operation.
    • endAndForget

      public RoutingContext endAndForget(String chunk)
      Variant of end(String) that ignores the result of the operation.

      This method subscribes on the result of end(String), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from end(String) but you don't need to compose it with other operations.

      Parameters:
      chunk -
      Returns:
      the instance of RoutingContext to chain method calls.
    • end

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> end(Buffer buffer)
      See end(java.lang.String)

      Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

      Parameters:
      buffer -
      Returns:
      the uni firing the result of the operation when completed, or a failure if the operation failed.
    • endAndAwait

      public Void endAndAwait(Buffer buffer)
      Blocking variant of end(io.vertx.mutiny.core.buffer.Buffer).

      This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Parameters:
      buffer -
      Returns:
      the Void instance produced by the operation.
    • endAndForget

      public RoutingContext endAndForget(Buffer buffer)
      Variant of end(io.vertx.mutiny.core.buffer.Buffer) that ignores the result of the operation.

      This method subscribes on the result of end(io.vertx.mutiny.core.buffer.Buffer), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from end(io.vertx.mutiny.core.buffer.Buffer) but you don't need to compose it with other operations.

      Parameters:
      buffer -
      Returns:
      the instance of RoutingContext to chain method calls.
    • end

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> end()
      See end(java.lang.String)

      Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

      Returns:
      the uni firing the result of the operation when completed, or a failure if the operation failed.
    • endAndAwait

      public Void endAndAwait()
      Blocking variant of end(java.lang.String).

      This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Returns:
      the Void instance produced by the operation.
    • endAndForget

      public RoutingContext endAndForget()
      Variant of end(java.lang.String) that ignores the result of the operation.

      This method subscribes on the result of end(java.lang.String), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from end(java.lang.String) but you don't need to compose it with other operations.

      Returns:
      the instance of RoutingContext to chain method calls.
    • data

      public Map<String,Object> data()
      Returns:
      all the context data as a map
    • queryParams

      public MultiMap queryParams(Charset encoding)
      Parameters:
      encoding - a non null character set.
      Returns:
      the multimap of query parameters
    • lastModified

      public RoutingContext lastModified(Instant instant)
      Parameters:
      instant - the last modified instant
      Returns:
      the instance of RoutingContext to chain method calls.
    • newInstance

      public static RoutingContext newInstance(io.vertx.ext.web.RoutingContext arg)