Class MustacheViewRenderer

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

public class MustacheViewRenderer extends Object implements ViewRenderer
ResponseProcessor that detects MustacheView-typed return values and asks the configured MustacheFactory to render them directly onto the response writer.

Auto-registered by MustacheMixin via @Rest(responseProcessors=...) — callers who add the mixin don't need to wire up this class explicitly. Callers who want to handle MustacheView returns without adopting the mixin can add this class to their own responseProcessors list.

Behavior:
  1. Inspect the response content. If the value is not a MustacheView, return NEXT so the rest of the chain runs.
  2. Read the active MustacheMixin from the RestContext bean store to discover the MustacheFactory (lazy default if no factory bean is registered) and the optional template-suffix knob.
  3. Apply every entry from MustacheView.getResponseHeaders() via res.setHeader(...).
  4. Default Content-Type to text/html;charset=UTF-8 if the caller did not set one explicitly (Mustache is content-neutral, but HTML is overwhelmingly the most common output target; an explicit caller header wins).
  5. Call factory.compile(templateName).execute(res.getWriter(), view.getAttributes()) to stream the rendered output.
  6. When no Mustache engine is on the classpath, the MustacheFactory-typed import here fails to load at first use and surfaces NO_ENGINE_DIAGNOSTIC naming the missing dependency.
See Also:
Since:
10.0.0
  • Field Details

    • DEFAULT_CONTENT_TYPE

      public static final String DEFAULT_CONTENT_TYPE
      Default Content-Type applied when the view does not specify one explicitly.
      See Also:
    • NO_ENGINE_DIAGNOSTIC

      public static final String NO_ENGINE_DIAGNOSTIC
      Diagnostic message emitted when no Mustache engine can be found on the classpath at render-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.