Class FreemarkerDispatcher
- All Implemented Interfaces:
RawTemplateDispatcher
FreemarkerMixin mixin, the FreemarkerServlet servlet, and the
FreemarkerResource child flavors.
This is the flavor-neutral worker for the FreeMarker capability: it is not one
of the three @Rest flavor classes — it is a plain bean that implements
RawTemplateDispatcher and holds the capability state (basePath /
templateSuffix / cacheTemplates / lazy default configuration) plus the raw-serve
and configuration-resolution logic. Each flavor independently holds an instance of this worker and
delegates to it, so no flavor is another flavor's worker.
See Also:
- Since:
- 10.0.0
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault base path applied when noFreemarkerDispatcher.Builder.basePath(String)call has been made.static final booleanDefault template-cache flag —true(production-safe).static final booleanDefault field-exposure flag —true(public-field DTOs render out of the box).static final StringDefault template suffix — empty (literal template names, no implicit suffix). -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBuilder constructor. -
Method Summary
Modifier and TypeMethodDescriptionapplyTemplateSuffix(String name) AppendsgetTemplateSuffix()tonameif not already present (idempotent).protected freemarker.template.ConfigurationConstructs the bridge-defaultConfiguration.static FreemarkerDispatcher.Buildercreate()Creates a new builder.Returns the base path under which template resources are resolved.freemarker.template.ObjectWrapperReturns the user-suppliedObjectWrapperoverride, if any.Returns the configured template-name suffix.booleanReturns the template-cache flag.booleanReturns the field-exposure flag applied to the bridge-default object wrapper.voidrender(String path, RestRequest req, RestResponse res) Renders a raw template through the FreeMarker engine onto the response.freemarker.template.ConfigurationResolves the activeConfiguration.
-
Field Details
-
DEFAULT_BASE_PATH
Default base path applied when noFreemarkerDispatcher.Builder.basePath(String)call has been made.- See Also:
-
DEFAULT_TEMPLATE_SUFFIX
Default template suffix — empty (literal template names, no implicit suffix).- See Also:
-
DEFAULT_CACHE_TEMPLATES
Default template-cache flag —true(production-safe).- See Also:
-
DEFAULT_EXPOSE_FIELDS
Default field-exposure flag —true(public-field DTOs render out of the box).- See Also:
-
-
Constructor Details
-
FreemarkerDispatcher
Builder constructor.- Parameters:
builder- The builder. Must not benull.
-
-
Method Details
-
create
Creates a new builder.- Returns:
- A new builder.
-
getBasePath
Returns the base path under which template resources are resolved.- Returns:
- The base path. Never
null.
-
getTemplateSuffix
Returns the configured template-name suffix.- Returns:
- The template suffix. Never
null.
-
isCacheTemplates
Returns the template-cache flag.- Returns:
- The cache flag.
-
isExposeFields
Returns the field-exposure flag applied to the bridge-default object wrapper.- Returns:
- The field-exposure flag. Ignored once
getObjectWrapper()returns non-null.
-
getObjectWrapper
Returns the user-suppliedObjectWrapperoverride, if any.- Returns:
- The object wrapper override, or
nullif the bridge builds its own default (aDefaultObjectWrapperconfigured perisExposeFields()).
-
applyTemplateSuffix
AppendsgetTemplateSuffix()tonameif not already present (idempotent).- Parameters:
name- The template name. Must not benull.- Returns:
- The template name with the configured suffix appended (if applicable).
-
resolveConfiguration
Resolves the activeConfiguration.Lookup order:
req.getContext().getBeanStore().getBean(Configuration.class)— any user-supplied bean (Spring@Beanincluding Spring Boot autoconfig, microserviceBasicBeanStore.put, etc.).- Lazy bridge default — constructed on first call when no configuration bean is
registered. Anchored on a classpath resource root derived from
basePath, withIncompatibleImprovementspinned to the bridge-tested minor version.
- Parameters:
req- The current REST request.- Returns:
- The active FreeMarker configuration. Never
null.
-
buildDefaultConfiguration
Constructs the bridge-defaultConfiguration.Anchored on a classpath resource root derived from
basePath(leading + trailing slashes trimmed; a"/"base yields a root-of-classpath resolver). The default pinsIncompatibleImprovementstoConfiguration.VERSION_2_3_34so behavior is stable across consumer upgrades oforg.freemarker:freemarker; setsDefaultEncodingtoUTF-8andOutputFormattoHTMLOutputFormat.INSTANCEso HTML escaping is the natural target; appliesTemplateUpdateDelayMillisecondsper the configuredcacheTemplatesflag; and sets anObjectWrapper— either the user-suppliedobjectWrapperoverride, or (by default) aDefaultObjectWrapperbuilt withexposeFieldsset toisExposeFields(). Field exposure defaults totrue(unlike FreeMarker's own version-default wrapper, which is getter-only): Juneau's own marshalling is comfortable with public-field beans elsewhere, so a view-model DTO written with public fields and no getters renders its field values here too, instead of silently resolving tonull/missing.Template exceptions are not logged by FreeMarker (
LogTemplateExceptionsisfalse): every caller rethrows them as anInternalServerErrorcarrying the cause, so logging them as well would only duplicate the stack trace.Subclasses may override to plug in custom loaders / encodings / output formats without registering a separate
@Bean Configuration.- Returns:
- A new
Configurationinstance.
-
render
public void render(String path, RestRequest req, RestResponse res) throws IOException, BasicHttpException Renders a raw template through the FreeMarker engine onto the response.- Specified by:
renderin interfaceRawTemplateDispatcher- Parameters:
path- The trailing path segment after the mount prefix (the template name relative to the configuredbase path; configured suffix appended if missing).req- The current REST request.res- The current REST response.- Throws:
IOException- If the underlying response writer fails.BasicHttpException- On boundary violation (403), missing engine (500), or render failure (500).
-