public.javadoc.org.spincast.plugins.routing.StaticResourceBuilderDefault.html Maven / Gradle / Ivy
Show all versions of spincast-website Show documentation
StaticResourceBuilderDefault (org.spincast:spincast-framework 1.14.0 API)
org.spincast.plugins.routing
Class StaticResourceBuilderDefault<R extends RequestContext<?>,W extends WebsocketContext<?>>
- java.lang.Object
-
- org.spincast.plugins.routing.StaticResourceBuilderDefault<R,W>
-
- All Implemented Interfaces:
- StaticResourceBuilder<R>
public class StaticResourceBuilderDefault<R extends RequestContext<?>,W extends WebsocketContext<?>>
extends Object
implements StaticResourceBuilder<R>
-
-
Field Summary
Fields
Modifier and Type
Field and Description
protected static org.slf4j.Logger
logger
-
Constructor Summary
Constructors
Constructor and Description
StaticResourceBuilderDefault(boolean isDir,
StaticResourceFactory<R> staticResourceFactory,
StaticResourceCorsConfigFactory staticResourceCorsConfigFactory,
StaticResourceCacheConfigFactory staticResourceCacheConfigFactory,
SpincastConfig spincastConfig,
SpincastUtils spincastUtils,
SpincastRouterConfig spincastRouterConfig)
StaticResourceBuilderDefault(Router<R,W> router,
boolean isDir,
StaticResourceFactory<R> staticResourceFactory,
StaticResourceCorsConfigFactory staticResourceCorsConfigFactory,
StaticResourceCacheConfigFactory staticResourceCacheConfigFactory,
SpincastConfig spincastConfig,
SpincastUtils spincastUtils,
SpincastRouterConfig spincastRouterConfig)
-
Method Summary
All Methods Instance Methods Concrete Methods
Modifier and Type
Method and Description
StaticResourceBuilder<R>
cache(int seconds)
Adds public cache headers.
StaticResourceBuilder<R>
cache(int seconds,
boolean isCachePrivate)
Adds cache headers.
StaticResourceBuilder<R>
cache(int seconds,
boolean isCachePrivate,
Integer cdnSeconds)
Adds cache headers.
StaticResourceBuilder<R>
classpath(String path)
The path to the resource, on the classpath.
StaticResourceBuilder<R>
cors()
Enables Cross-Origin Resource Sharing (Cors)
StaticResourceBuilder<R>
cors(Set<String> allowedOrigins)
Enables Cross-Origin Resource Sharing (Cors)
StaticResourceBuilder<R>
cors(Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead)
Enables Cross-Origin Resource Sharing (Cors)
StaticResourceBuilder<R>
cors(Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent)
Enables Cross-Origin Resource Sharing (Cors)
StaticResourceBuilder<R>
cors(Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent,
boolean allowCookies)
Enables Cross-Origin Resource Sharing (Cors)
StaticResourceBuilder<R>
cors(Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent,
boolean allowCookies,
int maxAgeInSeconds)
Enables Cross-Origin Resource Sharing (Cors)
StaticResource<R>
create()
Creates and returns the static resource without adding it to
the router.
protected Integer
getCacheCdnSecondsDefault()
StaticResourceCacheConfig
getCacheConfig()
StaticResourceCorsConfig
getCorsConfig()
protected Set<String>
getCorsDefaultAllowedOrigins()
The origins allowed, by default.
protected Set<String>
getCorsDefaultExtraHeadersAllowedToBeRead()
The extra headers allowed to be read, by default,
protected Set<String>
getCorsDefaultExtraHeadersAllowedToBeSent()
The extra headers allowed to be sent, by default,
protected boolean
getCorsDefaultIsCookiesAllowed()
Are cookies allowed by default?
protected int
getCorsDefaultMaxAgeInSeconds()
If <= 0, the "Access-Control-Max-Age" header
won't be sent.
protected StaticResourceCacheConfig
getDefaultCacheConfig()
The default cache configurations to use if it is
not specified.
Handler<R>
getGenerator()
HotlinkingManager
getHotlinkingManager()
String
getPath()
protected Router<R,W>
getRouter()
protected SpincastConfig
getSpincastConfig()
protected SpincastRouterConfig
getSpincastRouterConfig()
protected SpincastUtils
getSpincastUtils()
protected StaticResourceCacheConfigFactory
getStaticResourceCacheConfigFactory()
protected StaticResourceCorsConfigFactory
getStaticResourceCorsConfigFactory()
protected StaticResourceFactory<R>
getStaticResourceFactory()
String
getUrl()
void
handle()
Saves the static resource route to the router.
void
handle(Handler<R> generator)
Saves the static resource route.
void
handle(Handler<R> generator,
boolean ignoreQueryString)
Saves the static resource route.
StaticResourceBuilder<R>
hotlinkingProtected()
When a static resource is flagged as being
*hotlinking protected*, the server will
validate the origin
and referer
of the request.
StaticResourceBuilder<R>
hotlinkingProtected(HotlinkingManager hotlinkingManager)
When a static resource is flagged as being
*hotlinking protected*, the server will
validate the origin
and referer
of the request.
protected boolean
isCachePrivateDefault()
Is the cache private by default?
boolean
isClasspath()
protected boolean
isDir()
boolean
isHotlinkingProtected()
boolean
isIgnoreQueryString()
protected boolean
isSpicastOrPluginAddedResource()
StaticResourceBuilder<R>
pathAbsolute(String absolutePath)
The absolute path to the resource, on the file system.
StaticResourceBuilder<R>
pathRelative(String relativePath)
The path to the resource, on the file system, relative to the
temp Spincast directory, as returned by
SpincastConfig::getSpincastTempDir()
StaticResourceBuilder<R>
spicastOrPluginAddedResource()
This should only by called by *plugins*.
StaticResourceBuilder<R>
url(String url)
The URL pointing to the resource.
-
-
Constructor Detail
-
StaticResourceBuilderDefault
public StaticResourceBuilderDefault(boolean isDir,
StaticResourceFactory<R> staticResourceFactory,
StaticResourceCorsConfigFactory staticResourceCorsConfigFactory,
StaticResourceCacheConfigFactory staticResourceCacheConfigFactory,
SpincastConfig spincastConfig,
SpincastUtils spincastUtils,
SpincastRouterConfig spincastRouterConfig)
-
StaticResourceBuilderDefault
public StaticResourceBuilderDefault(Router<R,W> router,
boolean isDir,
StaticResourceFactory<R> staticResourceFactory,
StaticResourceCorsConfigFactory staticResourceCorsConfigFactory,
StaticResourceCacheConfigFactory staticResourceCacheConfigFactory,
SpincastConfig spincastConfig,
SpincastUtils spincastUtils,
SpincastRouterConfig spincastRouterConfig)
-
Method Detail
-
isDir
protected boolean isDir()
-
isSpicastOrPluginAddedResource
protected boolean isSpicastOrPluginAddedResource()
-
getStaticResourceFactory
protected StaticResourceFactory<R> getStaticResourceFactory()
-
getStaticResourceCorsConfigFactory
protected StaticResourceCorsConfigFactory getStaticResourceCorsConfigFactory()
-
getStaticResourceCacheConfigFactory
protected StaticResourceCacheConfigFactory getStaticResourceCacheConfigFactory()
-
getSpincastConfig
protected SpincastConfig getSpincastConfig()
-
getSpincastUtils
protected SpincastUtils getSpincastUtils()
-
getSpincastRouterConfig
protected SpincastRouterConfig getSpincastRouterConfig()
-
getUrl
public String getUrl()
-
getPath
public String getPath()
-
isHotlinkingProtected
public boolean isHotlinkingProtected()
-
getHotlinkingManager
public HotlinkingManager getHotlinkingManager()
-
isClasspath
public boolean isClasspath()
-
getCorsConfig
public StaticResourceCorsConfig getCorsConfig()
-
getCacheConfig
public StaticResourceCacheConfig getCacheConfig()
-
isIgnoreQueryString
public boolean isIgnoreQueryString()
-
spicastOrPluginAddedResource
public StaticResourceBuilder<R> spicastOrPluginAddedResource()
Description copied from interface: StaticResourceBuilder
This should only by called by *plugins*.
When this method is called, the resulting route for
the resource 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:
spicastOrPluginAddedResource
in interface StaticResourceBuilder<R extends RequestContext<?>>
-
url
public StaticResourceBuilder<R> url(String url)
Description copied from interface: StaticResourceBuilder
The URL pointing to the resource.
- Specified by:
url
in interface StaticResourceBuilder<R extends RequestContext<?>>
-
classpath
public StaticResourceBuilder<R> classpath(String path)
Description copied from interface: StaticResourceBuilder
The path to the resource, on the classpath.
- Specified by:
classpath
in interface StaticResourceBuilder<R extends RequestContext<?>>
-
pathAbsolute
public StaticResourceBuilder<R> pathAbsolute(String absolutePath)
Description copied from interface: StaticResourceBuilder
The absolute path to the resource, on the file system.
- Specified by:
pathAbsolute
in interface StaticResourceBuilder<R extends RequestContext<?>>
- Parameters:
absolutePath
- the absolute path to the resource. If this is a file
and not a directory, remember that it will be served as a static resource,
so its extension is important for the
correct Content-Type
to be sent!
-
pathRelative
public StaticResourceBuilder<R> pathRelative(String relativePath)
Description copied from interface: StaticResourceBuilder
The path to the resource, on the file system, relative to the
temp Spincast directory, as returned by
SpincastConfig::getSpincastTempDir()
- Specified by:
pathRelative
in interface StaticResourceBuilder<R extends RequestContext<?>>
- Parameters:
relativePath
- the relative path to the resource. If this is a file
and not a directory, remember that it will be served as a static resource,
so its extension is important for the
correct Content-Type
to be sent!
-
cors
public StaticResourceBuilder<R> cors()
Description copied from interface: StaticResourceBuilder
Enables Cross-Origin Resource Sharing (Cors)
- Specified by:
cors
in interface StaticResourceBuilder<R extends RequestContext<?>>
- See Also:
SpincastFilters#cors(R context)
-
cors
public StaticResourceBuilder<R> cors(Set<String> allowedOrigins)
Description copied from interface: StaticResourceBuilder
Enables Cross-Origin Resource Sharing (Cors)
- Specified by:
cors
in interface StaticResourceBuilder<R extends RequestContext<?>>
- See Also:
SpincastFilters#cors(R context,
Set<String> allowedOrigins)
-
cors
public StaticResourceBuilder<R> cors(Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead)
Description copied from interface: StaticResourceBuilder
Enables Cross-Origin Resource Sharing (Cors)
- Specified by:
cors
in interface StaticResourceBuilder<R extends RequestContext<?>>
- See Also:
SpincastFilters#cors(R context,
Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead)
-
cors
public StaticResourceBuilder<R> cors(Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent)
Description copied from interface: StaticResourceBuilder
Enables Cross-Origin Resource Sharing (Cors)
- Specified by:
cors
in interface StaticResourceBuilder<R extends RequestContext<?>>
- See Also:
SpincastFilters#cors(R context,
Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent)
-
cors
public StaticResourceBuilder<R> cors(Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent,
boolean allowCookies)
Description copied from interface: StaticResourceBuilder
Enables Cross-Origin Resource Sharing (Cors)
- Specified by:
cors
in interface StaticResourceBuilder<R extends RequestContext<?>>
- See Also:
SpincastFilters#cors(R context,
Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent,
boolean allowCookies)
-
cors
public StaticResourceBuilder<R> cors(Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent,
boolean allowCookies,
int maxAgeInSeconds)
Description copied from interface: StaticResourceBuilder
Enables Cross-Origin Resource Sharing (Cors)
- Specified by:
cors
in interface StaticResourceBuilder<R extends RequestContext<?>>
- See Also:
SpincastFilters#cors(R context,
Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent,
boolean allowCookies,
int maxAgeInSeconds
)
-
getCorsDefaultMaxAgeInSeconds
protected int getCorsDefaultMaxAgeInSeconds()
If <= 0, the "Access-Control-Max-Age" header
won't be sent.
-
getCorsDefaultAllowedOrigins
protected Set<String> getCorsDefaultAllowedOrigins()
The origins allowed, by default.
-
getCorsDefaultExtraHeadersAllowedToBeRead
protected Set<String> getCorsDefaultExtraHeadersAllowedToBeRead()
The extra headers allowed to be read, by default,
-
getCorsDefaultExtraHeadersAllowedToBeSent
protected Set<String> getCorsDefaultExtraHeadersAllowedToBeSent()
The extra headers allowed to be sent, by default,
-
getCorsDefaultIsCookiesAllowed
protected boolean getCorsDefaultIsCookiesAllowed()
Are cookies allowed by default?
-
isCachePrivateDefault
protected boolean isCachePrivateDefault()
Is the cache private by default?
-
getCacheCdnSecondsDefault
protected Integer getCacheCdnSecondsDefault()
-
cache
public StaticResourceBuilder<R> cache(int seconds)
Description copied from interface: StaticResourceBuilder
Adds public cache headers.
- Specified by:
cache
in interface StaticResourceBuilder<R extends RequestContext<?>>
- Parameters:
seconds
- The number of seconds the resource associated with
this route should be cached.
-
cache
public StaticResourceBuilder<R> cache(int seconds,
boolean isCachePrivate)
Description copied from interface: StaticResourceBuilder
Adds cache headers.
- Specified by:
cache
in interface StaticResourceBuilder<R extends RequestContext<?>>
- Parameters:
seconds
- The number of seconds the resource associated with
this route should be cached.
isCachePrivate
- should the cache be private?
(help)
-
cache
public StaticResourceBuilder<R> cache(int seconds,
boolean isCachePrivate,
Integer cdnSeconds)
Description copied from interface: StaticResourceBuilder
Adds cache headers.
- Specified by:
cache
in interface StaticResourceBuilder<R extends RequestContext<?>>
- Parameters:
seconds
- The number of seconds the resource associated with
this route should be cached.
isCachePrivate
- should the cache be private?
(help)
cdnSeconds
- The number of seconds the resource associated with
this route should be cached by a CDN/proxy. If null
, it
won't be used.
-
handle
public void handle()
Description copied from interface: StaticResourceBuilder
Saves the static resource route to the router.
If the creation of the resource was not started using
an Router
object, an exception will be
thrown.
- Specified by:
handle
in interface StaticResourceBuilder<R extends RequestContext<?>>
-
handle
public void handle(Handler<R> generator)
Description copied from interface: StaticResourceBuilder
Saves the static resource route.
Note that the generated resource won't be cached
if there is a queryString on the request : it will
always be generated.
If the creation of the resource was not started using
an Router
object, an exception will be
thrown.
- Specified by:
handle
in interface StaticResourceBuilder<R extends RequestContext<?>>
- Parameters:
generator
- If the resource is not found, the specified
generator will be used to generate it and
the result will be saved.
-
handle
public void handle(Handler<R> generator,
boolean ignoreQueryString)
Description copied from interface: StaticResourceBuilder
Saves the static resource route.
If the creation of the resource was not started using
an Router
object, an exception will be
thrown.
- Specified by:
handle
in interface StaticResourceBuilder<R extends RequestContext<?>>
- Parameters:
generator
- If the resource is not found, the specified
generator will be used to generate it and
the result will be saved.
ignoreQueryString
- If true
, only one
instance of the resource will be generated and cached. If
false
(the default), the resource will always be
generated if there is a queryString.
-
create
public StaticResource<R> create()
Description copied from interface: StaticResourceBuilder
Creates and returns the static resource without adding it to
the router.
NOTE : use handle(...)
instead to save the static resource
to the router at the end of the build process!
- Specified by:
create
in interface StaticResourceBuilder<R extends RequestContext<?>>
-
getDefaultCacheConfig
protected StaticResourceCacheConfig getDefaultCacheConfig()
The default cache configurations to use if it is
not specified. It can still be null
and,
in that case, no cache header will be used.
-
hotlinkingProtected
public StaticResourceBuilder<R> hotlinkingProtected()
Description copied from interface: StaticResourceBuilder
When a static resource is flagged as being
*hotlinking protected*, the server will
validate the origin
and referer
of the request. If those don't matche the host of the
application, a protection will be apply, the one provided
by the default .
- Specified by:
hotlinkingProtected
in interface StaticResourceBuilder<R extends RequestContext<?>>
-
hotlinkingProtected
public StaticResourceBuilder<R> hotlinkingProtected(HotlinkingManager hotlinkingManager)
Description copied from interface: StaticResourceBuilder
When a static resource is flagged as being
*hotlinking protected*, the server will
validate the origin
and referer
of the request. If those don't matche the host of the
application, a protection will be apply, the one provided
by the specified hotlinkingManager
.
- Specified by:
hotlinkingProtected
in interface StaticResourceBuilder<R extends RequestContext<?>>
Copyright © 2019. All rights reserved.