Module io.jooby
Package io.jooby

Class ForwardingContext

java.lang.Object
io.jooby.ForwardingContext
All Implemented Interfaces:
Context, Registry

public class ForwardingContext extends Object implements Context
Utility class that helps to wrap and delegate to another context.
Since:
2.0.2
Author:
edgar
  • Constructor Details

    • ForwardingContext

      public ForwardingContext(@NonNull Context context)
      Creates a new forwarding context.
      Parameters:
      context - Source context.
  • Method Details

    • getUser

      @Nullable public <T> T getUser()
      Description copied from interface: Context
      Current user or null if none was set.
      Specified by:
      getUser in interface Context
      Type Parameters:
      T - User type.
      Returns:
      Current user or null if none was set.
    • setUser

      @NonNull public Context setUser(@Nullable Object user)
      Description copied from interface: Context
      Set current user.
      Specified by:
      setUser in interface Context
      Parameters:
      user - Current user.
      Returns:
      This context.
    • forward

      @NonNull public Object forward(@NonNull String path)
      Description copied from interface: Context
      Forward executing to another route. We use the given path to find a matching route.

      NOTE: the entire handler pipeline is executed (filter, decorator, etc.).

      Specified by:
      forward in interface Context
      Parameters:
      path - Path to forward the request.
      Returns:
      Forward result.
    • matches

      public boolean matches(@NonNull String pattern)
      Description copied from interface: Context
      Check if the request path matches the given pattern.
      Specified by:
      matches in interface Context
      Parameters:
      pattern - Pattern to use.
      Returns:
      True if request path matches the pattern.
    • isSecure

      public boolean isSecure()
      Description copied from interface: Context
      Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.
      Specified by:
      isSecure in interface Context
      Returns:
      a boolean indicating if the request was made using a secure channel
    • getAttributes

      @NonNull public Map<String,Object> getAttributes()
      Description copied from interface: Context
      Context attributes (a.k.a request attributes).
      Specified by:
      getAttributes in interface Context
      Returns:
      Mutable Context attributes.
    • getAttribute

      @Nullable public <T> T getAttribute(@NonNull String key)
      Description copied from interface: Context
      Get an attribute by his key. This is just an utility method around Context.getAttributes(). This method look first in current context and fallback to application attributes.
      Specified by:
      getAttribute in interface Context
      Type Parameters:
      T - Attribute type.
      Parameters:
      key - Attribute key.
      Returns:
      Attribute value or null.
    • setAttribute

      @NonNull public Context setAttribute(@NonNull String key, Object value)
      Description copied from interface: Context
      Set an application attribute.
      Specified by:
      setAttribute in interface Context
      Parameters:
      key - Attribute key.
      value - Attribute value.
      Returns:
      This router.
    • getRouter

      @NonNull public Router getRouter()
      Description copied from interface: Context
      Get the HTTP router (usually this represents an instance of Jooby.
      Specified by:
      getRouter in interface Context
      Returns:
      HTTP router (usually this represents an instance of Jooby.
    • flash

      @NonNull public FlashMap flash()
      Description copied from interface: Context
      Flash map.
      Specified by:
      flash in interface Context
      Returns:
      Flash map.
    • flash

      @NonNull public Value flash(@NonNull String name)
      Description copied from interface: Context
      Get a flash attribute.
      Specified by:
      flash in interface Context
      Parameters:
      name - Attribute's name.
      Returns:
      Flash attribute.
    • session

      @NonNull public Value session(@NonNull String name)
      Description copied from interface: Context
      Find a session attribute using the given name. If there is no session or attribute under that name a missing value is returned.
      Specified by:
      session in interface Context
      Parameters:
      name - Attribute's name.
      Returns:
      Session's attribute or missing.
    • session

      @NonNull public Session session()
      Description copied from interface: Context
      Find a session or creates a new session.
      Specified by:
      session in interface Context
      Returns:
      Session.
    • sessionOrNull

      @Nullable public Session sessionOrNull()
      Description copied from interface: Context
      Find an existing session.
      Specified by:
      sessionOrNull in interface Context
      Returns:
      Existing session or null.
    • cookie

      @NonNull public Value cookie(@NonNull String name)
      Description copied from interface: Context
      Get a cookie matching the given name.
      Specified by:
      cookie in interface Context
      Parameters:
      name - Cookie's name.
      Returns:
      Cookie value.
    • cookieMap

      @NonNull public Map<String,String> cookieMap()
      Description copied from interface: Context
      Request cookies.
      Specified by:
      cookieMap in interface Context
      Returns:
      Request cookies.
    • getMethod

      @NonNull public String getMethod()
      Description copied from interface: Context
      HTTP method in upper-case form.
      Specified by:
      getMethod in interface Context
      Returns:
      HTTP method in upper-case form.
    • setMethod

      @NonNull public Context setMethod(@NonNull String method)
      Description copied from interface: Context
      Set HTTP method in upper-case form.
      Specified by:
      setMethod in interface Context
      Parameters:
      method - HTTP method in upper-case form.
      Returns:
      This context.
    • getRoute

      @NonNull public Route getRoute()
      Description copied from interface: Context
      Matching route.
      Specified by:
      getRoute in interface Context
      Returns:
      Matching route.
    • setRoute

      @NonNull public Context setRoute(@NonNull Route route)
      Description copied from interface: Context
      Set matching route. This is part of public API, but shouldn't be use by application code.
      Specified by:
      setRoute in interface Context
      Parameters:
      route - Matching route.
      Returns:
      This context.
    • getRequestPath

      @NonNull public String getRequestPath()
      Description copied from interface: Context
      Request path without decoding (a.k.a raw Path) without query string.
      Specified by:
      getRequestPath in interface Context
      Returns:
      Request path without decoding (a.k.a raw Path) without query string.
    • setRequestPath

      @NonNull public Context setRequestPath(@NonNull String path)
      Description copied from interface: Context
      Set request path. This is usually done by Web Server or framework, but by user.
      Specified by:
      setRequestPath in interface Context
      Parameters:
      path - Request path.
      Returns:
      This context.
    • path

      @NonNull public Value path(@NonNull String name)
      Description copied from interface: Context
      Path variable. Value is decoded.
      Specified by:
      path in interface Context
      Parameters:
      name - Path key.
      Returns:
      Associated value or a missing value, but never a null reference.
    • path

      @NonNull public <T> T path(@NonNull Class<T> type)
      Description copied from interface: Context
      Convert the Context.pathMap() to the given type.
      Specified by:
      path in interface Context
      Type Parameters:
      T - Target type.
      Parameters:
      type - Target type.
      Returns:
      Instance of target type.
    • path

      @NonNull public ValueNode path()
      Description copied from interface: Context
      Convert Context.pathMap() to a ValueNode object.
      Specified by:
      path in interface Context
      Returns:
      A value object.
    • pathMap

      @NonNull public Map<String,String> pathMap()
      Description copied from interface: Context
      Path map represent all the path keys with their values.
      
       {
         get("/:id", ctx -> ctx.pathMap());
       }
       
      A call to:
      GET /678
      Produces a path map like: id: 678
      Specified by:
      pathMap in interface Context
      Returns:
      Path map from path pattern.
    • setPathMap

      @NonNull public Context setPathMap(@NonNull Map<String,String> pathMap)
      Description copied from interface: Context
      Set path map. This method is part of public API but shouldn't be use it by application code.
      Specified by:
      setPathMap in interface Context
      Parameters:
      pathMap - Path map.
      Returns:
      This context.
    • query

      @NonNull public QueryString query()
      Description copied from interface: Context
      Query string as ValueNode object.
      Specified by:
      query in interface Context
      Returns:
      Query string as ValueNode object.
    • query

      @NonNull public ValueNode query(@NonNull String name)
      Description copied from interface: Context
      Get a query parameter that matches the given name.
      
       {
         get("/search", ctx -> {
           String q = ctx.query("q").value();
           ...
         });
      
       }
       
      Specified by:
      query in interface Context
      Parameters:
      name - Parameter name.
      Returns:
      A query value.
    • queryString

      @NonNull public String queryString()
      Description copied from interface: Context
      Query string with the leading ? or empty string. This is the raw query string, without decoding it.
      Specified by:
      queryString in interface Context
      Returns:
      Query string with the leading ? or empty string. This is the raw query string, without decoding it.
    • query

      @NonNull public <T> T query(@NonNull Class<T> type)
      Description copied from interface: Context
      Convert the queryString to the given type.
      Specified by:
      query in interface Context
      Type Parameters:
      T - Target type.
      Parameters:
      type - Target type.
      Returns:
      Query string converted to target type.
    • queryMap

      @NonNull public Map<String,String> queryMap()
      Description copied from interface: Context
      Query string as simple map.
      /search?q=jooby&sort=name
      Produces
      {q: jooby, sort: name}
      Specified by:
      queryMap in interface Context
      Returns:
      Query string as map.
    • header

      @NonNull public ValueNode header()
      Description copied from interface: Context
      Request headers as ValueNode.
      Specified by:
      header in interface Context
      Returns:
      Request headers as ValueNode.
    • header

      @NonNull public Value header(@NonNull String name)
      Description copied from interface: Context
      Get a header that matches the given name.
      Specified by:
      header in interface Context
      Parameters:
      name - Header name. Case insensitive.
      Returns:
      A header value or missing value, never a null reference.
    • headerMap

      @NonNull public Map<String,String> headerMap()
      Description copied from interface: Context
      Header as single-value map.
      Specified by:
      headerMap in interface Context
      Returns:
      Header as single-value map.
    • accept

      public boolean accept(@NonNull MediaType contentType)
      Description copied from interface: Context
      True if the given type matches the `Accept` header. This method returns true if there is no accept header.
      Specified by:
      accept in interface Context
      Parameters:
      contentType - Content type to match.
      Returns:
      True for matching type or if content header is absent.
    • accept

      @Nullable public MediaType accept(@NonNull List<MediaType> produceTypes)
      Description copied from interface: Context
      Check if the accept type list matches the given produces list and return the most specific media type from produces list.
      Specified by:
      accept in interface Context
      Parameters:
      produceTypes - Produced types.
      Returns:
      The most specific produces type.
    • getRequestType

      @Nullable public MediaType getRequestType()
      Description copied from interface: Context
      Request Content-Type header or null when missing.
      Specified by:
      getRequestType in interface Context
      Returns:
      Request Content-Type header or null when missing.
    • getRequestType

      @NonNull public MediaType getRequestType(MediaType defaults)
      Description copied from interface: Context
      Request Content-Type header or null when missing.
      Specified by:
      getRequestType in interface Context
      Parameters:
      defaults - Default content type to use when the header is missing.
      Returns:
      Request Content-Type header or null when missing.
    • getRequestLength

      public long getRequestLength()
      Description copied from interface: Context
      Request Content-Length header or -1 when missing.
      Specified by:
      getRequestLength in interface Context
      Returns:
      Request Content-Length header or -1 when missing.
    • getRemoteAddress

      @NonNull public String getRemoteAddress()
      Description copied from interface: Context
      The IP address of the client or last proxy that sent the request.

      If you run behind a reverse proxy that has been configured to send the X-Forwarded-* header, please consider to set Router.setTrustProxy(boolean) option.

      Specified by:
      getRemoteAddress in interface Context
      Returns:
      The IP address of the client or last proxy that sent the request or empty string for interrupted requests.
    • setRemoteAddress

      @NonNull public Context setRemoteAddress(@NonNull String remoteAddress)
      Description copied from interface: Context
      Set IP address of client or last proxy that sent the request.
      Specified by:
      setRemoteAddress in interface Context
      Parameters:
      remoteAddress - Remote Address.
      Returns:
      This context.
    • getHost

      @NonNull public String getHost()
      Description copied from interface: Context
      Return the host that this request was sent to, in general this will be the value of the Host header, minus the port specifier. Unless, it is set manually using the Context.setHost(String) method.

      If you run behind a reverse proxy that has been configured to send the X-Forwarded-* header, please consider to set Router.setTrustProxy(boolean) option.

      Specified by:
      getHost in interface Context
      Returns:
      Return the host that this request was sent to, in general this will be the value of the Host header, minus the port specifier.
    • setHost

      @NonNull public Context setHost(@NonNull String host)
      Description copied from interface: Context
      Set the host (without the port value).

      Please keep in mind this method doesn't alter/modify the host header.

      Specified by:
      setHost in interface Context
      Parameters:
      host - Host value.
      Returns:
      This context.
    • getServerPort

      public int getServerPort()
      Description copied from interface: Context
      Server port for current request.
      Specified by:
      getServerPort in interface Context
      Returns:
      Server port for current request.
    • getServerHost

      @NonNull public String getServerHost()
      Description copied from interface: Context
      Server host.
      Specified by:
      getServerHost in interface Context
      Returns:
      Server host.
    • getPort

      public int getPort()
      Description copied from interface: Context
      Return the port that this request was sent to. In general this will be the value of the Host header, minus the host name.

      If no host header is present, this method returns the value of Context.getServerPort().

      Specified by:
      getPort in interface Context
      Returns:
      Return the port that this request was sent to. In general this will be the value of the Host header, minus the host name.
    • setPort

      @NonNull public Context setPort(int port)
      Description copied from interface: Context
      Set port this request was sent to.
      Specified by:
      setPort in interface Context
      Parameters:
      port - Port.
      Returns:
      This context.
    • getHostAndPort

      @NonNull public String getHostAndPort()
      Description copied from interface: Context
      Return the host and port that this request was sent to, in general this will be the value of the Host.

      If you run behind a reverse proxy that has been configured to send the X-Forwarded-* header, please consider to set Router.setTrustProxy(boolean) option.

      Specified by:
      getHostAndPort in interface Context
      Returns:
      Return the host that this request was sent to, in general this will be the value of the Host header.
    • getRequestURL

      @NonNull public String getRequestURL()
      Description copied from interface: Context
      Recreates full/entire url of the current request using the Host header.

      If you run behind a reverse proxy that has been configured to send the X-Forwarded-* header, please consider to set Router.setTrustProxy(boolean) option.

      Specified by:
      getRequestURL in interface Context
      Returns:
      Full/entire request url using the Host header.
    • getRequestURL

      @NonNull public String getRequestURL(@NonNull String path)
      Description copied from interface: Context
      Recreates full/entire request url using the Host header with a custom path/suffix.

      If you run behind a reverse proxy that has been configured to send the X-Forwarded-* header, please consider to set Router.setTrustProxy(boolean) option.

      Specified by:
      getRequestURL in interface Context
      Parameters:
      path - Path or suffix to use, can also include query string parameters.
      Returns:
      Full/entire request url using the Host header.
    • getProtocol

      @NonNull public String getProtocol()
      Description copied from interface: Context
      The name of the protocol the request. Always in lower-case.
      Specified by:
      getProtocol in interface Context
      Returns:
      The name of the protocol the request. Always in lower-case.
    • getClientCertificates

      @NonNull public List<Certificate> getClientCertificates()
      Description copied from interface: Context
      The certificates presented by the client for mutual TLS. Empty if ssl is not enabled, or client authentication is not required.
      Specified by:
      getClientCertificates in interface Context
      Returns:
      The certificates presented by the client for mutual TLS. Empty if ssl is not enabled, or client authentication is not required.
    • getScheme

      @NonNull public String getScheme()
      Description copied from interface: Context
      HTTP scheme in lower case.
      Specified by:
      getScheme in interface Context
      Returns:
      HTTP scheme in lower case.
    • setScheme

      @NonNull public Context setScheme(@NonNull String scheme)
      Description copied from interface: Context
      Set HTTP scheme in lower case.
      Specified by:
      setScheme in interface Context
      Parameters:
      scheme - HTTP scheme in lower case.
      Returns:
      This context.
    • form

      @NonNull public Formdata form()
      Description copied from interface: Context
      Get form data.

      Only for application/x-www-form-urlencoded or multipart/form-data request.

      Specified by:
      form in interface Context
      Returns:
      Multipart value.
    • form

      @NonNull public ValueNode form(@NonNull String name)
      Description copied from interface: Context
      Get a form field that matches the given name.

      File upload retrieval is available using Context.file(String).

      Only for multipart/form-data request.

      Specified by:
      form in interface Context
      Parameters:
      name - Field name.
      Returns:
      Multipart value.
    • form

      @NonNull public <T> T form(@NonNull Class<T> type)
      Description copied from interface: Context
      Convert form data to the given type.

      Only for application/x-www-form-urlencoded or multipart/form-data request.

      Specified by:
      form in interface Context
      Type Parameters:
      T - Target type.
      Parameters:
      type - Target type.
      Returns:
      Target value.
    • formMap

      @NonNull public Map<String,String> formMap()
      Description copied from interface: Context
      Form data as single-value map.

      Only for application/x-www-form-urlencoded or multipart/form-data request.

      Specified by:
      formMap in interface Context
      Returns:
      Single-value map.
    • files

      @NonNull public List<FileUpload> files()
      Description copied from interface: Context
      All file uploads. Only for multipart/form-data request.
      Specified by:
      files in interface Context
      Returns:
      All file uploads.
    • files

      @NonNull public List<FileUpload> files(@NonNull String name)
      Description copied from interface: Context
      All file uploads that matches the given field name.

      Only for multipart/form-data request.

      Specified by:
      files in interface Context
      Parameters:
      name - Field name. Please note this is the form field name, not the actual file name.
      Returns:
      All file uploads.
    • file

      @NonNull public FileUpload file(@NonNull String name)
      Description copied from interface: Context
      A file upload that matches the given field name.

      Only for multipart/form-data request.

      Specified by:
      file in interface Context
      Parameters:
      name - Field name. Please note this is the form field name, not the actual file name.
      Returns:
      A file upload.
    • body

      @NonNull public Body body()
      Description copied from interface: Context
      HTTP body which provides access to body content.
      Specified by:
      body in interface Context
      Returns:
      HTTP body which provides access to body content.
    • body

      @NonNull public <T> T body(@NonNull Class<T> type)
      Description copied from interface: Context
      Convert the HTTP body to the given type.
      Specified by:
      body in interface Context
      Type Parameters:
      T - Conversion type.
      Parameters:
      type - Reified type.
      Returns:
      Instance of conversion type.
    • body

      @NonNull public <T> T body(@NonNull Type type)
      Description copied from interface: Context
      Convert the HTTP body to the given type.
      Specified by:
      body in interface Context
      Type Parameters:
      T - Conversion type.
      Parameters:
      type - Reified type.
      Returns:
      Instance of conversion type.
    • convert

      @NonNull public <T> T convert(@NonNull ValueNode value, @NonNull Class<T> type)
      Description copied from interface: Context
      Converts a value (single or hash) into the given type.
      Specified by:
      convert in interface Context
      Type Parameters:
      T - Generic type.
      Parameters:
      value - Value to convert.
      type - Expected type.
      Returns:
      Converted value.
    • convertOrNull

      @Nullable public <T> T convertOrNull(@NonNull ValueNode value, @NonNull Class<T> type)
      Description copied from interface: Context
      Converts a value (single or hash) into the given type.
      Specified by:
      convertOrNull in interface Context
      Type Parameters:
      T - Generic type.
      Parameters:
      value - Value to convert.
      type - Expected type.
      Returns:
      Converted value or null.
    • decode

      @NonNull public <T> T decode(@NonNull Type type, @NonNull MediaType contentType)
      Description copied from interface: Context
      Convert the HTTP body to the given type.
      Specified by:
      decode in interface Context
      Type Parameters:
      T - Conversion type.
      Parameters:
      type - Generic type.
      contentType - Content type to use.
      Returns:
      Instance of conversion type.
    • decoder

      @NonNull public MessageDecoder decoder(@NonNull MediaType contentType)
      Description copied from interface: Context
      Get a decoder for the given content type or get an StatusCode.UNSUPPORTED_MEDIA_TYPE.
      Specified by:
      decoder in interface Context
      Parameters:
      contentType - Content type.
      Returns:
      MessageDecoder.
    • isInIoThread

      public boolean isInIoThread()
      Description copied from interface: Context
      True when request runs in IO threads.
      Specified by:
      isInIoThread in interface Context
      Returns:
      True when request runs in IO threads.
    • dispatch

      @NonNull public Context dispatch(@NonNull Runnable action)
      Description copied from interface: Context
      Dispatch context to a worker threads. Worker threads allow to execute blocking code. The default worker thread pool is provided by web server or by application code using the Jooby.setWorker(Executor).

      Example:

      
       get("/", ctx -> {
         return ctx.dispatch(() -> {
      
           // run blocking code
      
         }):
       });
      
       
      Specified by:
      dispatch in interface Context
      Parameters:
      action - Application code.
      Returns:
      This context.
    • dispatch

      @NonNull public Context dispatch(@NonNull Executor executor, @NonNull Runnable action)
      Description copied from interface: Context
      Dispatch context to the given executor.

      Example:

      
       Executor executor = ...;
       get("/", ctx -> {
         return ctx.dispatch(executor, () -> {
      
           // run blocking code
      
         }):
       });
      
       
      Specified by:
      dispatch in interface Context
      Parameters:
      executor - Executor to use.
      action - Application code.
      Returns:
      This context.
    • detach

      @NonNull public Context detach(@NonNull Route.Handler next) throws Exception
      Description copied from interface: Context
      Tells context that response will be generated form a different thread. This operation is similar to Context.dispatch(Runnable) except there is no thread dispatching here.

      This operation integrates easily with third-party libraries like rxJava or others.

      Specified by:
      detach in interface Context
      Parameters:
      next - Application code.
      Returns:
      This context.
      Throws:
      Exception - When detach operation fails.
    • upgrade

      @NonNull public Context upgrade(@NonNull WebSocket.Initializer handler)
      Description copied from interface: Context
      Perform a websocket handsahke and upgrade a HTTP GET into a websocket protocol.

      NOTE: This method is part of Public API, but shouldn't be used by client code.

      Specified by:
      upgrade in interface Context
      Parameters:
      handler - Web socket initializer.
      Returns:
      This context.
    • upgrade

      @NonNull public Context upgrade(@NonNull ServerSentEmitter.Handler handler)
      Description copied from interface: Context
      Perform a server-sent event handshake and upgrade HTTP GET into a Server-Sent protocol.

      NOTE: This method is part of Public API, but shouldn't be used by client code.

      Specified by:
      upgrade in interface Context
      Parameters:
      handler - Server-Sent event handler.
      Returns:
      This context.
    • setResponseHeader

      @NonNull public Context setResponseHeader(@NonNull String name, @NonNull Date value)
      Description copied from interface: Context
      Set response header.
      Specified by:
      setResponseHeader in interface Context
      Parameters:
      name - Header name.
      value - Header value.
      Returns:
      This context.
    • setResponseHeader

      @NonNull public Context setResponseHeader(@NonNull String name, @NonNull Instant value)
      Description copied from interface: Context
      Set response header.
      Specified by:
      setResponseHeader in interface Context
      Parameters:
      name - Header name.
      value - Header value.
      Returns:
      This context.
    • setResponseHeader

      @NonNull public Context setResponseHeader(@NonNull String name, @NonNull Object value)
      Description copied from interface: Context
      Set response header.
      Specified by:
      setResponseHeader in interface Context
      Parameters:
      name - Header name.
      value - Header value.
      Returns:
      This context.
    • setResponseHeader

      @NonNull public Context setResponseHeader(@NonNull String name, @NonNull String value)
      Description copied from interface: Context
      Set response header.
      Specified by:
      setResponseHeader in interface Context
      Parameters:
      name - Header name.
      value - Header value.
      Returns:
      This context.
    • removeResponseHeader

      @NonNull public Context removeResponseHeader(@NonNull String name)
      Description copied from interface: Context
      Remove a response header.
      Specified by:
      removeResponseHeader in interface Context
      Parameters:
      name - Header's name.
      Returns:
      This context.
    • removeResponseHeaders

      @NonNull public Context removeResponseHeaders()
      Description copied from interface: Context
      Clear/reset all the headers, including cookies.
      Specified by:
      removeResponseHeaders in interface Context
      Returns:
      This context.
    • getResponseHeader

      @Nullable public String getResponseHeader(@NonNull String name)
      Description copied from interface: Context
      Get response header.
      Specified by:
      getResponseHeader in interface Context
      Parameters:
      name - Header's name.
      Returns:
      Header's value (if set previously) or null.
    • getResponseLength

      public long getResponseLength()
      Description copied from interface: Context
      Get response content length or -1 when none was set.
      Specified by:
      getResponseLength in interface Context
      Returns:
      Response content length or -1 when none was set.
    • setResponseLength

      @NonNull public Context setResponseLength(long length)
      Description copied from interface: Context
      Set response content length header.
      Specified by:
      setResponseLength in interface Context
      Parameters:
      length - Response length.
      Returns:
      This context.
    • setResponseCookie

      @NonNull public Context setResponseCookie(@NonNull Cookie cookie)
      Description copied from interface: Context
      Set/add a cookie to response.
      Specified by:
      setResponseCookie in interface Context
      Parameters:
      cookie - Cookie to add.
      Returns:
      This context.
    • setResponseType

      @NonNull public Context setResponseType(@NonNull String contentType)
      Description copied from interface: Context
      Set response content type header.
      Specified by:
      setResponseType in interface Context
      Parameters:
      contentType - Content type.
      Returns:
      This context.
    • setResponseType

      @NonNull public Context setResponseType(@NonNull MediaType contentType)
      Description copied from interface: Context
      Set response content type header.
      Specified by:
      setResponseType in interface Context
      Parameters:
      contentType - Content type.
      Returns:
      This context.
    • setResponseType

      @NonNull public Context setResponseType(@NonNull MediaType contentType, @Nullable Charset charset)
      Description copied from interface: Context
      Set response content type header.
      Specified by:
      setResponseType in interface Context
      Parameters:
      contentType - Content type.
      charset - Charset.
      Returns:
      This context.
    • setDefaultResponseType

      @NonNull public Context setDefaultResponseType(@NonNull MediaType contentType)
      Description copied from interface: Context
      Set the default response content type header. It is used if the response content type header was not set yet.
      Specified by:
      setDefaultResponseType in interface Context
      Parameters:
      contentType - Content type.
      Returns:
      This context.
    • getResponseType

      @NonNull public MediaType getResponseType()
      Description copied from interface: Context
      Get response content type.
      Specified by:
      getResponseType in interface Context
      Returns:
      Response content type.
    • setResponseCode

      @NonNull public Context setResponseCode(@NonNull StatusCode statusCode)
      Description copied from interface: Context
      Set response status code.
      Specified by:
      setResponseCode in interface Context
      Parameters:
      statusCode - Status code.
      Returns:
      This context.
    • setResponseCode

      @NonNull public Context setResponseCode(int statusCode)
      Description copied from interface: Context
      Set response status code.
      Specified by:
      setResponseCode in interface Context
      Parameters:
      statusCode - Status code.
      Returns:
      This context.
    • getResponseCode

      @NonNull public StatusCode getResponseCode()
      Description copied from interface: Context
      Get response status code.
      Specified by:
      getResponseCode in interface Context
      Returns:
      Response status code.
    • render

      @NonNull public Context render(@NonNull Object value)
      Description copied from interface: Context
      Render a value and send the response to client.
      Specified by:
      render in interface Context
      Parameters:
      value - Object value.
      Returns:
      This context.
    • responseStream

      @NonNull public OutputStream responseStream()
      Description copied from interface: Context
      HTTP response channel as output stream. Usually for chunked responses.
      Specified by:
      responseStream in interface Context
      Returns:
      HTTP channel as output stream. Usually for chunked responses.
    • responseStream

      @NonNull public OutputStream responseStream(@NonNull MediaType contentType)
      Description copied from interface: Context
      HTTP response channel as output stream. Usually for chunked responses.
      Specified by:
      responseStream in interface Context
      Parameters:
      contentType - Media type.
      Returns:
      HTTP channel as output stream. Usually for chunked responses.
    • responseStream

      @NonNull public Context responseStream(@NonNull MediaType contentType, @NonNull SneakyThrows.Consumer<OutputStream> consumer) throws Exception
      Description copied from interface: Context
      HTTP response channel as output stream. Usually for chunked responses.
      Specified by:
      responseStream in interface Context
      Parameters:
      contentType - Content type.
      consumer - Output stream consumer.
      Returns:
      HTTP channel as output stream. Usually for chunked responses.
      Throws:
      Exception - Is something goes wrong.
    • responseStream

      @NonNull public Context responseStream(@NonNull SneakyThrows.Consumer<OutputStream> consumer) throws Exception
      Description copied from interface: Context
      HTTP response channel as output stream. Usually for chunked responses.
      Specified by:
      responseStream in interface Context
      Parameters:
      consumer - Output stream consumer.
      Returns:
      HTTP channel as output stream. Usually for chunked responses.
      Throws:
      Exception - Is something goes wrong.
    • responseSender

      @NonNull public Sender responseSender()
      Description copied from interface: Context
      HTTP response channel as chunker.
      Specified by:
      responseSender in interface Context
      Returns:
      HTTP channel as chunker. Usually for chunked response.
    • responseWriter

      @NonNull public PrintWriter responseWriter()
      Description copied from interface: Context
      HTTP response channel as response writer.
      Specified by:
      responseWriter in interface Context
      Returns:
      HTTP channel as response writer. Usually for chunked response.
    • responseWriter

      @NonNull public PrintWriter responseWriter(@NonNull MediaType contentType)
      Description copied from interface: Context
      HTTP response channel as response writer.
      Specified by:
      responseWriter in interface Context
      Parameters:
      contentType - Content type.
      Returns:
      HTTP channel as response writer. Usually for chunked response.
    • responseWriter

      @NonNull public PrintWriter responseWriter(@NonNull MediaType contentType, @Nullable Charset charset)
      Description copied from interface: Context
      HTTP response channel as response writer.
      Specified by:
      responseWriter in interface Context
      Parameters:
      contentType - Content type.
      charset - Charset.
      Returns:
      HTTP channel as response writer. Usually for chunked response.
    • responseWriter

      @NonNull public Context responseWriter(@NonNull SneakyThrows.Consumer<PrintWriter> consumer) throws Exception
      Description copied from interface: Context
      HTTP response channel as response writer.
      Specified by:
      responseWriter in interface Context
      Parameters:
      consumer - Writer consumer.
      Returns:
      This context.
      Throws:
      Exception - Is something goes wrong.
    • responseWriter

      @NonNull public Context responseWriter(@NonNull MediaType contentType, @NonNull SneakyThrows.Consumer<PrintWriter> consumer) throws Exception
      Description copied from interface: Context
      HTTP response channel as response writer.
      Specified by:
      responseWriter in interface Context
      Parameters:
      contentType - Content type.
      consumer - Writer consumer.
      Returns:
      This context.
      Throws:
      Exception - Is something goes wrong.
    • responseWriter

      @NonNull public Context responseWriter(@NonNull MediaType contentType, @Nullable Charset charset, @NonNull SneakyThrows.Consumer<PrintWriter> consumer) throws Exception
      Description copied from interface: Context
      HTTP response channel as response writer.
      Specified by:
      responseWriter in interface Context
      Parameters:
      contentType - Content type.
      charset - Charset.
      consumer - Writer consumer.
      Returns:
      This context.
      Throws:
      Exception - Is something goes wrong.
    • sendRedirect

      @NonNull public Context sendRedirect(@NonNull String location)
      Description copied from interface: Context
      Send a 302 response.
      Specified by:
      sendRedirect in interface Context
      Parameters:
      location - Location.
      Returns:
      This context.
    • sendRedirect

      @NonNull public Context sendRedirect(@NonNull StatusCode redirect, @NonNull String location)
      Description copied from interface: Context
      Send a redirect response.
      Specified by:
      sendRedirect in interface Context
      Parameters:
      redirect - Redirect status code.
      location - Location.
      Returns:
      This context.
    • send

      @NonNull public Context send(@NonNull String data)
      Description copied from interface: Context
      Send response data.
      Specified by:
      send in interface Context
      Parameters:
      data - Response. Use UTF-8 charset.
      Returns:
      This context.
    • send

      @NonNull public Context send(@NonNull String data, @NonNull Charset charset)
      Description copied from interface: Context
      Send response data.
      Specified by:
      send in interface Context
      Parameters:
      data - Response.
      charset - Charset.
      Returns:
      This context.
    • send

      @NonNull public Context send(@NonNull byte[] data)
      Description copied from interface: Context
      Send response data.
      Specified by:
      send in interface Context
      Parameters:
      data - Response.
      Returns:
      This context.
    • send

      @NonNull public Context send(@NonNull ByteBuffer data)
      Description copied from interface: Context
      Send response data.
      Specified by:
      send in interface Context
      Parameters:
      data - Response.
      Returns:
      This context.
    • send

      @NonNull public Context send(@NonNull byte[]... data)
      Description copied from interface: Context
      Send response data.
      Specified by:
      send in interface Context
      Parameters:
      data - Response.
      Returns:
      This context.
    • send

      @NonNull public Context send(@NonNull ByteBuffer[] data)
      Description copied from interface: Context
      Send response data.
      Specified by:
      send in interface Context
      Parameters:
      data - Response.
      Returns:
      This context.
    • send

      @NonNull public Context send(@NonNull ReadableByteChannel channel)
      Description copied from interface: Context
      Send response data.
      Specified by:
      send in interface Context
      Parameters:
      channel - Response input.
      Returns:
      This context.
    • send

      @NonNull public Context send(@NonNull InputStream input)
      Description copied from interface: Context
      Send response data.
      Specified by:
      send in interface Context
      Parameters:
      input - Response.
      Returns:
      This context.
    • send

      @NonNull public Context send(@NonNull FileDownload file)
      Description copied from interface: Context
      Send a file download response.
      Specified by:
      send in interface Context
      Parameters:
      file - File download.
      Returns:
      This context.
    • send

      @NonNull public Context send(@NonNull Path file)
      Description copied from interface: Context
      Send a file response.
      Specified by:
      send in interface Context
      Parameters:
      file - File response.
      Returns:
      This context.
    • send

      @NonNull public Context send(@NonNull FileChannel file)
      Description copied from interface: Context
      Send a file response.
      Specified by:
      send in interface Context
      Parameters:
      file - File response.
      Returns:
      This context.
    • send

      @NonNull public Context send(@NonNull StatusCode statusCode)
      Description copied from interface: Context
      Send an empty response with the given status code.
      Specified by:
      send in interface Context
      Parameters:
      statusCode - Status code.
      Returns:
      This context.
    • sendError

      @NonNull public Context sendError(@NonNull Throwable cause)
      Description copied from interface: Context
      Send an error response. Status code is computed via Router.errorCode(Throwable).
      Specified by:
      sendError in interface Context
      Parameters:
      cause - Error. If this is a fatal error it is going to be rethrow it.
      Returns:
      This context.
    • sendError

      @NonNull public Context sendError(@NonNull Throwable cause, @NonNull StatusCode code)
      Description copied from interface: Context
      Send an error response.
      Specified by:
      sendError in interface Context
      Parameters:
      cause - Error. If this is a fatal error it is going to be rethrow it.
      code - Status code.
      Returns:
      This context.
    • isResponseStarted

      public boolean isResponseStarted()
      Description copied from interface: Context
      True if response already started.
      Specified by:
      isResponseStarted in interface Context
      Returns:
      True if response already started.
    • getResetHeadersOnError

      public boolean getResetHeadersOnError()
      Description copied from interface: Context
      True if response headers are cleared on application error. If none set it uses the default/global value specified by RouterOption.RESET_HEADERS_ON_ERROR.
      Specified by:
      getResetHeadersOnError in interface Context
      Returns:
      True if response headers are cleared on application error. If none set it uses the default/global value specified by RouterOption.RESET_HEADERS_ON_ERROR.
    • setResetHeadersOnError

      public Context setResetHeadersOnError(boolean value)
      Description copied from interface: Context
      Set whenever reset/clear headers on application error.
      Specified by:
      setResetHeadersOnError in interface Context
      Parameters:
      value - True for reset/clear headers.
      Returns:
      This context.
    • onComplete

      @NonNull public Context onComplete(@NonNull Route.Complete task)
      Description copied from interface: Context
      Add a complete listener.
      Specified by:
      onComplete in interface Context
      Parameters:
      task - Task to execute.
      Returns:
      This context.
    • require

      @NonNull public <T> T require(@NonNull Class<T> type) throws RegistryException
      Description copied from interface: Registry
      Provides an instance of the given type.
      Specified by:
      require in interface Registry
      Type Parameters:
      T - Object type.
      Parameters:
      type - Object type.
      Returns:
      Instance of this type.
      Throws:
      RegistryException - If there was a runtime failure while providing an instance.
    • require

      @NonNull public <T> T require(@NonNull Class<T> type, @NonNull String name) throws RegistryException
      Description copied from interface: Registry
      Provides an instance of the given type where name matches it.
      Specified by:
      require in interface Registry
      Type Parameters:
      T - Object type.
      Parameters:
      type - Object type.
      name - Object name.
      Returns:
      Instance of this type.
      Throws:
      RegistryException - If there was a runtime failure while providing an instance.
    • require

      @NonNull public <T> T require(@NonNull ServiceKey<T> key) throws RegistryException
      Description copied from interface: Registry
      Provides an instance of the given type.
      Specified by:
      require in interface Registry
      Type Parameters:
      T - Object type.
      Parameters:
      key - Object key.
      Returns:
      Instance of this type.
      Throws:
      RegistryException - If there was a runtime failure while providing an instance.
    • toString

      public String toString()
      Overrides:
      toString in class Object