public class SpincastRouter<R extends RequestContext<?>,W extends WebsocketContext<?>> extends Object implements Router<R,W>
| Modifier and Type | Field and Description |
|---|---|
protected org.slf4j.Logger |
logger |
DEFAULT_ROUTE_PATH| Constructor and Description |
|---|
SpincastRouter(SpincastRouterDeps<R,W> spincastRouterDeps) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addDefaultFilters() |
void |
addRoute(Route<R> route) |
void |
addRouteParamPatternAlias(String alias,
String pattern) |
void |
addStaticResource(StaticResource<R> staticResource) |
void |
addWebsocketRoute(WebsocketRoute<R,W> websocketRoute) |
RouteBuilder<R> |
ALL() |
RouteBuilder<R> |
ALL(String path) |
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 RouteHandlerMatch<R> |
createHandlerMatchForBeforeOrAfterFilter(RouteHandlerMatch<R> mainRouteHandlerMatch,
Handler<R> beforeOrAfterMethod,
int position)
Creates a new match for a "before" or "after" handler specific
to a route.
|
protected Route<R> |
createHttpRouteFromWebsocketRoute(WebsocketRoute<R,W> websocketRoute) |
protected RouteHandlerMatch<R> |
createNoMatchingParamsHandlerMatch(Route<R> route,
String id,
Handler<R> handler,
int position)
Creates an handler match with no matching params.
|
protected List<RouteHandlerMatch<R>> |
createRegularHandlerMatches(RoutingType routingType,
Route<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 RoutingResult<R> |
createRoutingResult(List<RouteHandlerMatch<R>> routeHandlerMatches) |
RouteBuilder<R> |
DELETE() |
RouteBuilder<R> |
DELETE(String path) |
StaticResourceBuilder<R> |
dir(String url) |
void |
exception(Handler<R> handler) |
void |
exception(String path,
Handler<R> handler) |
StaticResourceBuilder<R> |
file(String url) |
RouteBuilder<R> |
GET() |
RouteBuilder<R> |
GET(String path) |
protected Dictionary |
getDictionary() |
protected Map<Integer,List<Route<R>>> |
getGlobalAfterFiltersPerPosition() |
List<Route<R>> |
getGlobalAfterFiltersRoutes() |
protected Map<Integer,List<Route<R>>> |
getGlobalBeforeFiltersPerPosition() |
List<Route<R>> |
getGlobalBeforeFiltersRoutes() |
List<Route<R>> |
getMainRoutes() |
protected Pattern |
getPattern(String patternStr) |
protected String |
getPatternFromAlias(String alias)
Get a path pattern from its alias.
|
protected RedirectRuleBuilderFactory<R,W> |
getRedirectRuleBuilderFactory() |
Route<R> |
getRoute(String routeId) |
protected RouteBuilderFactory<R,W> |
getRouteBuilderFactory() |
protected RouteFactory<R> |
getRouteFactory() |
protected RouteHandlerMatchFactory<R> |
getRouteHandlerMatchFactory() |
protected Set<String> |
getRouteIdsPrefixToKeepByDefaultWhenRemovingAll()
The route with ids starting with those prefixes won't be removed
by default when removeAllRoutes() is called without the
"delete all" parameter.
|
Map<String,String> |
getRouteParamPatternAliases() |
protected Server |
getServer() |
protected SpincastConfig |
getSpincastConfig() |
protected SpincastFilters<R> |
getSpincastFilters() |
protected SpincastRouterConfig |
getSpincastRouterConfig() |
protected SpincastRoutingUtils |
getSpincastRoutingUtils() |
protected StaticResourceBuilderFactory<R,W> |
getStaticResourceBuilderFactory() |
protected StaticResourceFactory<R> |
getStaticResourceFactory() |
protected WebsocketRouteBuilderFactory<R,W> |
getWebsocketRouteBuilderFactory() |
protected WebsocketRouteHandlerFactory<R,W> |
getWebsocketRouteHandlerFactory() |
RouteBuilder<R> |
HEAD() |
RouteBuilder<R> |
HEAD(String path) |
void |
httpAuth(String pathPrefix,
String realmName) |
protected void |
init() |
protected boolean |
isCreateStaticResourceOnDisk() |
protected boolean |
isRouteMatchAcceptedContentType(Route<R> route,
List<String> requestContentTypes) |
protected boolean |
isRouteMatchHttpMethod(Route<R> route,
HttpMethod httpMethod)
Validate if a route matches the given HTTP method.
|
protected boolean |
isRoutingTypeMatch(RoutingType routingType,
Route<R> route) |
void |
notFound(Handler<R> handler) |
void |
notFound(String path,
Handler<R> handler) |
RouteBuilder<R> |
OPTIONS() |
RouteBuilder<R> |
OPTIONS(String path) |
RouteBuilder<R> |
PATCH() |
RouteBuilder<R> |
PATCH(String path) |
RouteBuilder<R> |
POST() |
RouteBuilder<R> |
POST(String path) |
RouteBuilder<R> |
PUT() |
RouteBuilder<R> |
PUT(String path) |
RedirectRuleBuilder |
redirect(String oldPath) |
void |
removeAllRoutes() |
void |
removeAllRoutes(boolean removeSpincastRoutesToo) |
void |
removeRoute(String routeId) |
RoutingResult<R> |
route(R requestContext) |
RoutingResult<R> |
route(R requestContext,
RoutingType routingType) |
RoutingResult<R> |
route(R requestContext,
String fullUrl,
RoutingType routingType) |
RouteBuilder<R> |
SOME(HttpMethod... httpMethods) |
RouteBuilder<R> |
SOME(Set<HttpMethod> httpMethods) |
RouteBuilder<R> |
SOME(String path,
HttpMethod... httpMethods) |
RouteBuilder<R> |
SOME(String path,
Set<HttpMethod> httpMethods) |
protected boolean |
startsWithAnyOf(String id,
Set<String> prefixes) |
RouteBuilder<R> |
TRACE() |
RouteBuilder<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() |
WebsocketRouteBuilder<R,W> |
websocket(String path) |
@Inject public SpincastRouter(SpincastRouterDeps<R,W> spincastRouterDeps)
@Inject protected void init()
protected void validation()
protected void addDefaultFilters()
protected SpincastRouterConfig getSpincastRouterConfig()
protected RouteFactory<R> getRouteFactory()
protected SpincastConfig getSpincastConfig()
protected Dictionary getDictionary()
protected Server getServer()
protected SpincastFilters<R> getSpincastFilters()
protected RouteBuilderFactory<R,W> getRouteBuilderFactory()
protected RedirectRuleBuilderFactory<R,W> getRedirectRuleBuilderFactory()
protected WebsocketRouteBuilderFactory<R,W> getWebsocketRouteBuilderFactory()
protected WebsocketRouteHandlerFactory<R,W> getWebsocketRouteHandlerFactory()
protected StaticResourceBuilderFactory<R,W> getStaticResourceBuilderFactory()
protected RouteHandlerMatchFactory<R> getRouteHandlerMatchFactory()
protected StaticResourceFactory<R> getStaticResourceFactory()
protected SpincastRoutingUtils getSpincastRoutingUtils()
public Map<String,String> getRouteParamPatternAliases()
getRouteParamPatternAliases in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public Route<R> getRoute(String routeId)
getRoute in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>protected Map<Integer,List<Route<R>>> getGlobalBeforeFiltersPerPosition()
public List<Route<R>> getGlobalBeforeFiltersRoutes()
getGlobalBeforeFiltersRoutes in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>protected Map<Integer,List<Route<R>>> getGlobalAfterFiltersPerPosition()
public List<Route<R>> getGlobalAfterFiltersRoutes()
getGlobalAfterFiltersRoutes in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public List<Route<R>> getMainRoutes()
getMainRoutes in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public void addRoute(Route<R> route)
addRoute in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>protected void validateId(String id)
protected void validatePath(String path)
public void removeAllRoutes()
removeAllRoutes in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public void removeAllRoutes(boolean removeSpincastRoutesToo)
removeAllRoutes in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>protected Set<String> getRouteIdsPrefixToKeepByDefaultWhenRemovingAll()
public void removeRoute(String routeId)
removeRoute in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RoutingResult<R> route(R requestContext)
route in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RoutingResult<R> route(R requestContext, RoutingType routingType)
route in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RoutingResult<R> route(R requestContext, String fullUrl, RoutingType routingType)
protected boolean isRoutingTypeMatch(RoutingType routingType, Route<R> route)
protected RoutingResult<R> createRoutingResult(List<RouteHandlerMatch<R>> routeHandlerMatches)
protected List<RouteHandlerMatch<R>> createRegularHandlerMatches(RoutingType routingType, Route<R> route, HttpMethod httpMethod, List<String> acceptedContentTypes, URL url, int position)
protected boolean isRouteMatchAcceptedContentType(Route<R> route, List<String> requestContentTypes)
protected RouteHandlerMatch<R> createNoMatchingParamsHandlerMatch(Route<R> route, String id, Handler<R> handler, int position)
protected RouteHandlerMatch<R> createHandlerMatchForBeforeOrAfterFilter(RouteHandlerMatch<R> mainRouteHandlerMatch, Handler<R> beforeOrAfterMethod, int position)
protected boolean isRouteMatchHttpMethod(Route<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 Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RouteBuilder<R> GET()
GET in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RouteBuilder<R> GET(String path)
GET in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RouteBuilder<R> POST()
POST in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RouteBuilder<R> POST(String path)
POST in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RouteBuilder<R> PUT()
PUT in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RouteBuilder<R> PUT(String path)
PUT in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RouteBuilder<R> DELETE()
DELETE in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RouteBuilder<R> DELETE(String path)
DELETE in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RouteBuilder<R> OPTIONS()
OPTIONS in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RouteBuilder<R> OPTIONS(String path)
OPTIONS in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RouteBuilder<R> TRACE()
TRACE in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RouteBuilder<R> TRACE(String path)
TRACE in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RouteBuilder<R> HEAD()
HEAD in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RouteBuilder<R> HEAD(String path)
HEAD in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RouteBuilder<R> PATCH()
PATCH in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RouteBuilder<R> PATCH(String path)
PATCH in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RouteBuilder<R> ALL()
ALL in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RouteBuilder<R> ALL(String path)
ALL in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RouteBuilder<R> SOME(HttpMethod... httpMethods)
SOME in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RouteBuilder<R> SOME(String path, HttpMethod... httpMethods)
SOME in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RouteBuilder<R> SOME(Set<HttpMethod> httpMethods)
SOME in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public RouteBuilder<R> SOME(String path, Set<HttpMethod> httpMethods)
SOME in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public void exception(Handler<R> handler)
exception in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public void exception(String path, Handler<R> handler)
exception in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public void notFound(Handler<R> handler)
notFound in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public void notFound(String path, Handler<R> handler)
notFound in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public void cors()
cors in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public void cors(Set<String> allowedOrigins)
cors in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public void cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead)
cors in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public void cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent)
cors in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public void cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies)
cors in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public void cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods)
cors in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public void cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods, int maxAgeInSeconds)
cors in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public void cors(String path)
cors in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public void cors(String path, Set<String> allowedOrigins)
cors in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public void cors(String path, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead)
cors in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public void cors(String path, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent)
cors in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public void cors(String path, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies)
cors in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public void cors(String path, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods)
cors in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public void cors(String path, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods, int maxAgeInSeconds)
cors in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public StaticResourceBuilder<R> file(String url)
file in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public StaticResourceBuilder<R> dir(String url)
dir in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public void addStaticResource(StaticResource<R> staticResource)
addStaticResource in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>protected boolean isCreateStaticResourceOnDisk()
public void httpAuth(String pathPrefix, String realmName)
httpAuth in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public WebsocketRouteBuilder<R,W> websocket(String path)
websocket in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>public void addWebsocketRoute(WebsocketRoute<R,W> websocketRoute)
addWebsocketRoute in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>protected Route<R> createHttpRouteFromWebsocketRoute(WebsocketRoute<R,W> websocketRoute)
public RedirectRuleBuilder redirect(String oldPath)
redirect in interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>Copyright © 2018. All rights reserved.