public class RouteBuilderDefault<R extends RequestContext<?>,W extends WebsocketContext<?>> extends Object implements RouteBuilder<R>
| Modifier and Type | Field and Description |
|---|---|
protected static org.slf4j.Logger |
logger |
| Constructor and Description |
|---|
RouteBuilderDefault(RouteFactory<R> routeFactory,
SpincastRouterConfig spincastRouterConfig,
SpincastFilters<R> spincastFilters,
SpincastConfig spincastConfig) |
RouteBuilderDefault(Router<R,W> router,
RouteFactory<R> routeFactory,
SpincastRouterConfig spincastRouterConfig,
SpincastFilters<R> spincastFilters,
SpincastConfig spincastConfig) |
| Modifier and Type | Method and Description |
|---|---|
RouteBuilder<R> |
accept(ContentTypeDefaults... acceptedContentTypes)
Sets the accepted
Content-Types. |
RouteBuilder<R> |
accept(Set<ContentTypeDefaults> acceptedContentTypes)
Sets the accepted
Content-Types. |
RouteBuilder<R> |
acceptAsString(Set<String> acceptedContentTypes)
Sets the accepted
Content-Types. |
RouteBuilder<R> |
acceptAsString(String... acceptedContentTypes)
Sets the accepted
Content-Types. |
RouteBuilder<R> |
after(Handler<R> afterFilter)
Adds an "after" filter which will only be applied to this particular route.
|
RouteBuilder<R> |
ALL()
Adds all HTTP methods as being supported.
|
RouteBuilder<R> |
allRoutingTypes()
This route will be considered for all routing types.
|
RouteBuilder<R> |
before(Handler<R> beforeFilter)
Adds a "before" filter which will only be applied to this particular route.
|
RouteBuilder<R> |
cache()
Adds cache headers.
|
RouteBuilder<R> |
cache(int seconds)
Adds public cache headers.
|
RouteBuilder<R> |
cache(int seconds,
boolean isPrivate)
Adds cache headers.
|
RouteBuilder<R> |
cache(int seconds,
boolean isPrivate,
Integer secondsCdn)
Adds cache headers.
|
Route<R> |
create(Handler<R> mainHandler)
Creates and returns the route without adding it to
the router.
|
RouteBuilder<R> |
DELETE()
Adds
DELETE as a supported HTTP method. |
RouteBuilder<R> |
exception()
This route will be considered during an
Exception routing process. |
RouteBuilder<R> |
found()
This route will be considered during a
Found routing process. |
RouteBuilder<R> |
GET()
Addss
GET as a supported HTTP method. |
Set<String> |
getAcceptedContentTypes() |
List<Handler<R>> |
getAfterFilters() |
List<Handler<R>> |
getBeforeFilters() |
protected Integer |
getCacheCdnSecondsByDefault() |
protected int |
getCacheSecondsByDefault() |
Set<String> |
getFilterIdsToSkip() |
Set<HttpMethod> |
getHttpMethods() |
String |
getId() |
Handler<R> |
getMainHandler() |
String |
getPath() |
int |
getPosition() |
protected RouteFactory<R> |
getRouteFactory() |
protected Router<R,W> |
getRouter() |
Set<RoutingType> |
getRoutingTypes() |
Object |
getSpecs()
May be
null. |
Object[] |
getSpecsParameters() |
protected SpincastConfig |
getSpincastConfig() |
protected SpincastFilters<R> |
getSpincastFilters() |
protected SpincastRouterConfig |
getSpincastRouterConfig() |
void |
handle(Handler<R> mainHandler)
Creates the route and saves it to the router.
|
RouteBuilder<R> |
HEAD()
Adds
HEAD as a supported HTTP method. |
RouteBuilder<R> |
html()
Adds
application/html as an accepted Content-Type. |
RouteBuilder<R> |
id(String id)
An id that can be used to identify the route.
|
protected boolean |
isCachePrivateByDefault() |
boolean |
isSkipResources() |
boolean |
isSpecsIgnore() |
boolean |
isSpicastCoreRouteOrPluginRoute() |
RouteBuilder<R> |
json()
Adds
application/json as an accepted Content-Type. |
RouteBuilder<R> |
methods(HttpMethod... httpMethods)
Adds the specified HTTP methods as being supported.
|
RouteBuilder<R> |
methods(Set<HttpMethod> httpMethods)
Adds the specified HTTP methods as being supported.
|
RouteBuilder<R> |
noCache()
Automatically adds "no-cache" headers to the response.
|
RouteBuilder<R> |
notFound()
This route will be considered during a
Not Found routing process. |
RouteBuilder<R> |
OPTIONS()
Adds
OPTIONS as a supported HTTP method. |
RouteBuilder<R> |
PATCH()
Adds
PATCH as a supported HTTP method. |
RouteBuilder<R> |
path(String path)
The path of the route.
|
RouteBuilder<R> |
pos(int position)
The position of the handler.
|
RouteBuilder<R> |
POST()
Adds
POST as a supported HTTP method. |
RouteBuilder<R> |
PUT()
Adds
PUT as a supported HTTP method. |
RouteBuilder<R> |
skip(String filterId)
Skip a "before" and "after" filter for this route.
|
RouteBuilder<R> |
skipResourcesRequests()
Won't be applied if the request is for a resource
(
Route.isStaticResourceRoute()). |
RouteBuilder<R> |
specs(Object specs,
Object... parameters)
Generic method to provide specifications
for an endpoint.
|
RouteBuilder<R> |
specsIgnore()
When calling this method, the associated route won't
be part of the generated specs.
|
RouteBuilder<R> |
spicastCoreRouteOrPluginRoute()
This should only by called by *plugins*.
|
RouteBuilder<R> |
TRACE()
Adds
TRACE as a supported HTTP method. |
RouteBuilder<R> |
xml()
Adds
application/xml as an accepted Content-Type. |
public RouteBuilderDefault(RouteFactory<R> routeFactory, SpincastRouterConfig spincastRouterConfig, SpincastFilters<R> spincastFilters, SpincastConfig spincastConfig)
public RouteBuilderDefault(Router<R,W> router, RouteFactory<R> routeFactory, SpincastRouterConfig spincastRouterConfig, SpincastFilters<R> spincastFilters, SpincastConfig spincastConfig)
protected RouteFactory<R> getRouteFactory()
protected SpincastRouterConfig getSpincastRouterConfig()
protected SpincastFilters<R> getSpincastFilters()
protected SpincastConfig getSpincastConfig()
public String getId()
public boolean isSpicastCoreRouteOrPluginRoute()
public String getPath()
public int getPosition()
public boolean isSkipResources()
public Set<RoutingType> getRoutingTypes()
public Set<HttpMethod> getHttpMethods()
public Object getSpecs()
null.public boolean isSpecsIgnore()
public Object[] getSpecsParameters()
public RouteBuilder<R> id(String id)
RouteBuilderid in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> spicastCoreRouteOrPluginRoute()
RouteBuilder
When this method is called, the resulting route won't
be remove by default when the
Router.removeAllRoutes() method is used. The
Router.removeAllRoutes(boolean) with true
will have to be called to actually remove it.
This is useful during development, when an hotreload mecanism
is used to reload the Router without
restarting the application, when the application routes changed.
By default only the routes for which the
#isSpicastCoreRouteOrPluginRoute()
method has been called would then be reloaded.
spicastCoreRouteOrPluginRoute in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> pos(int position)
RouteBuilderIf "0", the handler is considered as the *main* handler. Only one main handler per request is run (the first one found)! The main handler is usually where the body of the response is created.
A route with a position less than "0" is considered as a "before" filter and will be run before the main handler. A route with a position greater than "0" is considered as an "after" filter and will be run after the main handler. All the matching before and after filters are run, from the lower position to the higher. If two filters have the same position, they will be run in order they have been added to the router.
Be especially careful with after filters since the response
may have been flushed at that time. For example,
after filters are run if a RedirectException
is thrown, but the response will then be closed!
If not specified, "0" is used.
pos in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> allRoutingTypes()
RouteBuilderallRoutingTypes in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> found()
RouteBuilderFound routing process.found in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> notFound()
RouteBuilderNot Found routing process.notFound in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> exception()
RouteBuilderException routing process.exception in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> before(Handler<R> beforeFilter)
RouteBuilderbefore in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> after(Handler<R> afterFilter)
RouteBuilderafter in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> acceptAsString(String... acceptedContentTypes)
RouteBuilderContent-Types.
This route will only be considered for requests specifying those
Content-Types as being accepted
(using the Accept header).acceptAsString in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> acceptAsString(Set<String> acceptedContentTypes)
RouteBuilderContent-Types.
This route will only be considered for requests specifying those
Content-Types as being accepted
(using the Accept header).acceptAsString in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> accept(ContentTypeDefaults... acceptedContentTypes)
RouteBuilderContent-Types.
This route will only be considered for requests specifying those
Content-Types as being accepted
(using the Accept header).accept in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> accept(Set<ContentTypeDefaults> acceptedContentTypes)
RouteBuilderContent-Types.
This route will only be considered for requests specifying those
Content-Types as being accepted
(using the Accept header).accept in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> html()
RouteBuilderapplication/html as an accepted Content-Type.html in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> json()
RouteBuilderapplication/json as an accepted Content-Type.json in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> xml()
RouteBuilderapplication/xml as an accepted Content-Type.xml in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> path(String path)
RouteBuilderpath in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> GET()
RouteBuilderGET as a supported HTTP method.
If you started the creation of the route from an
Router object, you already specified some
supported HTTP methods. This one will simply be added.GET in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> POST()
RouteBuilderPOST as a supported HTTP method.
If you started the creation of the route from an
Router object, you already specified some
supported HTTP methods. This one will simply be added.POST in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> PUT()
RouteBuilderPUT as a supported HTTP method.
If you started the creation of the route from an
Router object, you already specified some
supported HTTP methods. This one will simply be added.PUT in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> DELETE()
RouteBuilderDELETE as a supported HTTP method.
If you started the creation of the route from an
Router object, you already specified some
supported HTTP methods. This one will simply be added.DELETE in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> OPTIONS()
RouteBuilderOPTIONS as a supported HTTP method.
If you started the creation of the route from an
Router object, you already specified some
supported HTTP methods. This one will simply be added.OPTIONS in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> TRACE()
RouteBuilderTRACE as a supported HTTP method.
If you started the creation of the route from an
Router object, you already specified some
supported HTTP methods. This one will simply be added.TRACE in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> HEAD()
RouteBuilderHEAD as a supported HTTP method.
If you started the creation of the route from an
Router object, you already specified some
supported HTTP methods. This one will simply be added.HEAD in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> PATCH()
RouteBuilderPATCH as a supported HTTP method.
If you started the creation of the route from an
Router object, you already specified some
supported HTTP methods. This one will simply be added.PATCH in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> ALL()
RouteBuilderRouter object, you already specified some
supported HTTP methods. By calling this method, all
methods will now be suported.ALL in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> methods(Set<HttpMethod> httpMethods)
RouteBuilderRouter object, you already specified some
supported HTTP methods. Those new ones will simply be added.methods in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> methods(HttpMethod... httpMethods)
RouteBuilderRouter object, you already specified some
supported HTTP methods. Those new ones will simply be added.methods in interface RouteBuilder<R extends RequestContext<?>>public void handle(Handler<R> mainHandler)
RouteBuilderRouter object, an exception will be
thrown.handle in interface RouteBuilder<R extends RequestContext<?>>public Route<R> create(Handler<R> mainHandler)
RouteBuildersave(...) instead to save the route
to the router at the end of the build process!create in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> noCache()
RouteBuildernoCache in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> cache()
RouteBuilder
Uses the default cache configurations, provided
by SpincastConfig
cache in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> cache(int seconds)
RouteBuildercache in interface RouteBuilder<R extends RequestContext<?>>seconds - The number of seconds the resource associated with
this route should be cached.public RouteBuilder<R> cache(int seconds, boolean isPrivate)
RouteBuildercache in interface RouteBuilder<R extends RequestContext<?>>seconds - The number of seconds the resource associated with
this route should be cached.isPrivate - should the cache be private?
(help)public RouteBuilder<R> cache(int seconds, boolean isPrivate, Integer secondsCdn)
RouteBuildercache in interface RouteBuilder<R extends RequestContext<?>>seconds - The number of seconds the resource associated with
this route should be cached.isPrivate - should the cache be private?
(help)secondsCdn - The number of seconds the resource associated with
this route should be cached by a CDN/proxy. If null, it
won't be used.protected int getCacheSecondsByDefault()
protected boolean isCachePrivateByDefault()
protected Integer getCacheCdnSecondsByDefault()
public RouteBuilder<R> skip(String filterId)
RouteBuilderThis is useful when you set a global filter but want to skip it one a specific route only.
skip in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> skipResourcesRequests()
RouteBuilderRoute.isStaticResourceRoute()). In the case
of Dynamic Resources,
the filters will indeed be called when the generator is used. By
calling this RouteBuilder.skipResourcesRequests() method, the current filter
will never be called for such resources.
This feature only makes sense if the current route if a filter. Otherwise, it won't be used.
skipResourcesRequests in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> specs(Object specs, Object... parameters)
RouteBuilderDoes nothing by default. Requires a plugin that knows how to parse the provided object.
specs in interface RouteBuilder<R extends RequestContext<?>>public RouteBuilder<R> specsIgnore()
RouteBuilderspecsIgnore in interface RouteBuilder<R extends RequestContext<?>>Copyright © 2019. All rights reserved.