Class DefaultRouteBuilder

java.lang.Object
io.micronaut.web.router.DefaultRouteBuilder
All Implemented Interfaces:
RouteBuilder
Direct Known Subclasses:
AnnotatedFilterRouteBuilder, AnnotatedFunctionRouteBuilder, AnnotatedMethodRouteBuilder, DeleteEndpointRouteBuilder, ReadEndpointRouteBuilder, ServerFilterRouteBuilder, ServerWebSocketProcessor, WriteEndpointRouteBuilder

public abstract class DefaultRouteBuilder extends Object implements RouteBuilder
A DefaultRouteBuilder implementation for building roots.
Since:
1.0
Author:
Graeme Rocher
  • Field Details

  • Constructor Details

    • DefaultRouteBuilder

      public DefaultRouteBuilder(ExecutionHandleLocator executionHandleLocator)
      Parameters:
      executionHandleLocator - The execution handler locator
    • DefaultRouteBuilder

      public DefaultRouteBuilder(ExecutionHandleLocator executionHandleLocator, RouteBuilder.UriNamingStrategy uriNamingStrategy)
      Parameters:
      executionHandleLocator - The execution handler locator
      uriNamingStrategy - The URI naming strategy
    • DefaultRouteBuilder

      public DefaultRouteBuilder(ExecutionHandleLocator executionHandleLocator, RouteBuilder.UriNamingStrategy uriNamingStrategy, ConversionService conversionService)
      Parameters:
      executionHandleLocator - The execution handler locator
      uriNamingStrategy - The URI naming strategy
      conversionService - The conversion service
  • Method Details

    • getExposedPorts

      public Set<Integer> getExposedPorts()
      Specified by:
      getExposedPorts in interface RouteBuilder
      Returns:
      The exposed ports
    • getFilterRoutes

      public List<FilterRoute> getFilterRoutes()
      Specified by:
      getFilterRoutes in interface RouteBuilder
      Returns:
      The filter routes
    • addFilter

      public FilterRoute addFilter(String pathPattern, BeanLocator beanLocator, BeanDefinition<? extends HttpFilter> definition)
      Description copied from interface: RouteBuilder
      Add a filter.
      Specified by:
      addFilter in interface RouteBuilder
      Parameters:
      pathPattern - The path pattern for the filter
      beanLocator - The bean locator
      definition - The bean definition
      Returns:
      The FilterRoute
    • getStatusRoutes

      public List<StatusRoute> getStatusRoutes()
      Specified by:
      getStatusRoutes in interface RouteBuilder
      Returns:
      Obtain a list of constructed routes
    • getErrorRoutes

      public List<ErrorRoute> getErrorRoutes()
      Specified by:
      getErrorRoutes in interface RouteBuilder
      Returns:
      Obtain a list of constructed routes
    • getUriRoutes

      public List<UriRoute> getUriRoutes()
      Specified by:
      getUriRoutes in interface RouteBuilder
      Returns:
      Obtain a list of constructed routes
    • getUriNamingStrategy

      public RouteBuilder.UriNamingStrategy getUriNamingStrategy()
      Specified by:
      getUriNamingStrategy in interface RouteBuilder
      Returns:
      The URI naming strategy
    • resources

      public ResourceRoute resources(Class<?> cls)
      Description copied from interface: RouteBuilder

      Builds the necessary mappings to treat the given class as a REST endpoint.

      For example given a class called BookController the following routes will be produced:

      
           GET "/book"
           GET "/book{/id}"
           POST "/book"
           PUT "/book{/id}"
           PATCH "/book{/id}"
           DELETE "/book{/id}"
       

      By default it is assumed the accepted and returned content type is MediaType.APPLICATION_JSON_TYPE.

      Specified by:
      resources in interface RouteBuilder
      Parameters:
      cls - The class
      Returns:
      The ResourceRoute
    • single

      public ResourceRoute single(Class<?> cls)
      Description copied from interface: RouteBuilder

      Builds the necessary mappings to treat the given class as a singular REST endpoint.

      For example given a class called BookController the following routes will be produced:

      
           GET "/book"
           POST "/book"
           PUT "/book"
           PATCH "/book"
           DELETE "/book"
       

      By default it is assumed the accepted and returned content type is MediaType.APPLICATION_JSON_TYPE.

      Specified by:
      single in interface RouteBuilder
      Parameters:
      cls - The class
      Returns:
      The ResourceRoute
    • status

      public StatusRoute status(Class<?> originatingClass, HttpStatus status, Class<?> type, String method, Class<?>[] parameterTypes)
      Description copied from interface: RouteBuilder
      Register a route to handle the returned status code. This implementation considers the originatingClass for matching.
      Specified by:
      status in interface RouteBuilder
      Parameters:
      originatingClass - The class where the error originates from
      status - The status code
      type - The type
      method - The method
      parameterTypes - The parameter types for the target method
      Returns:
      The route
    • status

      public StatusRoute status(HttpStatus status, Class<?> type, String method, Class<?>[] parameterTypes)
      Description copied from interface: RouteBuilder
      Register a route to handle the returned status code.
      Specified by:
      status in interface RouteBuilder
      Parameters:
      status - The status code
      type - The type
      method - The method
      parameterTypes - The parameter types for the target method
      Returns:
      The route
    • error

      public ErrorRoute error(Class<?> originatingClass, Class<? extends Throwable> error, Class<?> type, String method, Class<?>[] parameterTypes)
      Description copied from interface: RouteBuilder
      Register a route to handle the error.
      Specified by:
      error in interface RouteBuilder
      Parameters:
      originatingClass - The class where the error originates from
      error - The error type
      type - The type to route to
      method - The method to route to
      parameterTypes - The parameter types for the target method
      Returns:
      The route
    • error

      public ErrorRoute error(Class<? extends Throwable> error, Class<?> type, String method, Class<?>[] parameterTypes)
      Description copied from interface: RouteBuilder
      Register a route to handle the error.
      Specified by:
      error in interface RouteBuilder
      Parameters:
      error - The error
      type - The type
      method - The method
      parameterTypes - The parameter types for the target method
      Returns:
      The route
    • GET

      public UriRoute GET(String uri, Object target, String method, Class<?>... parameterTypes)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      GET in interface RouteBuilder
      Parameters:
      uri - The URI
      target - The target
      method - The method
      parameterTypes - The parameter types for the target method
      Returns:
      The route
    • GET

      public UriRoute GET(String uri, Class<?> type, String method, Class<?>... parameterTypes)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      GET in interface RouteBuilder
      Parameters:
      uri - The URI
      type - The type
      method - The method
      parameterTypes - The parameter types for the target method
      Returns:
      The route
    • POST

      public UriRoute POST(String uri, Object target, String method, Class<?>... parameterTypes)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      POST in interface RouteBuilder
      Parameters:
      uri - The URI
      target - The target
      method - The method
      parameterTypes - The parameter types for the target method
      Returns:
      The route
    • POST

      public UriRoute POST(String uri, Class<?> type, String method, Class<?>... parameterTypes)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      POST in interface RouteBuilder
      Parameters:
      uri - The URI
      type - The type
      method - The method
      parameterTypes - The parameter types for the target method
      Returns:
      The route
    • PUT

      public UriRoute PUT(String uri, Object target, String method, Class<?>... parameterTypes)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      PUT in interface RouteBuilder
      Parameters:
      uri - The URI
      target - The target
      method - The method
      parameterTypes - The parameter types for the target method
      Returns:
      The route
    • PUT

      public UriRoute PUT(String uri, Class<?> type, String method, Class<?>... parameterTypes)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      PUT in interface RouteBuilder
      Parameters:
      uri - The URI
      type - The type
      method - The method
      parameterTypes - The parameter types for the target method
      Returns:
      The route
    • PATCH

      public UriRoute PATCH(String uri, Object target, String method, Class<?>... parameterTypes)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      PATCH in interface RouteBuilder
      Parameters:
      uri - The URI
      target - The target
      method - The method
      parameterTypes - The parameter types for the target method
      Returns:
      The route
    • PATCH

      public UriRoute PATCH(String uri, Class<?> type, String method, Class<?>... parameterTypes)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      PATCH in interface RouteBuilder
      Parameters:
      uri - The URI
      type - The type
      method - The method
      parameterTypes - The parameter types for the target method
      Returns:
      The route
    • DELETE

      public UriRoute DELETE(String uri, Object target, String method, Class<?>... parameterTypes)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      DELETE in interface RouteBuilder
      Parameters:
      uri - The URI
      target - The target
      method - The method
      parameterTypes - The parameter types for the target method
      Returns:
      The route
    • DELETE

      public UriRoute DELETE(String uri, Class<?> type, String method, Class<?>... parameterTypes)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      DELETE in interface RouteBuilder
      Parameters:
      uri - The URI
      type - The type
      method - The method
      parameterTypes - The parameter types for the target method
      Returns:
      The route
    • OPTIONS

      public UriRoute OPTIONS(String uri, Object target, String method, Class<?>... parameterTypes)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      OPTIONS in interface RouteBuilder
      Parameters:
      uri - The URI
      target - The target
      method - The method
      parameterTypes - The parameter types for the target method
      Returns:
      The route
    • OPTIONS

      public UriRoute OPTIONS(String uri, Class<?> type, String method, Class<?>... parameterTypes)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      OPTIONS in interface RouteBuilder
      Parameters:
      uri - The URI
      type - The type
      method - The method
      parameterTypes - The parameter types for the target method
      Returns:
      The route
    • HEAD

      public UriRoute HEAD(String uri, Object target, String method, Class<?>... parameterTypes)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      HEAD in interface RouteBuilder
      Parameters:
      uri - The URI
      target - The target
      method - The method
      parameterTypes - The parameter types for the target method
      Returns:
      The route
    • HEAD

      public UriRoute HEAD(String uri, Class<?> type, String method, Class<?>... parameterTypes)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      HEAD in interface RouteBuilder
      Parameters:
      uri - The URI
      type - The type
      method - The method
      parameterTypes - The parameter types for the target method
      Returns:
      The route
    • TRACE

      public UriRoute TRACE(String uri, Object target, String method, Class<?>[] parameterTypes)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      TRACE in interface RouteBuilder
      Parameters:
      uri - The URI
      target - The target
      method - The method
      parameterTypes - The parameter types for the target method
      Returns:
      The route
    • TRACE

      public UriRoute TRACE(String uri, Class<?> type, String method, Class<?>[] parameterTypes)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      TRACE in interface RouteBuilder
      Parameters:
      uri - The URI
      type - The type
      method - The method
      parameterTypes - The parameter types for the target method
      Returns:
      The route
    • GET

      public UriRoute GET(String uri, BeanDefinition<?> beanDefinition, ExecutableMethod<?,?> method)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      GET in interface RouteBuilder
      Parameters:
      uri - The URI
      beanDefinition - The bean definition
      method - The method
      Returns:
      The route
    • POST

      public UriRoute POST(String uri, BeanDefinition<?> beanDefinition, ExecutableMethod<?,?> method)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      POST in interface RouteBuilder
      Parameters:
      uri - The URI
      beanDefinition - The bean definition
      method - The method
      Returns:
      The route
    • PUT

      public UriRoute PUT(String uri, BeanDefinition<?> beanDefinition, ExecutableMethod<?,?> method)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      PUT in interface RouteBuilder
      Parameters:
      uri - The URI
      beanDefinition - The bean definition
      method - The method
      Returns:
      The route
    • PATCH

      public UriRoute PATCH(String uri, BeanDefinition<?> beanDefinition, ExecutableMethod<?,?> method)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      PATCH in interface RouteBuilder
      Parameters:
      uri - The URI
      beanDefinition - The bean definition
      method - The method
      Returns:
      The route
    • DELETE

      public UriRoute DELETE(String uri, BeanDefinition<?> beanDefinition, ExecutableMethod<?,?> method)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      DELETE in interface RouteBuilder
      Parameters:
      uri - The URI
      beanDefinition - The bean definition
      method - The method
      Returns:
      The route
    • OPTIONS

      public UriRoute OPTIONS(String uri, BeanDefinition<?> beanDefinition, ExecutableMethod<?,?> method)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      OPTIONS in interface RouteBuilder
      Parameters:
      uri - The URI
      beanDefinition - The bean definition
      method - The method
      Returns:
      The route
    • HEAD

      public UriRoute HEAD(String uri, BeanDefinition<?> beanDefinition, ExecutableMethod<?,?> method)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      HEAD in interface RouteBuilder
      Parameters:
      uri - The URI
      beanDefinition - The bean definition
      method - The method
      Returns:
      The route
    • TRACE

      public UriRoute TRACE(String uri, BeanDefinition<?> beanDefinition, ExecutableMethod<?,?> method)
      Description copied from interface: RouteBuilder

      Route the specified URI template to the specified target.

      The number of variables in the template should match the number of method arguments

      Specified by:
      TRACE in interface RouteBuilder
      Parameters:
      uri - The URI
      beanDefinition - The bean definition
      method - The method
      Returns:
      The route
    • buildRoute

      protected UriRoute buildRoute(HttpMethod httpMethod, String uri, Class<?> type, String method, Class<?>... parameterTypes)
      Build a route.
      Parameters:
      httpMethod - The HTTP method
      uri - The URI
      type - The type
      method - The method
      parameterTypes - Parameters
      Returns:
      an UriRoute
    • buildRoute

      protected UriRoute buildRoute(HttpMethod httpMethod, String uri, MethodExecutionHandle<Object,Object> executableHandle)
      Build a route.
      Parameters:
      httpMethod - The HTTP method
      uri - The URI
      executableHandle - The executable handle
      Returns:
      an UriRoute
    • buildRoute

      protected UriRoute buildRoute(HttpMethod httpMethod, String uri, List<MediaType> mediaTypes, MethodExecutionHandle<Object,Object> executableHandle)
      Build a route.
      Parameters:
      httpMethod - The HTTP method
      uri - The URI
      mediaTypes - The media types
      executableHandle - The executable handle
      Returns:
      an UriRoute
      Since:
      4.2.0
    • buildBeanRoute

      protected UriRoute buildBeanRoute(String httpMethodName, HttpMethod httpMethod, String uri, BeanDefinition<?> beanDefinition, ExecutableMethod<?,?> method)
      A special case that is required for non-standard http methods.
      Parameters:
      httpMethodName - The name of method. For standard http methods matches Enum.name()
      httpMethod - The http method. Is HttpMethod.CUSTOM for non-standard http methods.
      uri - The uri.
      beanDefinition - The definition of the bean.
      method - The method description
      Returns:
      The uri route corresponding to the method.