public class StaticResourceBuilderDefault<R extends RequestContext<?>,W extends WebsocketContext<?>> extends Object implements StaticResourceBuilder<R>
| Modifier and Type | Field and Description |
|---|---|
protected static org.slf4j.Logger |
logger |
| 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) |
| 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.
|
public StaticResourceBuilderDefault(boolean isDir,
StaticResourceFactory<R> staticResourceFactory,
StaticResourceCorsConfigFactory staticResourceCorsConfigFactory,
StaticResourceCacheConfigFactory staticResourceCacheConfigFactory,
SpincastConfig spincastConfig,
SpincastUtils spincastUtils,
SpincastRouterConfig spincastRouterConfig)
public StaticResourceBuilderDefault(Router<R,W> router, boolean isDir, StaticResourceFactory<R> staticResourceFactory, StaticResourceCorsConfigFactory staticResourceCorsConfigFactory, StaticResourceCacheConfigFactory staticResourceCacheConfigFactory, SpincastConfig spincastConfig, SpincastUtils spincastUtils, SpincastRouterConfig spincastRouterConfig)
protected boolean isDir()
protected boolean isSpicastOrPluginAddedResource()
protected StaticResourceFactory<R> getStaticResourceFactory()
protected StaticResourceCorsConfigFactory getStaticResourceCorsConfigFactory()
protected StaticResourceCacheConfigFactory getStaticResourceCacheConfigFactory()
protected SpincastConfig getSpincastConfig()
protected SpincastUtils getSpincastUtils()
protected SpincastRouterConfig getSpincastRouterConfig()
public String getUrl()
public String getPath()
public boolean isHotlinkingProtected()
public HotlinkingManager getHotlinkingManager()
public boolean isClasspath()
public StaticResourceCorsConfig getCorsConfig()
public StaticResourceCacheConfig getCacheConfig()
public boolean isIgnoreQueryString()
public StaticResourceBuilder<R> spicastOrPluginAddedResource()
StaticResourceBuilder
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.
spicastOrPluginAddedResource in interface StaticResourceBuilder<R extends RequestContext<?>>public StaticResourceBuilder<R> url(String url)
StaticResourceBuilderurl in interface StaticResourceBuilder<R extends RequestContext<?>>public StaticResourceBuilder<R> classpath(String path)
StaticResourceBuilderclasspath in interface StaticResourceBuilder<R extends RequestContext<?>>public StaticResourceBuilder<R> pathAbsolute(String absolutePath)
StaticResourceBuilderpathAbsolute in interface StaticResourceBuilder<R extends RequestContext<?>>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!public StaticResourceBuilder<R> pathRelative(String relativePath)
StaticResourceBuilderSpincastConfig::getSpincastTempDir()pathRelative in interface StaticResourceBuilder<R extends RequestContext<?>>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!public StaticResourceBuilder<R> cors()
StaticResourceBuildercors in interface StaticResourceBuilder<R extends RequestContext<?>>SpincastFilters#cors(R context)public StaticResourceBuilder<R> cors(Set<String> allowedOrigins)
StaticResourceBuildercors in interface StaticResourceBuilder<R extends RequestContext<?>>SpincastFilters#cors(R context,
Set<String> allowedOrigins)public StaticResourceBuilder<R> cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead)
StaticResourceBuildercors in interface StaticResourceBuilder<R extends RequestContext<?>>SpincastFilters#cors(R context,
Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead)public StaticResourceBuilder<R> cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent)
StaticResourceBuildercors in interface StaticResourceBuilder<R extends RequestContext<?>>SpincastFilters#cors(R context,
Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent)public StaticResourceBuilder<R> cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies)
StaticResourceBuildercors in interface StaticResourceBuilder<R extends RequestContext<?>>SpincastFilters#cors(R context,
Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent,
boolean allowCookies)public StaticResourceBuilder<R> cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, int maxAgeInSeconds)
StaticResourceBuildercors in interface StaticResourceBuilder<R extends RequestContext<?>>SpincastFilters#cors(R context,
Set<String> allowedOrigins,
Set<String> extraHeadersAllowedToBeRead,
Set<String> extraHeadersAllowedToBeSent,
boolean allowCookies,
int maxAgeInSeconds
)protected int getCorsDefaultMaxAgeInSeconds()
protected Set<String> getCorsDefaultAllowedOrigins()
protected Set<String> getCorsDefaultExtraHeadersAllowedToBeRead()
protected Set<String> getCorsDefaultExtraHeadersAllowedToBeSent()
protected boolean getCorsDefaultIsCookiesAllowed()
protected boolean isCachePrivateDefault()
protected Integer getCacheCdnSecondsDefault()
public StaticResourceBuilder<R> cache(int seconds)
StaticResourceBuildercache in interface StaticResourceBuilder<R extends RequestContext<?>>seconds - The number of seconds the resource associated with
this route should be cached.public StaticResourceBuilder<R> cache(int seconds, boolean isCachePrivate)
StaticResourceBuildercache in interface StaticResourceBuilder<R extends RequestContext<?>>seconds - The number of seconds the resource associated with
this route should be cached.isCachePrivate - should the cache be private?
(help)public StaticResourceBuilder<R> cache(int seconds, boolean isCachePrivate, Integer cdnSeconds)
StaticResourceBuildercache in interface StaticResourceBuilder<R extends RequestContext<?>>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.public void handle()
StaticResourceBuilder
If the creation of the resource was not started using
an Router object, an exception will be
thrown.
handle in interface StaticResourceBuilder<R extends RequestContext<?>>public void handle(Handler<R> generator)
StaticResourceBuilder
If the creation of the resource was not started using
an Router object, an exception will be
thrown.
handle in interface StaticResourceBuilder<R extends RequestContext<?>>generator - If the resource is not found, the specified
generator will be used to generate it and
the result will be saved.public void handle(Handler<R> generator, boolean ignoreQueryString)
StaticResourceBuilder
If the creation of the resource was not started using
an Router object, an exception will be
thrown.
handle in interface StaticResourceBuilder<R extends RequestContext<?>>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.public StaticResource<R> create()
StaticResourceBuildersave(...) instead to save the static resource
to the router at the end of the build process!create in interface StaticResourceBuilder<R extends RequestContext<?>>protected StaticResourceCacheConfig getDefaultCacheConfig()
null and,
in that case, no cache header will be used.public StaticResourceBuilder<R> hotlinkingProtected()
StaticResourceBuilderorigin 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 .hotlinkingProtected in interface StaticResourceBuilder<R extends RequestContext<?>>public StaticResourceBuilder<R> hotlinkingProtected(HotlinkingManager hotlinkingManager)
StaticResourceBuilderorigin 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.hotlinkingProtected in interface StaticResourceBuilder<R extends RequestContext<?>>Copyright © 2019. All rights reserved.