Class JspMixin
Compose into a host resource via
@Rest(mixins=JspMixin.class); the host then:
- Gains a default mount at
/jsp/*that serves raw.jspresources from the importer's classpath viaforward(...). - Registers
JspViewRendererfor the mixin's own endpoints (e.g. the/jsp/*route above) via the mixin's own@Rest(responseProcessors=...)declaration.
Auto-wiring the renderer into the host's own endpoints:
A bare @Rest(mixins=JspMixin.class) is enough — a host whose own @RestOp method returns
JspView renders it through the JSP engine with no extra wiring. That works because JspMixin
declares @Rest(mergeResponseProcessorsIntoHost=true) on its own
class, so the framework folds JspMixin's JspViewRenderer into the host's own response-processor
chain automatically.
This fold is per-mixin, opt-in, and response-processor-scoped: it happens only because JspMixin
declares the opt-in (a mixin that does not is still scoped to its own endpoints, the standard
@Rest(mixins=...) rule), and it folds only the renderer — never guards,
serializers, or any other list-shaped attribute.
Two explicit wirings remain supported — useful when you want to be explicit, or to fold more than the renderer:
@Mixin(mergeIntoHost=true)via the richmixinDefsform — folds all ofJspMixin's list-shaped@Restattributes into the host's own chain, not just the renderer.- List
JspViewRenderer.classexplicitly in the host's own@Rest(responseProcessors=...)— the fully manual equivalent.
The ResponseProcessorList partition pass repositions
JspViewRenderer (a
ViewRenderer) ahead of
SerializedPojoProcessor in every case, so the JspView bean is dispatched to the JSP engine
rather than bean-serialized.
Composition example (microservice):
Configurable mount path:
The default mount /jsp/* can be overridden via the SVL variable
${juneau.jsp.path:jsp} — set via system property
(-Djuneau.jsp.path=views), environment variable
(JUNEAU_JSP_PATH=views), or Config key
(juneau.jsp.path = views) to change the runtime mount without subclassing.
Resolution happens once at RestContext construction time (SVL resolution in @RestOp(path)).
Override accepts bare token (jsp), leading slash (/jsp), trailing slash
(jsp/), or wildcard suffix (/jsp/*) — all resolve to the same mount.
Mixin-only deployment:
This resource is designed for composition via @Rest(mixins=...). The mount path is
pinned at the op level by @RestGet(path="/{juneau.jsp.path:jsp}/*") on
render(java.lang.String, org.apache.juneau.rest.server.RestRequest, org.apache.juneau.rest.server.RestResponse); a class-level @Rest(paths=...) declaration would be silently
ignored under the mixin pattern (see @Rest(paths) Javadoc).
Engine-agnostic packaging:
The juneau-rest-server-view-jsp module ships only the JSP API + JSTL impl in
provided scope. No JSP engine is bundled with the bridge module. Consumers add
the engine matching their container:
- Jetty 12 EE11 (microservice-jetty, Spring Boot embedded Jetty):
org.eclipse.jetty.ee11:jetty-ee11-apache-jsp. - Embedded Tomcat (Spring Boot default):
org.apache.tomcat.embed:tomcat-embed-jasper. - External-WAR deployments: container-supplied; no additional dependency.
When no engine is on the classpath, the renderer surfaces
JspViewRenderer.NO_ENGINE_DIAGNOSTIC naming the missing dependency.
Spring Boot fat-jar caveat:
Spring Boot's repackaged fat jar does not place .jsp files where the embedded JSP
engine looks by default. Place JSP resources under
src/main/resources/META-INF/resources/WEB-INF/views/... (the META-INF/resources/
prefix is the Servlet 3.0 convention Spring Boot honors for embedded servlets). Both
mvn spring-boot:run and the deployed jar pick the files up this way.
Multiple base paths:
A host with /views/ JSPs and /admin/views/ JSPs registers two
JspMixin beans, each mounted via a subclass declaring its own op-level
@RestGet(path=...) override and its own basePath. See the
JspMixin_MultiBasePath_Test test in juneau-integration-tests for the canonical
pattern.
OpenAPI surface:
The greedy /* handler is not API-meaningful and is excluded from generated
Swagger / OpenAPI specs via @OpSwagger(ignore=true).
See Also:
- Since:
- 10.0.0
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault base path applied when noJspMixin.Builder.basePath(String)call has been made.static final booleanDefault cache-templates setting —true. -
Constructor Summary
ConstructorsModifierConstructorDescriptionJspMixin()No-arg constructor — usesDEFAULT_BASE_PATHas the base path.protectedJspMixin(JspMixin.Builder builder) Builder constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic JspMixin.Buildercreate()Creates a new builder.Returns the base path under which.jspresources are resolved.booleanReturns the configured cache-templates flag.voidrender(String path, RestRequest req, RestResponse res) [GET /jsp/*] — forward the request to the JSP engine.
-
Field Details
-
DEFAULT_BASE_PATH
Default base path applied when noJspMixin.Builder.basePath(String)call has been made.- See Also:
-
DEFAULT_CACHE_TEMPLATES
Default cache-templates setting —true. Reported forViewMixinBuilderconformance only; seeJspMixin.Builder.cacheTemplates(boolean).- See Also:
-
-
Constructor Details
-
JspMixin
public JspMixin()No-arg constructor — usesDEFAULT_BASE_PATHas the base path.The mixin walk falls back to this constructor when the
BeanStoredoes not have a registeredJspMixinbean. -
JspMixin
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.jspresources are resolved.Read by
JspViewRendererwhen dispatching aJspView-typed return value, and by therender(...)handler when forwarding raw-.jsprequests under/jsp/*.- Returns:
- The base path. Never
null.
-
isCacheTemplates
Returns the configured cache-templates flag.Reported for
ViewMixinBuilderconformance only — JSP recompilation is delegated entirely to the servlet container (seeJspMixin.Builder.cacheTemplates(boolean)for the full caveat).- Returns:
- The cache flag. Defaults to
DEFAULT_CACHE_TEMPLATES.
-
render
public void render(@Path("/*") String path, RestRequest req, RestResponse res) throws IOException, NotFound [GET /jsp/*] — forward the request to the JSP engine.The
@Path("/*") String pathcaptures the multi-segment trailing remainder (e.g. a request for/jsp/admin/dashboard.jspmatches the mount withpath = "admin/dashboard.jsp"). Delegates to the sharedJspDispatcherworker, which dispatches viaServletContext.getRequestDispatcher(basePath + path).forward(...)so the container's JSP engine renders the template.Missing JSP resources surface as a 404 from the underlying container; missing JSP engine surfaces as
JspViewRenderer.NO_ENGINE_DIAGNOSTIC.- Parameters:
path- The trailing path segment after/jsp/(the JSP file name relative to the configuredbase path).req- The current REST request.res- The current REST response.- Throws:
IOException- If the underlying servlet writer fails.NotFound- If the JSP resource cannot be resolved.
-