Package ai.preferred.venom
Class UrlRouter
- java.lang.Object
-
- ai.preferred.venom.UrlRouter
-
- All Implemented Interfaces:
HandlerRouter
,ValidatorRouter
public class UrlRouter extends 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 Handler
getHandler(Request request)
Returns the handler to be used for a specified request.Validator
getValidator(Request request)
Returns the handler to be used for a specified request.UrlRouter
register(Pattern urlPattern, Handler handler)
Adds a url pattern, and the handler to be used.UrlRouter
register(Pattern urlPattern, Handler handler, Validator validator)
Adds a url pattern, and the handler to be used.UrlRouter
register(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(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(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(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:HandlerRouter
Returns 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:
getHandler
in interfaceHandlerRouter
- Parameters:
request
- request made- Returns:
- the instance of handler to be used
-
getValidator
public final Validator getValidator(Request request)
Description copied from interface:ValidatorRouter
Returns 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:
getValidator
in interfaceValidatorRouter
- Parameters:
request
- request made- Returns:
- the instance of handler to be used
-
-