Sunday 20 March 2016

Error Page Handler Using ACS Commons

Goal:

Provide an author-able means for defining, creating and managing custom Error pages per content tree/site.

How to use:

  • Create the proxy overlays for Sling errorhandler scripts (404.jsp and default.jsp) which include the acs-commons counterparts.
  • Create the overlay for 404.jsp
    • /apps/sling/servlet/errorhandler/404.jsp
    • <%@page session="false"%><%%><%@include file="/apps/acs-commons/components/utilities/errorpagehandler/default.jsp" %>
  • In your base page implementation, add the following cq:Widget to the Page Properties dialog
    • <errorpages jcr:primaryType="cq:Widget" path="/apps/acs-commons/components/utilities/errorpagehandler/dialog/errorpages.infinity.json" xtype="cqinclude"/>
  • Create a sling:OsgiConfig node to enable the Error Page Handler
    • /apps/myapp/config/com.adobe.acs.commons.errorpagehandler.impl.ErrorPageHandlerImpl.xml

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="sling:OsgiConfig"
enabled="{Boolean}true"
cache.serve-authenticated="{Boolean}true"
cache.ttl="{Long}300"/>

  • Create a CQ Page that will act as the default Error page, and also contain all custom variations of error pages. Each error page’s “name” (Node name) should correspond to the HTTP Response Status code it should respond to.
    • 500: Internal Server Error
    • 404: Not Found
    • 403: Forbidden
  • Create the above pages under root page of the project structure e.g., /content/projectroot/errors/500
  • Finally, Edit the Page Properties of the site’s root node, and in the new “Error Pages” dialog input
More Links:

1 comment:

  1. You should actually provide a note that this does not work for sightly or HTL pages.

    ReplyDelete