Class DefaultRouteBuilder
- All Implemented Interfaces:
RouteBuilder
- Direct Known Subclasses:
AnnotatedFilterRouteBuilder
,AnnotatedFunctionRouteBuilder
,AnnotatedMethodRouteBuilder
,DeleteEndpointRouteBuilder
,ReadEndpointRouteBuilder
,ServerFilterRouteBuilder
,ServerWebSocketProcessor
,WriteEndpointRouteBuilder
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.micronaut.web.router.RouteBuilder
RouteBuilder.UriNamingStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final RouteBuilder.UriNamingStrategy
ARouteBuilder.UriNamingStrategy
whereby camel case conventions are used.protected final ConversionService
protected final Charset
protected final ExecutionHandleLocator
protected static final org.slf4j.Logger
protected final RouteBuilder.UriNamingStrategy
Fields inherited from interface io.micronaut.web.router.RouteBuilder
ID
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultRouteBuilder
(ExecutionHandleLocator executionHandleLocator) DefaultRouteBuilder
(ExecutionHandleLocator executionHandleLocator, RouteBuilder.UriNamingStrategy uriNamingStrategy) DefaultRouteBuilder
(ExecutionHandleLocator executionHandleLocator, RouteBuilder.UriNamingStrategy uriNamingStrategy, ConversionService conversionService) -
Method Summary
Modifier and TypeMethodDescriptionaddFilter
(String pathPattern, BeanLocator beanLocator, BeanDefinition<? extends HttpFilter> beanDefinition) Add a filter.protected UriRoute
buildBeanRoute
(String httpMethodName, HttpMethod httpMethod, String uri, BeanDefinition<?> beanDefinition, ExecutableMethod<?, ?> method) A special case that is required for non-standard http methods.protected UriRoute
buildRoute
(HttpMethod httpMethod, String uri, MethodExecutionHandle<Object, Object> executableHandle) Build a route.protected UriRoute
buildRoute
(HttpMethod httpMethod, String uri, Class<?> type, String method, Class<?>... parameterTypes) Build a route.DELETE
(String uri, BeanDefinition<?> beanDefinition, ExecutableMethod<?, ?> method) Route the specified URI template to the specified target.Route the specified URI template to the specified target.Route the specified URI template to the specified target.error
(Class<?> originatingClass, Class<? extends Throwable> error, Class<?> type, String method, Class<?>[] parameterTypes) Register a route to handle the error.Register a route to handle the error.GET
(String uri, BeanDefinition<?> beanDefinition, ExecutableMethod<?, ?> method) Route the specified URI template to the specified target.Route the specified URI template to the specified target.Route the specified URI template to the specified target.HEAD
(String uri, BeanDefinition<?> beanDefinition, ExecutableMethod<?, ?> method) Route the specified URI template to the specified target.Route the specified URI template to the specified target.Route the specified URI template to the specified target.OPTIONS
(String uri, BeanDefinition<?> beanDefinition, ExecutableMethod<?, ?> method) Route the specified URI template to the specified target.Route the specified URI template to the specified target.Route the specified URI template to the specified target.PATCH
(String uri, BeanDefinition<?> beanDefinition, ExecutableMethod<?, ?> method) Route the specified URI template to the specified target.Route the specified URI template to the specified target.Route the specified URI template to the specified target.POST
(String uri, BeanDefinition<?> beanDefinition, ExecutableMethod<?, ?> method) Route the specified URI template to the specified target.Route the specified URI template to the specified target.Route the specified URI template to the specified target.PUT
(String uri, BeanDefinition<?> beanDefinition, ExecutableMethod<?, ?> method) Route the specified URI template to the specified target.Route the specified URI template to the specified target.Route the specified URI template to the specified target.Builds the necessary mappings to treat the given class as a REST endpoint.Builds the necessary mappings to treat the given class as a singular REST endpoint.status
(HttpStatus status, Class<?> type, String method, Class<?>[] parameterTypes) Register a route to handle the returned status code.status
(Class<?> originatingClass, HttpStatus status, Class<?> type, String method, Class<?>[] parameterTypes) Register a route to handle the returned status code.TRACE
(String uri, BeanDefinition<?> beanDefinition, ExecutableMethod<?, ?> method) Route the specified URI template to the specified target.Route the specified URI template to the specified target.Route the specified URI template to the specified target.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.web.router.RouteBuilder
DELETE, DELETE, DELETE, DELETE, DELETE, DELETE, error, error, error, error, GET, GET, GET, GET, GET, GET, HEAD, HEAD, HEAD, HEAD, HEAD, HEAD, OPTIONS, OPTIONS, OPTIONS, OPTIONS, OPTIONS, OPTIONS, PATCH, PATCH, PATCH, PATCH, PATCH, PATCH, POST, POST, POST, POST, POST, POST, PUT, PUT, PUT, PUT, PUT, PUT, resources, single, status, TRACE, TRACE, TRACE, TRACE, TRACE, TRACE
-
Field Details
-
CAMEL_CASE_NAMING_STRATEGY
ARouteBuilder.UriNamingStrategy
whereby camel case conventions are used. -
LOG
protected static final org.slf4j.Logger LOG -
executionHandleLocator
-
uriNamingStrategy
-
conversionService
-
defaultCharset
-
-
Constructor Details
-
DefaultRouteBuilder
- Parameters:
executionHandleLocator
- The execution handler locator
-
DefaultRouteBuilder
public DefaultRouteBuilder(ExecutionHandleLocator executionHandleLocator, RouteBuilder.UriNamingStrategy uriNamingStrategy) - Parameters:
executionHandleLocator
- The execution handler locatoruriNamingStrategy
- The URI naming strategy
-
DefaultRouteBuilder
public DefaultRouteBuilder(ExecutionHandleLocator executionHandleLocator, RouteBuilder.UriNamingStrategy uriNamingStrategy, ConversionService conversionService) - Parameters:
executionHandleLocator
- The execution handler locatoruriNamingStrategy
- The URI naming strategyconversionService
- The conversion service
-
-
Method Details
-
getExposedPorts
- Specified by:
getExposedPorts
in interfaceRouteBuilder
- Returns:
- The exposed ports
-
getFilterRoutes
- Specified by:
getFilterRoutes
in interfaceRouteBuilder
- Returns:
- The filter routes
-
addFilter
public FilterRoute addFilter(String pathPattern, BeanLocator beanLocator, BeanDefinition<? extends HttpFilter> beanDefinition) Description copied from interface:RouteBuilder
Add a filter.- Specified by:
addFilter
in interfaceRouteBuilder
- Parameters:
pathPattern
- The path pattern for the filterbeanLocator
- The bean locatorbeanDefinition
- The bean definition- Returns:
- The
FilterRoute
-
getStatusRoutes
- Specified by:
getStatusRoutes
in interfaceRouteBuilder
- Returns:
- Obtain a list of constructed routes
-
getErrorRoutes
- Specified by:
getErrorRoutes
in interfaceRouteBuilder
- Returns:
- Obtain a list of constructed routes
-
getUriRoutes
- Specified by:
getUriRoutes
in interfaceRouteBuilder
- Returns:
- Obtain a list of constructed routes
-
getUriNamingStrategy
- Specified by:
getUriNamingStrategy
in interfaceRouteBuilder
- Returns:
- The URI naming strategy
-
resources
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 interfaceRouteBuilder
- Parameters:
cls
- The class- Returns:
- The
ResourceRoute
-
single
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 interfaceRouteBuilder
- 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 interfaceRouteBuilder
- Parameters:
originatingClass
- The class where the error originates fromstatus
- The status codetype
- The typemethod
- The methodparameterTypes
- 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 interfaceRouteBuilder
- Parameters:
status
- The status codetype
- The typemethod
- The methodparameterTypes
- 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 interfaceRouteBuilder
- Parameters:
originatingClass
- The class where the error originates fromerror
- The error typetype
- The type to route tomethod
- The method to route toparameterTypes
- 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 interfaceRouteBuilder
- Parameters:
error
- The errortype
- The typemethod
- The methodparameterTypes
- The parameter types for the target method- Returns:
- The route
-
GET
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 interfaceRouteBuilder
- Parameters:
uri
- The URItarget
- The targetmethod
- The methodparameterTypes
- The parameter types for the target method- Returns:
- The route
-
GET
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 interfaceRouteBuilder
- Parameters:
uri
- The URItype
- The typemethod
- The methodparameterTypes
- The parameter types for the target method- Returns:
- The route
-
POST
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 interfaceRouteBuilder
- Parameters:
uri
- The URItarget
- The targetmethod
- The methodparameterTypes
- The parameter types for the target method- Returns:
- The route
-
POST
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 interfaceRouteBuilder
- Parameters:
uri
- The URItype
- The typemethod
- The methodparameterTypes
- The parameter types for the target method- Returns:
- The route
-
PUT
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 interfaceRouteBuilder
- Parameters:
uri
- The URItarget
- The targetmethod
- The methodparameterTypes
- The parameter types for the target method- Returns:
- The route
-
PUT
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 interfaceRouteBuilder
- Parameters:
uri
- The URItype
- The typemethod
- The methodparameterTypes
- The parameter types for the target method- Returns:
- The route
-
PATCH
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 interfaceRouteBuilder
- Parameters:
uri
- The URItarget
- The targetmethod
- The methodparameterTypes
- The parameter types for the target method- Returns:
- The route
-
PATCH
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 interfaceRouteBuilder
- Parameters:
uri
- The URItype
- The typemethod
- The methodparameterTypes
- The parameter types for the target method- Returns:
- The route
-
DELETE
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 interfaceRouteBuilder
- Parameters:
uri
- The URItarget
- The targetmethod
- The methodparameterTypes
- The parameter types for the target method- Returns:
- The route
-
DELETE
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 interfaceRouteBuilder
- Parameters:
uri
- The URItype
- The typemethod
- The methodparameterTypes
- The parameter types for the target method- Returns:
- The route
-
OPTIONS
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 interfaceRouteBuilder
- Parameters:
uri
- The URItarget
- The targetmethod
- The methodparameterTypes
- The parameter types for the target method- Returns:
- The route
-
OPTIONS
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 interfaceRouteBuilder
- Parameters:
uri
- The URItype
- The typemethod
- The methodparameterTypes
- The parameter types for the target method- Returns:
- The route
-
HEAD
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 interfaceRouteBuilder
- Parameters:
uri
- The URItarget
- The targetmethod
- The methodparameterTypes
- The parameter types for the target method- Returns:
- The route
-
HEAD
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 interfaceRouteBuilder
- Parameters:
uri
- The URItype
- The typemethod
- The methodparameterTypes
- The parameter types for the target method- Returns:
- The route
-
TRACE
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 interfaceRouteBuilder
- Parameters:
uri
- The URItarget
- The targetmethod
- The methodparameterTypes
- The parameter types for the target method- Returns:
- The route
-
TRACE
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 interfaceRouteBuilder
- Parameters:
uri
- The URItype
- The typemethod
- The methodparameterTypes
- The parameter types for the target method- Returns:
- The route
-
GET
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 interfaceRouteBuilder
- Parameters:
uri
- The URIbeanDefinition
- The bean definitionmethod
- The method- Returns:
- The route
-
POST
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 interfaceRouteBuilder
- Parameters:
uri
- The URIbeanDefinition
- The bean definitionmethod
- The method- Returns:
- The route
-
PUT
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 interfaceRouteBuilder
- Parameters:
uri
- The URIbeanDefinition
- The bean definitionmethod
- The method- Returns:
- The route
-
PATCH
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 interfaceRouteBuilder
- Parameters:
uri
- The URIbeanDefinition
- The bean definitionmethod
- The method- Returns:
- The route
-
DELETE
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 interfaceRouteBuilder
- Parameters:
uri
- The URIbeanDefinition
- The bean definitionmethod
- The method- Returns:
- The route
-
OPTIONS
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 interfaceRouteBuilder
- Parameters:
uri
- The URIbeanDefinition
- The bean definitionmethod
- The method- Returns:
- The route
-
HEAD
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 interfaceRouteBuilder
- Parameters:
uri
- The URIbeanDefinition
- The bean definitionmethod
- The method- Returns:
- The route
-
TRACE
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 interfaceRouteBuilder
- Parameters:
uri
- The URIbeanDefinition
- The bean definitionmethod
- 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 methoduri
- The URItype
- The typemethod
- The methodparameterTypes
- Parameters- Returns:
- an
UriRoute
-
buildRoute
protected UriRoute buildRoute(HttpMethod httpMethod, String uri, MethodExecutionHandle<Object, Object> executableHandle) Build a route.- Parameters:
httpMethod
- The HTTP methoduri
- The URIexecutableHandle
- The executable handle- Returns:
- an
UriRoute
-
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 matchesEnum.name()
httpMethod
- The http method. IsHttpMethod.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.
-