Package ninja
Class RouterImpl
- java.lang.Object
-
- ninja.RouterImpl
-
-
Constructor Summary
Constructors Constructor Description RouterImpl(com.google.inject.Injector injector, NinjaProperties ninjaProperties, WebSockets webSockets, com.google.inject.Provider<RouteBuilderImpl> routeBuilderImplProvider)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
compileRoutes()
Compile all the routes that have been registered with the router.RouteBuilder
DELETE()
RouteBuilder
GET()
String
getReverseRoute(Class<?> controllerClass, String controllerMethodName)
Retrieves the reverse route for this controllerClass and method.String
getReverseRoute(Class<?> controllerClass, String controllerMethodName, Object... parameterMap)
Retrieves the reverse route for this controllerClass and method.String
getReverseRoute(Class<?> controllerClass, String controllerMethodName, Map<String,Object> parameterMap)
Retrieves the reverse route for this controllerClass and method.String
getReverseRoute(Class<?> controllerClass, String controllerMethodName, Optional<Map<String,Object>> parameterMap)
Retrieves the reverse route for this controllerClass and method.String
getReverseRoute(MethodReference controllerMethodRef)
String
getReverseRoute(MethodReference controllerMethodRef, Object... parameterMap)
String
getReverseRoute(MethodReference controllerMethodRef, Map<String,Object> parameterMap)
String
getReverseRoute(MethodReference controllerMethodRef, Optional<Map<String,Object>> parameterMap)
Route
getRouteFor(String httpMethod, String uri)
Get the route for the given method and URIOptional<Route>
getRouteForControllerClassAndMethod(Class<?> controllerClass, String controllerMethodName)
List<Route>
getRoutes()
Returns the list of compiled routes.RouteBuilder
HEAD()
RouteBuilder
METHOD(String method)
To match any http method.RouteBuilder
OPTIONS()
RouteBuilder
POST()
RouteBuilder
PUT()
RouteBuilder
WS()
-
-
-
Constructor Detail
-
RouterImpl
@Inject public RouterImpl(com.google.inject.Injector injector, NinjaProperties ninjaProperties, WebSockets webSockets, com.google.inject.Provider<RouteBuilderImpl> routeBuilderImplProvider)
-
-
Method Detail
-
getRouteFor
public Route getRouteFor(String httpMethod, String uri)
Description copied from interface:Router
Get the route for the given method and URI- Specified by:
getRouteFor
in interfaceRouter
- Parameters:
httpMethod
- The methoduri
- The URI- Returns:
- The route
-
getReverseRoute
public String getReverseRoute(Class<?> controllerClass, String controllerMethodName)
Description copied from interface:Router
Retrieves the reverse route for this controllerClass and method. Does not work with routes that contain placeholders. UseRouter.getReverseRoute(Class, String, Map)
in that case- Specified by:
getReverseRoute
in interfaceRouter
- Parameters:
controllerClass
- The controllerClass e.g. ApplicationController.classcontrollerMethodName
- the methodName of the class e.g. "index"- Returns:
- The final url (without server, and without any prefixes)
-
getReverseRoute
public String getReverseRoute(Class<?> controllerClass, String controllerMethodName, Object... parameterMap)
Description copied from interface:Router
Retrieves the reverse route for this controllerClass and method. The map contains pairs of url parameters. Eg. a raw route like "/person/{id} will become /person/1 when the map contains a pair like "id, "1".- Specified by:
getReverseRoute
in interfaceRouter
- Parameters:
controllerClass
- The controllerClass e.g. ApplicationController.classcontrollerMethodName
- the methodName of the class e.g. "index"parameterMap
- The map containing pairs with replacements for placeholders. Always supply key and value pairs. Key as strings, Values as objects. To get the value "toString()" is called on the object. Make sure that works for your object or simply use a String. If the raw uri does not contain the placeholders they will be added as query parameters ?key=value&key2=value2 and so on- Returns:
- The final url (without server, and without any prefixes)
-
getReverseRoute
public String getReverseRoute(Class<?> controllerClass, String controllerMethodName, Map<String,Object> parameterMap)
Description copied from interface:Router
Retrieves the reverse route for this controllerClass and method. The map contains pairs of url parameters. Eg. a raw route like "/person/{id} will become /person/1 when the map contains a pair like "id, "1".- Specified by:
getReverseRoute
in interfaceRouter
- Parameters:
controllerClass
- The controllerClass e.g. ApplicationController.classcontrollerMethodName
- the methodName of the class e.g. "index"- Returns:
- The final url (without server, and without any prefixes)
-
getReverseRoute
public String getReverseRoute(Class<?> controllerClass, String controllerMethodName, Optional<Map<String,Object>> parameterMap)
Description copied from interface:Router
Retrieves the reverse route for this controllerClass and method. The map contains pairs of url parameters. Eg. a raw route like "/person/{id} will become /person/1 when the map contains a pair like "id, "1".- Specified by:
getReverseRoute
in interfaceRouter
parameterMap
- An optinal map containing pairs with replacements for placeholders. Always supply key and value pairs. Key as strings, Values as objects. To get the value "toString()" is called on the object. Make sure that works for your object or simply use a String. If the raw uri does not contain the placeholders they will be added as query parameters ?key=value&key2=value2 and so on- Returns:
- The final url (without server, and without any prefixes)
-
getReverseRoute
public String getReverseRoute(MethodReference controllerMethodRef)
- Specified by:
getReverseRoute
in interfaceRouter
-
getReverseRoute
public String getReverseRoute(MethodReference controllerMethodRef, Map<String,Object> parameterMap)
- Specified by:
getReverseRoute
in interfaceRouter
-
getReverseRoute
public String getReverseRoute(MethodReference controllerMethodRef, Object... parameterMap)
- Specified by:
getReverseRoute
in interfaceRouter
-
getReverseRoute
public String getReverseRoute(MethodReference controllerMethodRef, Optional<Map<String,Object>> parameterMap)
- Specified by:
getReverseRoute
in interfaceRouter
-
compileRoutes
public void compileRoutes()
Description copied from interface:Router
Compile all the routes that have been registered with the router. This should be called once, during initialization, before the application starts serving requests.- Specified by:
compileRoutes
in interfaceRouter
-
getRoutes
public List<Route> getRoutes()
Description copied from interface:Router
Returns the list of compiled routes.
-
GET
public RouteBuilder GET()
-
POST
public RouteBuilder POST()
-
PUT
public RouteBuilder PUT()
-
DELETE
public RouteBuilder DELETE()
-
OPTIONS
public RouteBuilder OPTIONS()
-
HEAD
public RouteBuilder HEAD()
-
WS
public RouteBuilder WS()
-
METHOD
public RouteBuilder METHOD(String method)
Description copied from interface:Router
To match any http method. E.g. METHOD("PROPFIND") would route PROPFIND methods.
-
-