Module io.jooby
Package io.jooby

Class Route

java.lang.Object
io.jooby.Route

public class Route extends Object
Route contains information about the HTTP method, path pattern, which content types consumes and produces, etc..

Additionally, contains metadata about route return Java type, argument source (query, path, etc..) and Java type.

This class contains all the metadata associated to a route. It is like a Class object for routes.

Since:
2.0.0
Author:
edgar
  • Field Details

  • Constructor Details

    • Route

      public Route(@NonNull String method, @NonNull String pattern, @NonNull Route.Handler handler)
      Creates a new route.
      Parameters:
      method - HTTP method.
      pattern - Path pattern.
      handler - Route handler.
  • Method Details

    • getPattern

      @NonNull public String getPattern()
      Path pattern.
      Returns:
      Path pattern.
    • getMethod

      @NonNull public String getMethod()
      HTTP method.
      Returns:
      HTTP method.
    • getPathKeys

      @NonNull public List<String> getPathKeys()
      Path keys.
      Returns:
      Path keys.
    • setPathKeys

      @NonNull public Route setPathKeys(@NonNull List<String> pathKeys)
      Set path keys.
      Parameters:
      pathKeys - Path keys or empty list.
      Returns:
      This route.
    • getHandler

      @NonNull public Route.Handler getHandler()
      Route handler.
      Returns:
      Route handler.
    • getPipeline

      @NonNull public Route.Handler getPipeline()
      Route pipeline.
      Returns:
      Route pipeline.
    • reverse

      @NonNull public String reverse(@NonNull Map<String,Object> keys)
      Recreate a path pattern using the given variables. reserve(/{k1}/{k2}, {"k1": ""foo", "k2": "bar"}) => /foo/bar
      Parameters:
      keys - Path keys.
      Returns:
      Path.
    • reverse

      @NonNull public String reverse(Object... values)
      Recreate a path pattern using the given variables. reserve(/{k1}/{k2}, "foo", "bar") => /foo/bar
      Parameters:
      values - Values.
      Returns:
      Path.
    • getHandle

      @NonNull public Object getHandle()
      Handler instance which might or might not be the same as getHandler().

      The handle is required to extract correct metadata.

      Returns:
      Handle.
    • getAfter

      @Nullable public Route.After getAfter()
      After filter or null.
      Returns:
      After filter or null.
    • setAfter

      @NonNull public Route setAfter(@NonNull Route.After after)
      Set after filter.
      Parameters:
      after - After filter.
      Returns:
      This route.
    • getFilter

      @Nullable public Route.Filter getFilter()
      Decorator or null.
      Returns:
      Decorator or null.
    • setFilter

      @NonNull public Route setFilter(@Nullable Route.Filter filter)
      Set route filter.
      Parameters:
      filter - Filter.
      Returns:
      This route.
    • setHandle

      @NonNull public Route setHandle(@NonNull Object handle)
      Set route handle instance, required when handle is different from getHandler().
      Parameters:
      handle - Handle instance.
      Returns:
      This route.
    • setPipeline

      @NonNull public Route setPipeline(Route.Handler pipeline)
      Set route pipeline. This method is part of public API but isn't intended to be used by public.
      Parameters:
      pipeline - Pipeline.
      Returns:
      This routes.
    • getEncoder

      @NonNull public MessageEncoder getEncoder()
      Route encoder.
      Returns:
      Route encoder.
    • setEncoder

      @NonNull public Route setEncoder(@NonNull MessageEncoder encoder)
      Set encoder.
      Parameters:
      encoder - MessageEncoder.
      Returns:
      This route.
    • isNonBlocking

      @NonNull public boolean isNonBlocking()
      Truth when route is non-blocking. False otherwise. Blocking code isn't allowed for non-blocking routes.

      Default is blocking or non-blocking=false. Except when you startup your application using ExecutionMode.EVENT_LOOP.

      Returns:
      Truth when route is non-blocking. False otherwise or null otherwise.
    • isNonBlockingSet

      public boolean isNonBlockingSet()
      Test if the isNonBlocking() flag was set or not. Internal use only.
      Returns:
      Test if the isNonBlocking() flag was set or not. Internal use only.
    • setNonBlocking

      @NonNull public Route setNonBlocking(boolean nonBlocking)
      Set when the route is blocking or non-blocking.

      Default is blocking or non-blocking=false. Except when you startup your application using ExecutionMode.EVENT_LOOP.

      Parameters:
      nonBlocking - True for non-blocking routes.
      Returns:
    • getReturnType

      @Nullable public Type getReturnType()
      Return return type.
      Returns:
      Return type.
    • setReturnType

      @NonNull public Route setReturnType(@Nullable Type returnType)
      Set route return type.
      Parameters:
      returnType - Return type.
      Returns:
      This route.
    • getProduces

      @NonNull public List<MediaType> getProduces()
      Response types (format) produces by this route. If set, we expect to find a match in the Accept header. If none matches, we send a StatusCode.NOT_ACCEPTABLE response.
      Returns:
      Immutable list of produce types.
    • produces

      @NonNull public Route produces(@NonNull MediaType... produces)
      Add one or more response types (format) produces by this route.
      Parameters:
      produces - Produce types.
      Returns:
      This route.
    • setProduces

      @NonNull public Route setProduces(@NonNull Collection<MediaType> produces)
      Add one or more response types (format) produces by this route.
      Parameters:
      produces - Produce types.
      Returns:
      This route.
    • getConsumes

      @NonNull public List<MediaType> getConsumes()
      Request types (format) consumed by this route. If set the Content-Type header is checked against these values. If none matches we send a StatusCode.UNSUPPORTED_MEDIA_TYPE exception.
      Returns:
      Immutable list of consumed types.
    • consumes

      @NonNull public Route consumes(@NonNull MediaType... consumes)
      Add one or more request types (format) consumed by this route.
      Parameters:
      consumes - Consume types.
      Returns:
      This route.
    • setConsumes

      @NonNull public Route setConsumes(@NonNull Collection<MediaType> consumes)
      Add one or more request types (format) consumed by this route.
      Parameters:
      consumes - Consume types.
      Returns:
      This route.
    • getAttributes

      @NonNull public Map<String,Object> getAttributes()
      Attributes set to this route.
      Returns:
      Map of attributes set to the route.
    • attribute

      @Nullable public <T> T attribute(@NonNull String name)
      Retrieve value of this specific Attribute set to this route.
      Type Parameters:
      T - Generic type.
      Parameters:
      name - of the attribute to retrieve.
      Returns:
      value of the specific attribute.
    • setAttributes

      @NonNull public Route setAttributes(@NonNull Map<String,Object> attributes)
      Add one or more attributes applied to this route.
      Parameters:
      attributes - .
      Returns:
      This route.
    • attribute

      @NonNull public Route attribute(@NonNull String name, @NonNull Object value)
      Add one or more attributes applied to this route.
      Parameters:
      name - attribute name
      value - attribute value
      Returns:
      This route.
    • decoder

      @NonNull public MessageDecoder decoder(@NonNull MediaType contentType)
      MessageDecoder for given media type.
      Parameters:
      contentType - Media type.
      Returns:
      MessageDecoder.
    • getDecoders

      @NonNull public Map<String,MessageDecoder> getDecoders()
      Route message decoder.
      Returns:
      Message decoders.
    • setDecoders

      @NonNull public Route setDecoders(@NonNull Map<String,MessageDecoder> decoders)
      Set message decoders. Map key is a mime-type.
      Parameters:
      decoders - message decoder.
      Returns:
      This route.
    • isHttpOptions

      public boolean isHttpOptions()
      True if route support HTTP OPTIONS.
      Returns:
      True if route support HTTP OPTIONS.
    • isHttpTrace

      public boolean isHttpTrace()
      True if route support HTTP TRACE.
      Returns:
      True if route support HTTP TRACE.
    • isHttpHead

      public boolean isHttpHead()
      True if route support HTTP HEAD.
      Returns:
      True if route support HTTP HEAD.
    • setHttpOptions

      @NonNull public Route setHttpOptions(boolean enabled)
      Enabled or disabled HTTP Options.
      Parameters:
      enabled - Enabled or disabled HTTP Options.
      Returns:
      This route.
    • setHttpTrace

      @NonNull public Route setHttpTrace(boolean enabled)
      Enabled or disabled HTTP TRACE.
      Parameters:
      enabled - Enabled or disabled HTTP TRACE.
      Returns:
      This route.
    • setHttpHead

      @NonNull public Route setHttpHead(boolean enabled)
      Enabled or disabled HTTP HEAD.
      Parameters:
      enabled - Enabled or disabled HTTP HEAD.
      Returns:
      This route.
    • getExecutorKey

      @Nullable public String getExecutorKey()
      Specify the name of the executor where the route is going to run. Default is null.
      Returns:
      Executor key.
    • setExecutorKey

      @NonNull public Route setExecutorKey(@Nullable String executorKey)
      Set executor key. The route is going to use the given key to fetch an executor. Possible values are:

      - null: no specific executor, uses the default Jooby logic to choose one, based on the value of ExecutionMode; - worker: use the executor provided by the server. - arbitrary name: use an named executor which as registered using Router.executor(String, Executor).

      Parameters:
      executorKey - Executor key.
      Returns:
      This route.
    • getTags

      @NonNull public List<String> getTags()
      Route tags.
      Returns:
      Route tags.
    • setTags

      @NonNull public Route setTags(@NonNull List<String> tags)
      Tag this route. Tags are used for documentation purpose from openAPI generator.
      Parameters:
      tags - Tags.
      Returns:
      This route.
    • addTag

      @NonNull public Route addTag(@NonNull String tag)
      Add a tag to this route.

      Tags are used for documentation purpose from openAPI generator.

      Parameters:
      tag - Tag.
      Returns:
      This route.
    • tags

      @NonNull public Route tags(@NonNull String... tags)
      Tag this route. Tags are used for documentation purpose from openAPI generator.
      Parameters:
      tags - Tags.
      Returns:
      This route.
    • getSummary

      @Nullable public String getSummary()
      Route summary useful for documentation purpose from openAPI generator.
      Returns:
      Summary.
    • summary

      @NonNull public Route summary(@Nullable String summary)
      Route summary useful for documentation purpose from openAPI generator.
      Parameters:
      summary - Summary.
      Returns:
      This route.
    • setSummary

      @NonNull public Route setSummary(@Nullable String summary)
      Route summary useful for documentation purpose from openAPI generator.
      Parameters:
      summary - Summary.
      Returns:
      This route.
    • getDescription

      @Nullable public String getDescription()
      Route description useful for documentation purpose from openAPI generator.
      Returns:
      Route description.
    • setDescription

      @NonNull public Route setDescription(@Nullable String description)
      Route description useful for documentation purpose from openAPI generator.
      Parameters:
      description - Description.
      Returns:
      This route.
    • description

      @NonNull public Route description(@Nullable String description)
      Route description useful for documentation purpose from openAPI generator.
      Parameters:
      description - Description.
      Returns:
      This route.
    • isTransactional

      public boolean isTransactional(boolean defaultValue)
      Returns whether this route is marked as transactional, or returns defaultValue if this route has not been marked explicitly.
      Parameters:
      defaultValue - the value to return if this route was not explicitly marked
      Returns:
      whether this route should be considered as transactional
    • getMvcMethod

      @Nullable public Method getMvcMethod()
      Method for MVC/Controller. Not available for lambda routes.
      Returns:
      Method for MVC/Controller. Not available for lambda routes.
    • setMvcMethod

      @NonNull public Route setMvcMethod(@Nullable Method mvcMethod)
      Set mvc/controller method.
      Parameters:
      mvcMethod - Mvc/controller method.
      Returns:
      This route
    • mvcMethod

      @NonNull public Route mvcMethod(@Nullable Method mvcMethod)
      Set mvc/controller method.
      Parameters:
      mvcMethod - Mvc/controller method.
      Returns:
      This route
    • toString

      public String toString()
      Overrides:
      toString in class Object