@ -30,36 +30,36 @@ import org.springframework.web.server.adapter.HttpWebHandlerAdapter;
@@ -30,36 +30,36 @@ import org.springframework.web.server.adapter.HttpWebHandlerAdapter;
/ * *
* < strong > Central entry point to Spring ' s functional web framework . < / strong >
* Exposes routing functionality , such as to
* { @linkplain # route ( RequestPredicate , HandlerFunction ) create } a { @code Routing Function } given a
* { @linkplain # route ( RequestPredicate , HandlerFunction ) create } a { @code Router Function } given a
* { @code RequestPredicate } and { @code HandlerFunction } , and to do further
* { @linkplain # subroute ( RequestPredicate , Routing Function ) subrouting } on an existing routing
* { @linkplain # subroute ( RequestPredicate , Router Function ) subrouting } on an existing routing
* function .
*
* < p > Additionally , this class can { @linkplain # toHttpHandler ( Routing Function ) transform } a
* { @code Routing Function } into an { @code HttpHandler } , which can be run in Servlet 3 . 1 + ,
* < p > Additionally , this class can { @linkplain # toHttpHandler ( Router Function ) transform } a
* { @code Router Function } into an { @code HttpHandler } , which can be run in Servlet 3 . 1 + ,
* Reactor , RxNetty , or Undertow .
* And it can { @linkplain # toHandlerMapping ( Routing Function , Configuration ) transform } a
* { @code Routing Function } into an { @code HandlerMapping } , which can be run in a
* And it can { @linkplain # toHandlerMapping ( Router Function , Configuration ) transform } a
* { @code Router Function } into an { @code HandlerMapping } , which can be run in a
* { @code DispatcherHandler } .
*
* @author Arjen Poutsma
* @since 5 . 0
*
* /
public abstract class Routing Functions {
public abstract class Router Functions {
private static final HandlerFunction < Void > NOT_FOUND_HANDLER = request - > Response . notFound ( ) . build ( ) ;
/ * *
* Name of the { @link ServerWebExchange } attribute that contains the { @link Request } .
* /
public static final String REQUEST_ATTRIBUTE = Routing Functions . class . getName ( ) + ".request" ;
public static final String REQUEST_ATTRIBUTE = Router Functions . class . getName ( ) + ".request" ;
/ * *
* Name of the { @link ServerWebExchange } attribute that contains the URI
* templates map , mapping variable names to values .
* /
public static final String URI_TEMPLATE_VARIABLES_ATTRIBUTE = Routing Functions . class . getName ( ) + ".uriTemplateVariables" ;
public static final String URI_TEMPLATE_VARIABLES_ATTRIBUTE = Router Functions . class . getName ( ) + ".uriTemplateVariables" ;
/ * *
* Route to the given handler function if the given request predicate applies .
@ -70,7 +70,7 @@ public abstract class RoutingFunctions {
@@ -70,7 +70,7 @@ public abstract class RoutingFunctions {
* @return a routing function that routes to { @code handlerFunction } if { @code predicate } evaluates to { @code true }
* @see RequestPredicates
* /
public static < T > Routing Function < T > route ( RequestPredicate predicate , HandlerFunction < T > handlerFunction ) {
public static < T > Router Function < T > route ( RequestPredicate predicate , HandlerFunction < T > handlerFunction ) {
Assert . notNull ( predicate , "'predicate' must not be null" ) ;
Assert . notNull ( handlerFunction , "'handlerFunction' must not be null" ) ;
@ -81,19 +81,19 @@ public abstract class RoutingFunctions {
@@ -81,19 +81,19 @@ public abstract class RoutingFunctions {
* Route to the given routing function if the given request predicate applies .
*
* @param predicate the predicate to test
* @param routing Function the routing function to route to
* @param router Function the routing function to route to
* @param < T > the type of the handler function
* @return a routing function that routes to { @code routing Function } if { @code predicate } evaluates to { @code true }
* @return a routing function that routes to { @code router Function } if { @code predicate } evaluates to { @code true }
* @see RequestPredicates
* /
public static < T > Routing Function < T > subroute ( RequestPredicate predicate , Routing Function < T > routing Function ) {
public static < T > Router Function < T > subroute ( RequestPredicate predicate , Router Function < T > router Function ) {
Assert . notNull ( predicate , "'predicate' must not be null" ) ;
Assert . notNull ( routingFunction , "'routing Function' must not be null" ) ;
Assert . notNull ( routerFunction , "'router Function' must not be null" ) ;
return request - > {
if ( predicate . test ( request ) ) {
Request subRequest = predicate . subRequest ( request ) ;
return routing Function . route ( subRequest ) ;
return router Function . route ( subRequest ) ;
}
else {
return Optional . empty ( ) ;
@ -102,7 +102,7 @@ public abstract class RoutingFunctions {
@@ -102,7 +102,7 @@ public abstract class RoutingFunctions {
}
/ * *
* Converts the given { @linkplain Routing Function routing function } into a { @link HttpHandler } .
* Converts the given { @linkplain Router Function routing function } into a { @link HttpHandler } .
* This conversion uses the { @linkplain Configuration # builder ( ) default configuration } .
*
* < p > The returned { @code HttpHandler } can be adapted to run in
@ -117,15 +117,15 @@ public abstract class RoutingFunctions {
@@ -117,15 +117,15 @@ public abstract class RoutingFunctions {
* { @link org . springframework . http . server . reactive . UndertowHttpHandlerAdapter } . < / li >
* < / ul >
*
* @param routing Function the routing function to convert
* @param router Function the routing function to convert
* @return an http handler that handles HTTP request using the given routing function
* /
public static HttpHandler toHttpHandler ( Routing Function < ? > routing Function ) {
return toHttpHandler ( routing Function , defaultConfiguration ( ) ) ;
public static HttpHandler toHttpHandler ( Router Function < ? > router Function ) {
return toHttpHandler ( router Function , defaultConfiguration ( ) ) ;
}
/ * *
* Converts the given { @linkplain Routing Function routing function } into a { @link HttpHandler } ,
* Converts the given { @linkplain Router Function routing function } into a { @link HttpHandler } ,
* using the given configuration .
*
* < p > The returned { @code HttpHandler } can be adapted to run in
@ -140,61 +140,61 @@ public abstract class RoutingFunctions {
@@ -140,61 +140,61 @@ public abstract class RoutingFunctions {
* { @link org . springframework . http . server . reactive . UndertowHttpHandlerAdapter } . < / li >
* < / ul >
*
* @param routing Function the routing function to convert
* @param router Function the routing function to convert
* @param configuration the configuration to use
* @return an http handler that handles HTTP request using the given routing function
* /
public static HttpHandler toHttpHandler ( Routing Function < ? > routing Function , Configuration configuration ) {
Assert . notNull ( routingFunction , "'routing Function' must not be null" ) ;
public static HttpHandler toHttpHandler ( Router Function < ? > router Function , Configuration configuration ) {
Assert . notNull ( routerFunction , "'router Function' must not be null" ) ;
Assert . notNull ( configuration , "'configuration' must not be null" ) ;
return new HttpWebHandlerAdapter ( exchange - > {
Request request = new DefaultRequest ( exchange , configuration ) ;
addAttributes ( exchange , request ) ;
HandlerFunction < ? > handlerFunction = routing Function . route ( request ) . orElse ( notFound ( ) ) ;
HandlerFunction < ? > handlerFunction = router Function . route ( request ) . orElse ( notFound ( ) ) ;
Response < ? > response = handlerFunction . handle ( request ) ;
return response . writeTo ( exchange , configuration ) ;
} ) ;
}
/ * *
* Converts the given { @code Routing Function } into a { @code HandlerMapping } .
* Converts the given { @code Router Function } into a { @code HandlerMapping } .
* This conversion uses the { @linkplain Configuration # builder ( ) default configuration } .
*
* < p > The returned { @code HandlerMapping } can be run in a
* { @link org . springframework . web . reactive . DispatcherHandler } .
*
* @param routing Function the routing function to convert
* @param router Function the routing function to convert
* @return an handler mapping that maps HTTP request to a handler using the given routing function
* @see org . springframework . web . reactive . function . support . HandlerFunctionAdapter
* @see org . springframework . web . reactive . function . support . ResponseResultHandler
* /
public static HandlerMapping toHandlerMapping ( Routing Function < ? > routing Function ) {
return toHandlerMapping ( routing Function , defaultConfiguration ( ) ) ;
public static HandlerMapping toHandlerMapping ( Router Function < ? > router Function ) {
return toHandlerMapping ( router Function , defaultConfiguration ( ) ) ;
}
/ * *
* Converts the given { @linkplain Routing Function routing function } into a { @link HandlerMapping }
* Converts the given { @linkplain Router Function routing function } into a { @link HandlerMapping }
* using the given configuration .
*
* < p > The returned { @code HandlerMapping } can be run in a
* { @link org . springframework . web . reactive . DispatcherHandler } .
*
* @param routing Function the routing function to convert
* @param router Function the routing function to convert
* @return an handler mapping that maps HTTP request to a handler using the given routing function
* @see org . springframework . web . reactive . function . support . HandlerFunctionAdapter
* @see org . springframework . web . reactive . function . support . ResponseResultHandler
* /
public static HandlerMapping toHandlerMapping ( Routing Function < ? > routing Function , Configuration configuration ) {
Assert . notNull ( routingFunction , "'routing Function' must not be null" ) ;
public static HandlerMapping toHandlerMapping ( Router Function < ? > router Function , Configuration configuration ) {
Assert . notNull ( routerFunction , "'router Function' must not be null" ) ;
Assert . notNull ( configuration , "'configuration' must not be null" ) ;
return exchange - > {
Request request = new DefaultRequest ( exchange , configuration ) ;
addAttributes ( exchange , request ) ;
Optional < ? extends HandlerFunction < ? > > route = routing Function . route ( request ) ;
Optional < ? extends HandlerFunction < ? > > route = router Function . route ( request ) ;
return Mono . justOrEmpty ( route ) ;
} ;
}