public static class ServerPagesBundle.AppBuilder
extends java.lang.Object
| Modifier | Constructor and Description |
|---|---|
protected |
AppBuilder(boolean mainContext,
java.lang.String name,
java.lang.String path,
java.lang.String uri,
GlobalConfig config) |
| Modifier and Type | Method and Description |
|---|---|
ServerPagesBundle.AppBuilder |
attachWebjars()
Shortcut for
ServerPagesBundle.extendApp("name", "META-INF/resources/webjars/"). |
ServerPagesAppBundle |
build()
Note: if bundle is used inside guicey bundle then use
register(GuiceyBootstrap) for
bundle installation. |
ServerPagesBundle.AppBuilder |
errorPage(int code,
java.lang.String path)
Show special page instead of response with specified status code.
|
ServerPagesBundle.AppBuilder |
errorPage(java.lang.String path)
Default error page (shown in case of exceptions and for all error return codes (>=400)).
|
ServerPagesBundle.AppBuilder |
filePattern(java.lang.String regex)
Differentiation of template call from static resource is based on fact: static resources
have extensions.
|
ServerPagesBundle.AppBuilder |
indexPage(java.lang.String name)
Declares index page (served for "/" calls).
|
void |
register(ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyBootstrap bootstrap)
Use when server pages bundle must be registered within guicey bundle
(guicey bundle could register custom application, e.g. for administration or simply register
customizations for existing application).
|
ServerPagesBundle.AppBuilder |
requireRenderers(java.lang.String... names)
Specifies required template types (view renderes) for application.
|
ServerPagesBundle.AppBuilder |
spaRouting()
Shortcut for
spaRouting(String) with default regexp. |
ServerPagesBundle.AppBuilder |
spaRouting(java.lang.String noRedirectRegex)
Enable single page application html5 routing support.
|
ServerPagesBundle.AppBuilder |
viewsConfigurationModifier(java.lang.String name,
ViewRendererConfigurationModifier modifier)
Dropwizard views configuration modification.
|
protected AppBuilder(boolean mainContext,
java.lang.String name,
java.lang.String path,
java.lang.String uri,
GlobalConfig config)
public ServerPagesBundle.AppBuilder requireRenderers(java.lang.String... names)
ServerPagesBundle.builder()).
Without declaring required renderer, application will simply serve template files "as is" when no appropriate renderer found (because template file will not be recognized as template).
Renderer name is a renderer configuration key, defined in ViewRenderer.getConfigurationKey().
names - required renderer namespublic ServerPagesBundle.AppBuilder spaRouting()
spaRouting(String) with default regexp.public ServerPagesBundle.AppBuilder spaRouting(java.lang.String noRedirectRegex)
noRedirectRegex - regex to match all cases when redirection not neededfor more info how it works,
for more info about regexppublic ServerPagesBundle.AppBuilder indexPage(java.lang.String name)
Pay attention that index is not set by default to "index.html" because most likely it would be some template handled with rest resource (and so it would be too often necessary to override default).
name - index file name (by default "")public ServerPagesBundle.AppBuilder errorPage(java.lang.String path)
path - either path to static resource (inside registered classpath path) or resource url
(without app name prefix)for registereing error page on exact return codepublic ServerPagesBundle.AppBuilder errorPage(int code, java.lang.String path)
Error pages should use ErrorTemplateView as (base) model
class in order to get access to context exception. It is not required, if error object itself not required
during rendering.
NOTE that error page is returned only if original request accept html response and otherwise no error page will be shown. Intention here is to show human readable errors only for humans.
IMPORTANT: GSP errors mechanism override ExceptionMapper and dropwizard-view ErrorEntityWriter mechanisms
because exception is detected before them and request is redirected to error page. Both ExceptionMapper
and EntityWriter would be called, but their result will be ignored (still, ExceptionMapper is useful
for errors logging). This was done to avoid influence of global ExceptionMapper's to be sure custom
error page used. It is possible to ignore GSP error mechanism for exact rest methods by using
ManualErrorHandling annotation.
code - error code to map page ontopath - either path to static resource (inside registered classpath path) or resource url
(without app name prefix)for global errors pagepublic ServerPagesBundle.AppBuilder attachWebjars()
ServerPagesBundle.extendApp("name", "META-INF/resources/webjars/").
Useful if you want to use resources from webjars. All webjars package resources under the same path
(e.g. META-INF/resources/webjars/jquery/3.4.1/dist/jquery.min.js), so after enabling webjars support
you can reference any resource from webjar (in classpath) (e.g. as
<script src="jquery/3.4.1/dist/jquery.min.js">).public ServerPagesBundle.AppBuilder filePattern(java.lang.String regex)
Pattern must return detected file name as first matched group (so direct template could be detected). Pattern is searched (find) inside path, not matched (so simple patterns will also work).
regex - regex for file request detection and file name extractiondefault patternpublic ServerPagesBundle.AppBuilder viewsConfigurationModifier(java.lang.String name, ViewRendererConfigurationModifier modifier)
ServerPagesBundle.ViewsBuilder.viewsConfiguration(ViewConfigurable)). But it's often required to
"tune" template engine specifically for application. This method allows global views configuration
modification for exact server pages application.
The main use case is configuration of the exact template engine. For example, in case of freemarker this could be used to apply auto includes:
.viewsConfigurationModifier("freemarker", config -> config
// expose master template
.put("auto_include", "/com/my/app/ui/master.ftl"))
Note that configuration object is still global (becuase dropwizard views support is global) and so
multiple server pages applications could modify configuration. For example, if multiple applications will
declare auto includes (example above) then only one include will be actually used. Use
ServerPagesBundle.ViewsBuilder.printViewsConfiguration() to see the final view configuration.
name - renderer name (e.g. freemarker, mustache, etc.)modifier - modification callbackpublic ServerPagesAppBundle build()
register(GuiceyBootstrap) for
bundle installation.public void register(ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyBootstrap bootstrap)
bootstrap - guicey bootstrap object