Class TemplateRedirect


  • public class TemplateRedirect
    extends java.lang.Object
    Performs redirection of template request into rest context. Note that even if no special rest mapped for template, but request looks like direct file template, it would be rendered with the DirectTemplateExceptionMapper.

    Rest resource convention: /[rest context]/[prefix]/[path from request], where [prefix] is application registration name by default (but may be configured). Additional mappings may be configured to sub url, so redirection to different rest "branches" may be performed, depending on called url.

    If resource is annotated with Template annotation (it should!) then TemplateAnnotationFilter will detect it and set specified template into context TemplateContext.

    Important: resources must use TemplateView as base template model class in order to properly support Template annotation.

    Since:
    03.12.2018
    • Constructor Detail

      • TemplateRedirect

        public TemplateRedirect​(jakarta.servlet.Servlet restServlet,
                                java.lang.String app,
                                java.lang.String mapping,
                                ViewRestLookup views,
                                AssetLookup assets,
                                ErrorRedirect errorRedirect)
    • Method Detail

      • setRootPath

        public void setRootPath​(java.lang.String contextPath,
                                java.lang.String servletMapping)
        Parameters:
        contextPath - main context mapping path
        servletMapping - rest servlet mapping path
      • redirect

        public void redirect​(jakarta.servlet.http.HttpServletRequest request,
                             jakarta.servlet.http.HttpServletResponse response,
                             java.lang.String page,
                             boolean directTemplate)
                      throws java.io.IOException,
                             jakarta.servlet.ServletException
        Redirect template request into rest resource. Jersey will select appropriate resource by path, or thrown not found exception, received by DirectTemplateExceptionMapper (to render direct template instead).
        Parameters:
        request - template request
        response - template response
        page - requested template path (cleared for matching)
        directTemplate - true if target path looks like template call
        Throws:
        java.io.IOException - on dispatching errors
        jakarta.servlet.ServletException - on dispatching errors
      • getErrorRedirect

        public ErrorRedirect getErrorRedirect()
        Returns:
        custom error pages support
      • getRootPath

        public java.lang.String getRootPath()
        Returns:
        root rest mapping path
      • templateContext

        public static TemplateContext templateContext()
        Returns:
        thread bound template context or null