Class JspViewRenderer

java.lang.Object
org.apache.juneau.rest.server.view.jsp.JspViewRenderer
All Implemented Interfaces:
ResponseProcessor, ViewRenderer

public class JspViewRenderer extends Object implements ViewRenderer
ResponseProcessor that detects JspView-typed return values and dispatches them to the underlying JSP engine via ServletContext.getRequestDispatcher(...).forward(...).

Auto-registered by JspMixin via @Rest(responseProcessors=...) — callers who add the mixin don't need to wire up this class explicitly. Callers who want to handle JspView returns without adopting the mixin (e.g. mounting their own raw-JSP path) can add this class to their own responseProcessors list.

Behavior:
  1. Inspect the response content. If the value is not a JspView, return NEXT so the rest of the chain runs (the standard POJO serializer / plain-text fallback handle non-JspView returns).
  2. Read the active JspMixin from the RestContext bean store to discover the configured base path; fall back to "/" when none is registered (a caller using the renderer standalone without the mixin).
  3. Copy every entry from JspView.getAttributes() onto the request as a request attribute via req.setAttribute(...) so the JSP / JSTL EL pipeline can resolve them.
  4. Apply every entry from JspView.getResponseHeaders() via res.setHeader(...).
  5. Obtain the underlying ServletContext, getRequestDispatcher(basePath + templateName), and call forward(...).
  6. When no JSP engine is on the classpath, the dispatcher returns null (or forward fails with ClassNotFoundException). Surface a human-readable diagnostic naming the missing dependency and linking to the "Choosing a JSP engine" matrix.
Note on forward():

forward() resets the response output stream. If a @RestPreCall hook has already written response headers/body before the renderer runs, the forward may fail or produce malformed output. The renderer runs at response-resolution time so this is rarely hit by accident; document the constraint for any user relying on RestPreCall.

See Also:
Since:
10.0.0
  • Field Details

    • NO_ENGINE_DIAGNOSTIC

      public static final String NO_ENGINE_DIAGNOSTIC
      Diagnostic message emitted when no JSP engine can be found on the classpath at forward-time.

      Public so tests and consumer apps can pattern-match against the message text without depending on internal string literals.

      See Also:
  • Constructor Details

  • Method Details

    • process

      public int process(RestOpSession opSession) throws IOException, BasicHttpException
      Description copied from interface: ResponseProcessor
      Process this response if possible.
      Specified by:
      process in interface ResponseProcessor
      Parameters:
      opSession - The HTTP call.
      Returns:
      One of the following codes:
      • 0 - The processor could not handle the request.
      • 1 - The processor was able to fully handle the request.
      • 2 - The processor was able to partially handle the request by replacing the output. The response processors should start over.
      Throws:
      IOException - If low-level exception occurred on output stream.
      Results in a HttpServletResponse.SC_INTERNAL_SERVER_ERROR error.
      BasicHttpException - If some other exception occurred.
      Can be used to provide an appropriate HTTP response code and message.