public.javadoc.org.spincast.plugins.routing.RouteBuilderDefault.html Maven / Gradle / Ivy
Show all versions of spincast-website Show documentation
RouteBuilderDefault (org.spincast:spincast-framework 1.13.0 API)
org.spincast.plugins.routing
Class RouteBuilderDefault<R extends RequestContext<?>,W extends WebsocketContext<?>>
- java.lang.Object
-
- org.spincast.plugins.routing.RouteBuilderDefault<R,W>
-
- All Implemented Interfaces:
- RouteBuilder<R>
public class RouteBuilderDefault<R extends RequestContext<?>,W extends WebsocketContext<?>>
extends Object
implements RouteBuilder<R>
-
-
Field Summary
Fields
Modifier and Type
Field and Description
protected static org.slf4j.Logger
logger
-
Constructor Summary
Constructors
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)
-
Method Summary
All Methods Instance Methods Concrete Methods
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
.
-
-
Constructor Detail
-
RouteBuilderDefault
public RouteBuilderDefault(RouteFactory<R> routeFactory,
SpincastRouterConfig spincastRouterConfig,
SpincastFilters<R> spincastFilters,
SpincastConfig spincastConfig)
-
RouteBuilderDefault
public RouteBuilderDefault(Router<R,W> router,
RouteFactory<R> routeFactory,
SpincastRouterConfig spincastRouterConfig,
SpincastFilters<R> spincastFilters,
SpincastConfig spincastConfig)
-
Method Detail
-
getRouteFactory
protected RouteFactory<R> getRouteFactory()
-
getSpincastRouterConfig
protected SpincastRouterConfig getSpincastRouterConfig()
-
getSpincastFilters
protected SpincastFilters<R> getSpincastFilters()
-
getSpincastConfig
protected SpincastConfig getSpincastConfig()
-
getId
public String getId()
-
isSpicastCoreRouteOrPluginRoute
public boolean isSpicastCoreRouteOrPluginRoute()
-
getPath
public String getPath()
-
getPosition
public int getPosition()
-
isSkipResources
public boolean isSkipResources()
-
getRoutingTypes
public Set<RoutingType> getRoutingTypes()
-
getHttpMethods
public Set<HttpMethod> getHttpMethods()
-
getSpecs
public Object getSpecs()
May be null
.
-
isSpecsIgnore
public boolean isSpecsIgnore()
-
getSpecsParameters
public Object[] getSpecsParameters()
-
id
public RouteBuilder<R> id(String id)
Description copied from interface: RouteBuilder
An id that can be used to identify the route.
Must be unique.
- Specified by:
id
in interface RouteBuilder<R extends RequestContext<?>>
-
spicastCoreRouteOrPluginRoute
public RouteBuilder<R> spicastCoreRouteOrPluginRoute()
Description copied from interface: RouteBuilder
This should only by called by *plugins*.
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.
- Specified by:
spicastCoreRouteOrPluginRoute
in interface RouteBuilder<R extends RequestContext<?>>
-
pos
public RouteBuilder<R> pos(int position)
Description copied from interface: RouteBuilder
The position of the handler.
If "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.
- Specified by:
pos
in interface RouteBuilder<R extends RequestContext<?>>
-
allRoutingTypes
public RouteBuilder<R> allRoutingTypes()
Description copied from interface: RouteBuilder
This route will be considered for all routing types.
- Specified by:
allRoutingTypes
in interface RouteBuilder<R extends RequestContext<?>>
-
found
public RouteBuilder<R> found()
Description copied from interface: RouteBuilder
This route will be considered during a Found
routing process.
- Specified by:
found
in interface RouteBuilder<R extends RequestContext<?>>
-
notFound
public RouteBuilder<R> notFound()
Description copied from interface: RouteBuilder
This route will be considered during a Not Found
routing process.
- Specified by:
notFound
in interface RouteBuilder<R extends RequestContext<?>>
-
exception
public RouteBuilder<R> exception()
Description copied from interface: RouteBuilder
This route will be considered during an Exception
routing process.
- Specified by:
exception
in interface RouteBuilder<R extends RequestContext<?>>
-
before
public RouteBuilder<R> before(Handler<R> beforeFilter)
Description copied from interface: RouteBuilder
Adds a "before" filter which will only be applied to this particular route.
If more than one filter is added, they will be run in order they have been
added.
- Specified by:
before
in interface RouteBuilder<R extends RequestContext<?>>
-
after
public RouteBuilder<R> after(Handler<R> afterFilter)
Description copied from interface: RouteBuilder
Adds an "after" filter which will only be applied to this particular route.
If more than one filter is added, they will be run in order they have been
added.
- Specified by:
after
in interface RouteBuilder<R extends RequestContext<?>>
-
acceptAsString
public RouteBuilder<R> acceptAsString(String... acceptedContentTypes)
Description copied from interface: RouteBuilder
Sets the accepted Content-Types
.
This route will only be considered for requests specifying those
Content-Types
as being accepted
(using the Accept
header).
- Specified by:
acceptAsString
in interface RouteBuilder<R extends RequestContext<?>>
-
acceptAsString
public RouteBuilder<R> acceptAsString(Set<String> acceptedContentTypes)
Description copied from interface: RouteBuilder
Sets the accepted Content-Types
.
This route will only be considered for requests specifying those
Content-Types
as being accepted
(using the Accept
header).
- Specified by:
acceptAsString
in interface RouteBuilder<R extends RequestContext<?>>
-
accept
public RouteBuilder<R> accept(ContentTypeDefaults... acceptedContentTypes)
Description copied from interface: RouteBuilder
Sets the accepted Content-Types
.
This route will only be considered for requests specifying those
Content-Types
as being accepted
(using the Accept
header).
- Specified by:
accept
in interface RouteBuilder<R extends RequestContext<?>>
-
accept
public RouteBuilder<R> accept(Set<ContentTypeDefaults> acceptedContentTypes)
Description copied from interface: RouteBuilder
Sets the accepted Content-Types
.
This route will only be considered for requests specifying those
Content-Types
as being accepted
(using the Accept
header).
- Specified by:
accept
in interface RouteBuilder<R extends RequestContext<?>>
-
html
public RouteBuilder<R> html()
Description copied from interface: RouteBuilder
Adds application/html
as an accepted Content-Type
.
- Specified by:
html
in interface RouteBuilder<R extends RequestContext<?>>
-
json
public RouteBuilder<R> json()
Description copied from interface: RouteBuilder
Adds application/json
as an accepted Content-Type
.
- Specified by:
json
in interface RouteBuilder<R extends RequestContext<?>>
-
xml
public RouteBuilder<R> xml()
Description copied from interface: RouteBuilder
Adds application/xml
as an accepted Content-Type
.
- Specified by:
xml
in interface RouteBuilder<R extends RequestContext<?>>
-
path
public RouteBuilder<R> path(String path)
Description copied from interface: RouteBuilder
The path of the route.
- Specified by:
path
in interface RouteBuilder<R extends RequestContext<?>>
-
GET
public RouteBuilder<R> GET()
Description copied from interface: RouteBuilder
Addss GET
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.
- Specified by:
GET
in interface RouteBuilder<R extends RequestContext<?>>
-
POST
public RouteBuilder<R> POST()
Description copied from interface: RouteBuilder
Adds POST
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.
- Specified by:
POST
in interface RouteBuilder<R extends RequestContext<?>>
-
PUT
public RouteBuilder<R> PUT()
Description copied from interface: RouteBuilder
Adds PUT
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.
- Specified by:
PUT
in interface RouteBuilder<R extends RequestContext<?>>
-
DELETE
public RouteBuilder<R> DELETE()
Description copied from interface: RouteBuilder
Adds DELETE
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.
- Specified by:
DELETE
in interface RouteBuilder<R extends RequestContext<?>>
-
OPTIONS
public RouteBuilder<R> OPTIONS()
Description copied from interface: RouteBuilder
Adds OPTIONS
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.
- Specified by:
OPTIONS
in interface RouteBuilder<R extends RequestContext<?>>
-
TRACE
public RouteBuilder<R> TRACE()
Description copied from interface: RouteBuilder
Adds TRACE
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.
- Specified by:
TRACE
in interface RouteBuilder<R extends RequestContext<?>>
-
HEAD
public RouteBuilder<R> HEAD()
Description copied from interface: RouteBuilder
Adds HEAD
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.
- Specified by:
HEAD
in interface RouteBuilder<R extends RequestContext<?>>
-
PATCH
public RouteBuilder<R> PATCH()
Description copied from interface: RouteBuilder
Adds PATCH
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.
- Specified by:
PATCH
in interface RouteBuilder<R extends RequestContext<?>>
-
ALL
public RouteBuilder<R> ALL()
Description copied from interface: RouteBuilder
Adds all HTTP methods as being supported.
If you started the creation of the route from an
Router
object, you already specified some
supported HTTP methods. By calling this method, all
methods will now be suported.
- Specified by:
ALL
in interface RouteBuilder<R extends RequestContext<?>>
-
methods
public RouteBuilder<R> methods(Set<HttpMethod> httpMethods)
Description copied from interface: RouteBuilder
Adds the specified HTTP methods as being supported.
If you started the creation of the route from an
Router
object, you already specified some
supported HTTP methods. Those new ones will simply be added.
- Specified by:
methods
in interface RouteBuilder<R extends RequestContext<?>>
-
methods
public RouteBuilder<R> methods(HttpMethod... httpMethods)
Description copied from interface: RouteBuilder
Adds the specified HTTP methods as being supported.
If you started the creation of the route from an
Router
object, you already specified some
supported HTTP methods. Those new ones will simply be added.
- Specified by:
methods
in interface RouteBuilder<R extends RequestContext<?>>
-
handle
public void handle(Handler<R> mainHandler)
Description copied from interface: RouteBuilder
Creates the route and saves it to the router.
If the creation of the route was not started using
an Router
object, an exception will be
thrown.
- Specified by:
handle
in interface RouteBuilder<R extends RequestContext<?>>
-
create
public Route<R> create(Handler<R> mainHandler)
Description copied from interface: RouteBuilder
Creates and returns the route without adding it to
the router.
NOTE : use handle(...)
instead to save the route
to the router at the end of the build process!
- Specified by:
create
in interface RouteBuilder<R extends RequestContext<?>>
-
noCache
public RouteBuilder<R> noCache()
Description copied from interface: RouteBuilder
Automatically adds "no-cache" headers to the response.
- Specified by:
noCache
in interface RouteBuilder<R extends RequestContext<?>>
-
cache
public RouteBuilder<R> cache()
Description copied from interface: RouteBuilder
Adds cache headers.
Uses the default cache configurations, provided
by SpincastConfig
- Specified by:
cache
in interface RouteBuilder<R extends RequestContext<?>>
-
cache
public RouteBuilder<R> cache(int seconds)
Description copied from interface: RouteBuilder
Adds public cache headers.
- Specified by:
cache
in interface RouteBuilder<R extends RequestContext<?>>
- Parameters:
seconds
- The number of seconds the resource associated with
this route should be cached.
-
cache
public RouteBuilder<R> cache(int seconds,
boolean isPrivate)
Description copied from interface: RouteBuilder
Adds cache headers.
- Specified by:
cache
in interface RouteBuilder<R extends RequestContext<?>>
- Parameters:
seconds
- The number of seconds the resource associated with
this route should be cached.
isPrivate
- should the cache be private?
(help)
-
cache
public RouteBuilder<R> cache(int seconds,
boolean isPrivate,
Integer secondsCdn)
Description copied from interface: RouteBuilder
Adds cache headers.
- Specified by:
cache
in interface RouteBuilder<R extends RequestContext<?>>
- Parameters:
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.
-
getCacheSecondsByDefault
protected int getCacheSecondsByDefault()
-
isCachePrivateByDefault
protected boolean isCachePrivateByDefault()
-
getCacheCdnSecondsByDefault
protected Integer getCacheCdnSecondsByDefault()
-
skip
public RouteBuilder<R> skip(String filterId)
Description copied from interface: RouteBuilder
Skip a "before" and "after" filter for this route.
This is useful when you set a global filter but want to skip
it one a specific route only.
- Specified by:
skip
in interface RouteBuilder<R extends RequestContext<?>>
-
skipResourcesRequests
public RouteBuilder<R> skipResourcesRequests()
Description copied from interface: RouteBuilder
Won't be applied if the request is for a resource
(Route.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.
- Specified by:
skipResourcesRequests
in interface RouteBuilder<R extends RequestContext<?>>
-
specs
public RouteBuilder<R> specs(Object specs,
Object... parameters)
Description copied from interface: RouteBuilder
Generic method to provide specifications
for an endpoint.
Does nothing by default. Requires a plugin
that knows how to parse the provided
object.
- Specified by:
specs
in interface RouteBuilder<R extends RequestContext<?>>
-
specsIgnore
public RouteBuilder<R> specsIgnore()
Description copied from interface: RouteBuilder
When calling this method, the associated route won't
be part of the generated specs.
- Specified by:
specsIgnore
in interface RouteBuilder<R extends RequestContext<?>>
Copyright © 2019. All rights reserved.