Package ai.preferred.venom
Class UrlRouter
- java.lang.Object
-
- ai.preferred.venom.UrlRouter
-
- All Implemented Interfaces:
HandlerRouter,ValidatorRouter
public class UrlRouter extends java.lang.Object implements HandlerRouter, ValidatorRouter
This class provides an implementation to select a handler based on the url from which they were fetched.- Author:
- Maksim Tkachenko, Ween Jiann Lee
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HandlergetHandler(Request request)Returns the handler to be used for a specified request.ValidatorgetValidator(Request request)Returns the handler to be used for a specified request.UrlRouterregister(java.util.regex.Pattern urlPattern, Handler handler)Adds a url pattern, and the handler to be used.UrlRouterregister(java.util.regex.Pattern urlPattern, Handler handler, Validator validator)Adds a url pattern, and the handler to be used.UrlRouterregister(java.util.regex.Pattern urlPattern, Validator validator)Adds a url pattern, and the handler to be used.
-
-
-
Constructor Detail
-
UrlRouter
public UrlRouter()
Constructs a url router without default handler.
-
UrlRouter
public UrlRouter(Handler defaultHandler)
Constructs a url router with default handler.- Parameters:
defaultHandler- default handler
-
-
Method Detail
-
register
public final UrlRouter register(java.util.regex.Pattern urlPattern, Handler handler)
Adds a url pattern, and the handler to be used.Please note that the pattern must be an exact match of the url to work.
- Parameters:
urlPattern- regex pattern of the url.handler- handler to which the fetched page should use.- Returns:
- this.
-
register
public final UrlRouter register(java.util.regex.Pattern urlPattern, Validator validator)
Adds a url pattern, and the handler to be used.Please note that the pattern must be an exact match of the url to work.
- Parameters:
urlPattern- regex pattern of the url.validator- validator to which the fetched page should use.- Returns:
- this.
-
register
public final UrlRouter register(java.util.regex.Pattern urlPattern, Handler handler, Validator validator)
Adds a url pattern, and the handler to be used.Please note that the pattern must be an exact match of the url to work.
- Parameters:
urlPattern- regex pattern of the url.handler- handler to which the fetched page should use.validator- validator to which the fetched page should use.- Returns:
- this.
-
getHandler
public final Handler getHandler(Request request)
Description copied from interface:HandlerRouterReturns the handler to be used for a specified request.This will only be used if a handler is not specified in when added to scheduler.
- Specified by:
getHandlerin interfaceHandlerRouter- Parameters:
request- request made- Returns:
- the instance of handler to be used
-
getValidator
public final Validator getValidator(Request request)
Description copied from interface:ValidatorRouterReturns the handler to be used for a specified request.This will only be used if a handler is not specified in when added to scheduler
- Specified by:
getValidatorin interfaceValidatorRouter- Parameters:
request- request made- Returns:
- the instance of handler to be used
-
-