public class SpincastRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>> extends Object implements IRouter<R,W>
| Modifier and Type | Field and Description |
|---|---|
protected org.slf4j.Logger |
logger |
DEFAULT_ROUTE_PATH| Constructor and Description |
|---|
SpincastRouter(ISpincastRouterConfig spincastRouterConfig,
IRouteFactory<R> routeFactory,
ISpincastConfig spincastConfig,
ISpincastDictionary spincastDictionary,
IServer server,
ISpincastFilters<R> spincastFilters,
IRouteBuilderFactory<R,W> routeBuilderFactory,
IStaticResourceBuilderFactory<R,W> staticResourceBuilderFactory,
IRouteHandlerMatchFactory<R> routeHandlerMatchFactory,
IStaticResourceFactory<R> staticResourceFactory,
IWebsocketRouteBuilderFactory<R,W> websocketRouteBuilderFactory,
IWebsocketRouteHandlerFactory<R,W> websocketRouteHandlerFactory) |
| Modifier and Type | Method and Description |
|---|---|
protected IRouteBuilder<R> |
addFilterDefaultRoutingTypes(IRouteBuilder<R> builder) |
void |
addRoute(IRoute<R> route) |
void |
addRouteParamPatternAlias(String alias,
String pattern) |
void |
addStaticResource(IStaticResource<R> staticResource) |
void |
addWebsocketRoute(IWebsocketRoute<R,W> websocketRoute) |
void |
after(IHandler<R> handler) |
void |
after(String path,
IHandler<R> handler) |
IRouteBuilder<R> |
ALL(String path) |
void |
before(IHandler<R> handler) |
void |
before(String path,
IHandler<R> handler) |
void |
beforeAndAfter(IHandler<R> handler) |
void |
beforeAndAfter(String path,
IHandler<R> handler) |
void |
cors() |
void |
cors(Set<String> allowedOrigins) |
void |
cors(Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead) |
void |
cors(Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent) |
void |
cors(Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent,
boolean allowCookies) |
void |
cors(Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent,
boolean allowCookies,
Set<HttpMethod> allowedMethods) |
void |
cors(Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent,
boolean allowCookies,
Set<HttpMethod> allowedMethods,
int maxAgeInSeconds) |
void |
cors(String path) |
void |
cors(String path,
Set<String> allowedOrigins) |
void |
cors(String path,
Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead) |
void |
cors(String path,
Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent) |
void |
cors(String path,
Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent,
boolean allowCookies) |
void |
cors(String path,
Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent,
boolean allowCookies,
Set<HttpMethod> allowedMethods) |
void |
cors(String path,
Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent,
boolean allowCookies,
Set<HttpMethod> allowedMethods,
int maxAgeInSeconds) |
protected IRouteHandlerMatch<R> |
createHandlerMatchForBeforeOrAfterFilter(IRouteHandlerMatch<R> mainRouteHandlerMatch,
IHandler<R> beforeOrAfterMethod,
int position)
Creates a new match for a "before" or "after" handler specific
to a route.
|
protected IRoute<R> |
createHttpRouteFromWebsocketRoute(IWebsocketRoute<R,W> websocketRoute) |
protected IRouteHandlerMatch<R> |
createNoMatchingParamsHandlerMatch(IRoute<R> route,
String id,
IHandler<R> handler,
int position)
Creates an handler match with no matching params.
|
protected List<IRouteHandlerMatch<R>> |
createRegularHandlerMatches(RoutingType routingType,
IRoute<R> route,
HttpMethod httpMethod,
List<String> acceptedContentTypes,
URL url,
int position)
Get the matches (filters and main handle) if the route matches the URL and
HTTP method, or returns NULL otherwise.
|
protected IRoutingResult<R> |
createRoutingResult(List<IRouteHandlerMatch<R>> routeHandlerMatches) |
IRouteBuilder<R> |
DELETE(String path) |
IStaticResourceBuilder<R> |
dir(String url) |
void |
exception(IHandler<R> handler) |
void |
exception(String path,
IHandler<R> handler) |
IStaticResourceBuilder<R> |
file(String url) |
IRouteBuilder<R> |
GET(String path) |
protected Map<Integer,List<IRoute<R>>> |
getGlobalAfterFiltersPerPosition() |
List<IRoute<R>> |
getGlobalAfterFiltersRoutes() |
protected Map<Integer,List<IRoute<R>>> |
getGlobalBeforeFiltersPerPosition() |
List<IRoute<R>> |
getGlobalBeforeFiltersRoutes() |
List<IRoute<R>> |
getMainRoutes() |
protected Pattern |
getPattern(String patternStr) |
protected String |
getPatternFromAlias(String alias)
Get a path pattern from its alias.
|
IRoute<R> |
getRoute(String routeId) |
protected IRouteBuilderFactory<R,W> |
getRouteBuilderFactory() |
protected IRouteFactory<R> |
getRouteFactory() |
protected IRouteHandlerMatchFactory<R> |
getRouteHandlerMatchFactory() |
Map<String,String> |
getRouteParamPatternAliases() |
protected IServer |
getServer() |
protected ISpincastConfig |
getSpincastConfig() |
protected ISpincastDictionary |
getSpincastDictionary() |
protected ISpincastFilters<R> |
getSpincastFilters() |
protected ISpincastRouterConfig |
getSpincastRouterConfig() |
protected IStaticResourceBuilderFactory<R,W> |
getStaticResourceBuilderFactory() |
protected IStaticResourceFactory<R> |
getStaticResourceFactory() |
protected IWebsocketRouteBuilderFactory<R,W> |
getWebsocketRouteBuilderFactory() |
protected IWebsocketRouteHandlerFactory<R,W> |
getWebsocketRouteHandlerFactory() |
IRouteBuilder<R> |
HEAD(String path) |
void |
httpAuth(String pathPrefix,
String realmName) |
protected void |
init() |
protected boolean |
isRouteMatchAcceptedContentType(IRoute<R> route,
List<String> requestContentTypes) |
protected boolean |
isRouteMatchHttpMethod(IRoute<R> route,
HttpMethod httpMethod)
Validate if a route matches the given HTTP method.
|
protected boolean |
isRoutingTypeMatch(RoutingType routingType,
IRoute<R> route) |
void |
notFound(IHandler<R> handler) |
void |
notFound(String path,
IHandler<R> handler) |
IRouteBuilder<R> |
OPTIONS(String path) |
IRouteBuilder<R> |
PATCH(String path) |
IRouteBuilder<R> |
POST(String path) |
IRouteBuilder<R> |
PUT(String path) |
void |
removeAllRoutes() |
void |
removeRoute(String routeId) |
IRoutingResult<R> |
route(R requestContext) |
IRoutingResult<R> |
route(R requestContext,
RoutingType routingType) |
IRoutingResult<R> |
route(R requestContext,
String fullUrl,
RoutingType routingType) |
IRouteBuilder<R> |
SOME(String path,
HttpMethod... httpMethods) |
IRouteBuilder<R> |
SOME(String path,
Set<HttpMethod> httpMethods) |
IRouteBuilder<R> |
TRACE(String path) |
protected void |
validateId(String id) |
protected void |
validatePath(String path)
Validate the path of a route.
|
protected Map<String,String> |
validatePath(String routePath,
URL url)
Validate if url matches the path of the route and if so, returns the
parsed parameters, if any.
|
protected void |
validation() |
IWebsocketRouteBuilder<R,W> |
websocket(String path) |
@Inject public SpincastRouter(ISpincastRouterConfig spincastRouterConfig, IRouteFactory<R> routeFactory, ISpincastConfig spincastConfig, ISpincastDictionary spincastDictionary, IServer server, ISpincastFilters<R> spincastFilters, IRouteBuilderFactory<R,W> routeBuilderFactory, IStaticResourceBuilderFactory<R,W> staticResourceBuilderFactory, IRouteHandlerMatchFactory<R> routeHandlerMatchFactory, IStaticResourceFactory<R> staticResourceFactory, IWebsocketRouteBuilderFactory<R,W> websocketRouteBuilderFactory, IWebsocketRouteHandlerFactory<R,W> websocketRouteHandlerFactory)
@Inject protected void init()
protected void validation()
protected ISpincastRouterConfig getSpincastRouterConfig()
protected IRouteFactory<R> getRouteFactory()
protected ISpincastConfig getSpincastConfig()
protected ISpincastDictionary getSpincastDictionary()
protected IServer getServer()
protected ISpincastFilters<R> getSpincastFilters()
protected IRouteBuilderFactory<R,W> getRouteBuilderFactory()
protected IWebsocketRouteBuilderFactory<R,W> getWebsocketRouteBuilderFactory()
protected IWebsocketRouteHandlerFactory<R,W> getWebsocketRouteHandlerFactory()
protected IStaticResourceBuilderFactory<R,W> getStaticResourceBuilderFactory()
protected IRouteHandlerMatchFactory<R> getRouteHandlerMatchFactory()
protected IStaticResourceFactory<R> getStaticResourceFactory()
public Map<String,String> getRouteParamPatternAliases()
getRouteParamPatternAliases in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public IRoute<R> getRoute(String routeId)
getRoute in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>protected Map<Integer,List<IRoute<R>>> getGlobalBeforeFiltersPerPosition()
public List<IRoute<R>> getGlobalBeforeFiltersRoutes()
getGlobalBeforeFiltersRoutes in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>protected Map<Integer,List<IRoute<R>>> getGlobalAfterFiltersPerPosition()
public List<IRoute<R>> getGlobalAfterFiltersRoutes()
getGlobalAfterFiltersRoutes in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public List<IRoute<R>> getMainRoutes()
getMainRoutes in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void addRoute(IRoute<R> route)
addRoute in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>protected void validateId(String id)
protected void validatePath(String path)
public void removeAllRoutes()
removeAllRoutes in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void removeRoute(String routeId)
removeRoute in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public IRoutingResult<R> route(R requestContext)
route in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public IRoutingResult<R> route(R requestContext, RoutingType routingType)
route in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public IRoutingResult<R> route(R requestContext, String fullUrl, RoutingType routingType)
protected boolean isRoutingTypeMatch(RoutingType routingType, IRoute<R> route)
protected IRoutingResult<R> createRoutingResult(List<IRouteHandlerMatch<R>> routeHandlerMatches)
protected List<IRouteHandlerMatch<R>> createRegularHandlerMatches(RoutingType routingType, IRoute<R> route, HttpMethod httpMethod, List<String> acceptedContentTypes, URL url, int position)
protected boolean isRouteMatchAcceptedContentType(IRoute<R> route, List<String> requestContentTypes)
protected IRouteHandlerMatch<R> createNoMatchingParamsHandlerMatch(IRoute<R> route, String id, IHandler<R> handler, int position)
protected IRouteHandlerMatch<R> createHandlerMatchForBeforeOrAfterFilter(IRouteHandlerMatch<R> mainRouteHandlerMatch, IHandler<R> beforeOrAfterMethod, int position)
protected boolean isRouteMatchHttpMethod(IRoute<R> route, HttpMethod httpMethod)
protected Map<String,String> validatePath(String routePath, URL url)
protected String getPatternFromAlias(String alias)
public void addRouteParamPatternAlias(String alias, String pattern)
addRouteParamPatternAlias in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public IRouteBuilder<R> GET(String path)
GET in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public IRouteBuilder<R> POST(String path)
POST in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public IRouteBuilder<R> PUT(String path)
PUT in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public IRouteBuilder<R> DELETE(String path)
DELETE in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public IRouteBuilder<R> OPTIONS(String path)
OPTIONS in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public IRouteBuilder<R> TRACE(String path)
TRACE in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public IRouteBuilder<R> HEAD(String path)
HEAD in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public IRouteBuilder<R> PATCH(String path)
PATCH in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public IRouteBuilder<R> ALL(String path)
ALL in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public IRouteBuilder<R> SOME(String path, HttpMethod... httpMethods)
SOME in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public IRouteBuilder<R> SOME(String path, Set<HttpMethod> httpMethods)
SOME in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void before(IHandler<R> handler)
before in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void before(String path, IHandler<R> handler)
before in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void after(IHandler<R> handler)
after in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void after(String path, IHandler<R> handler)
after in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void beforeAndAfter(IHandler<R> handler)
beforeAndAfter in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void beforeAndAfter(String path, IHandler<R> handler)
beforeAndAfter in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>protected IRouteBuilder<R> addFilterDefaultRoutingTypes(IRouteBuilder<R> builder)
public void exception(IHandler<R> handler)
exception in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void exception(String path, IHandler<R> handler)
exception in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void notFound(IHandler<R> handler)
notFound in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void notFound(String path, IHandler<R> handler)
notFound in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void cors()
cors in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void cors(Set<String> allowedOrigins)
cors in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead)
cors in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent)
cors in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies)
cors in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods)
cors in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods, int maxAgeInSeconds)
cors in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void cors(String path)
cors in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void cors(String path, Set<String> allowedOrigins)
cors in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void cors(String path, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead)
cors in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void cors(String path, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent)
cors in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void cors(String path, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies)
cors in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void cors(String path, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods)
cors in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void cors(String path, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods, int maxAgeInSeconds)
cors in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public IStaticResourceBuilder<R> file(String url)
file in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public IStaticResourceBuilder<R> dir(String url)
dir in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void addStaticResource(IStaticResource<R> staticResource)
addStaticResource in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void httpAuth(String pathPrefix, String realmName)
httpAuth in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public IWebsocketRouteBuilder<R,W> websocket(String path)
websocket in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>public void addWebsocketRoute(IWebsocketRoute<R,W> websocketRoute)
addWebsocketRoute in interface IRouter<R extends IRequestContext<?>,W extends IWebsocketContext<?>>protected IRoute<R> createHttpRouteFromWebsocketRoute(IWebsocketRoute<R,W> websocketRoute)
Copyright © 2016. All rights reserved.