This is an automated email from the ASF dual-hosted git repository.

dklco pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git


The following commit(s) were added to refs/heads/master by this push:
     new dc3df36  Fixing an issue where the user was not showing a Sling CMS 
Page when the first accessed the application
dc3df36 is described below

commit dc3df362dc7cb14976213b9bc0992757cf67a32d
Author: Dan Klco <[email protected]>
AuthorDate: Thu May 3 15:08:08 2018 -0400

    Fixing an issue where the user was not showing a Sling CMS Page when the
    first accessed the application
---
 cms/builder/src/main/provisioning/repoinit.txt     |  5 ++
 .../apache/sling/cms/core/models/ErrorHandler.java | 56 +++++++++++++++-------
 .../sling-cms/errorhandling/401.json}              |  4 +-
 .../sling-cms/errorhandling/403.json}              |  4 +-
 .../sling-cms}/errorhandling/404.json              |  0
 .../sling-cms}/errorhandling/default.json          |  0
 .../libs/sling/servlet/errorhandler/default.jsp    |  4 +-
 7 files changed, 50 insertions(+), 23 deletions(-)

diff --git a/cms/builder/src/main/provisioning/repoinit.txt 
b/cms/builder/src/main/provisioning/repoinit.txt
index 9e1227b..f7f439a 100644
--- a/cms/builder/src/main/provisioning/repoinit.txt
+++ b/cms/builder/src/main/provisioning/repoinit.txt
@@ -29,6 +29,11 @@
     set ACL for everyone
         allow   jcr:read       on /content
     end
+    
+    create path (sling:OrderedFolder) /etc/clientlibs
+    set ACL for everyone
+        allow   jcr:read       on /etc/clientlibs
+    end
 
     # sling-mapping
     create service user sling-mapping
diff --git 
a/cms/core/src/main/java/org/apache/sling/cms/core/models/ErrorHandler.java 
b/cms/core/src/main/java/org/apache/sling/cms/core/models/ErrorHandler.java
index bceb46c..6d470ce 100644
--- a/cms/core/src/main/java/org/apache/sling/cms/core/models/ErrorHandler.java
+++ b/cms/core/src/main/java/org/apache/sling/cms/core/models/ErrorHandler.java
@@ -16,8 +16,11 @@
  */
 package org.apache.sling.cms.core.models;
 
+import java.io.IOException;
+
 import javax.annotation.PostConstruct;
 import javax.inject.Named;
+import javax.servlet.http.HttpServletResponse;
 
 import org.apache.sling.api.SlingConstants;
 import org.apache.sling.api.SlingHttpServletRequest;
@@ -27,6 +30,7 @@ import org.apache.sling.models.annotations.Default;
 import org.apache.sling.models.annotations.Model;
 import org.apache.sling.models.annotations.Optional;
 import org.apache.sling.models.annotations.injectorspecific.RequestAttribute;
+import org.apache.sling.models.annotations.injectorspecific.SlingObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -50,13 +54,16 @@ public class ErrorHandler {
        private SlingHttpServletRequest slingRequest;
 
        private Resource handler;
+       
+       @SlingObject
+       private HttpServletResponse response;
 
        public ErrorHandler(SlingHttpServletRequest slingRequest) {
                this.slingRequest = slingRequest;
        }
 
        @PostConstruct
-       public void init() {
+       public void init() throws IOException {
 
                Resource resource = slingRequest.getResource();
                ResourceResolver resolver = slingRequest.getResourceResolver();
@@ -67,34 +74,49 @@ public class ErrorHandler {
                        log.warn("Handing exception of type " + errorCode,
                                        
slingRequest.getAttribute(SlingConstants.ERROR_EXCEPTION));
                }
-               SiteManager siteMgr = resource.adaptTo(SiteManager.class);
-               if (siteMgr != null && siteMgr.getSite() != null) {
-                       Site site = siteMgr.getSite();
-                       log.debug("Checking for error pages in the site {}", 
site.getPath());
-
-                       handler = site.getResource().getChild("errors/" + 
errorCode.toString());
-                       if (handler == null) {
-                               handler = 
site.getResource().getChild("errors/default");
-                       }
-
-                       if (handler != null) {
-                               log.debug("Using error handler {}", handler);
-                       } else {
-                               log.debug("No error page defined for site {}", 
site.getPath());
+               
+               
+               try {
+                       SiteManager siteMgr = 
resource.adaptTo(SiteManager.class);
+                       if (siteMgr != null && siteMgr.getSite() != null) {
+                               Site site = siteMgr.getSite();
+                               log.debug("Checking for error pages in the site 
{}", site.getPath());
+
+                               handler = site.getResource().getChild("errors/" 
+ errorCode.toString());
+                               if (handler == null) {
+                                       handler = 
site.getResource().getChild("errors/default");
+                               }
+
+                               if (handler != null) {
+                                       log.debug("Using error handler {}", 
handler);
+                               } else {
+                                       log.debug("No error page defined for 
site {}", site.getPath());
+                               }
                        }
+               } catch (Exception e) {
+                       log.debug("Failed to retrieve current site, using 
default error handling");
                }
 
                if (handler == null) {
                        log.debug("Using Sling CMS default error pages");
-                       handler = 
resolver.getResource("/libs/sling-cms/content/errorhandling/" + 
errorCode.toString());
+                       handler = 
resolver.getResource("/content/sling-cms/errorhandling/" + 
errorCode.toString());
                        if (handler == null) {
-                               handler = 
resolver.getResource("/libs/sling-cms/content/errorhandling/default");
+                               handler = 
resolver.getResource("/content/sling-cms/errorhandling/default");
                        }
                        log.debug("Using Sling CMS error handler {}", handler);
                }
+               
+               log.debug("Sending error {}",errorCode);
+               response.sendError(errorCode);
+               
+               log.debug("Error handler initialized successfully!");
        }
 
        public Resource getHandler() {
                return handler;
        }
+       
+       public int getErrorCode() {
+               return errorCode;
+       }
 }
diff --git 
a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/errorhandling/404.json
 b/cms/ui/src/main/resources/jcr_root/content/sling-cms/errorhandling/401.json
similarity index 71%
copy from 
cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/errorhandling/404.json
copy to 
cms/ui/src/main/resources/jcr_root/content/sling-cms/errorhandling/401.json
index 0518c56..804e702 100644
--- 
a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/errorhandling/404.json
+++ 
b/cms/ui/src/main/resources/jcr_root/content/sling-cms/errorhandling/401.json
@@ -2,7 +2,7 @@
        "jcr:primaryType": "sling:Page",
        "jcr:content": {
                "sling:resourceType": "sling-cms/components/pages/error",
-               "jcr:title": "Not Found",
+               "jcr:title": "Unauthorized",
                "jcr:primaryType": "nt:unstructured",
                "container": {
                        "jcr:primaryType": "nt:unstructured",
@@ -10,7 +10,7 @@
                        "richtext": {
                                "jcr:primaryType": "nt:unstructured",
                                "sling:resourceType": 
"sling-cms/components/general/richtext",
-                               "text": "<h3>Not Found</h3><p>The requested 
content was not found.</p>"
+                               "text": "<h3>Unauthorized</h3><p>You cannot 
access the requested resource.</p><p><a 
href=\"/system/sling/form/login\">Login?</a>"
                        }
                }
        }
diff --git 
a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/errorhandling/404.json
 b/cms/ui/src/main/resources/jcr_root/content/sling-cms/errorhandling/403.json
similarity index 72%
copy from 
cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/errorhandling/404.json
copy to 
cms/ui/src/main/resources/jcr_root/content/sling-cms/errorhandling/403.json
index 0518c56..fd97e16 100644
--- 
a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/errorhandling/404.json
+++ 
b/cms/ui/src/main/resources/jcr_root/content/sling-cms/errorhandling/403.json
@@ -2,7 +2,7 @@
        "jcr:primaryType": "sling:Page",
        "jcr:content": {
                "sling:resourceType": "sling-cms/components/pages/error",
-               "jcr:title": "Not Found",
+               "jcr:title": "Forbidden",
                "jcr:primaryType": "nt:unstructured",
                "container": {
                        "jcr:primaryType": "nt:unstructured",
@@ -10,7 +10,7 @@
                        "richtext": {
                                "jcr:primaryType": "nt:unstructured",
                                "sling:resourceType": 
"sling-cms/components/general/richtext",
-                               "text": "<h3>Not Found</h3><p>The requested 
content was not found.</p>"
+                               "text": "<h3>Forbidden</h3><p>You cannot access 
the requested resource.</p><p><a href=\"/system/sling/form/login\">Login?</a>"
                        }
                }
        }
diff --git 
a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/errorhandling/404.json
 b/cms/ui/src/main/resources/jcr_root/content/sling-cms/errorhandling/404.json
similarity index 100%
rename from 
cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/errorhandling/404.json
rename to 
cms/ui/src/main/resources/jcr_root/content/sling-cms/errorhandling/404.json
diff --git 
a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/errorhandling/default.json
 
b/cms/ui/src/main/resources/jcr_root/content/sling-cms/errorhandling/default.json
similarity index 100%
rename from 
cms/ui/src/main/resources/jcr_root/libs/sling-cms/content/errorhandling/default.json
rename to 
cms/ui/src/main/resources/jcr_root/content/sling-cms/errorhandling/default.json
diff --git 
a/cms/ui/src/main/resources/jcr_root/libs/sling/servlet/errorhandler/default.jsp
 
b/cms/ui/src/main/resources/jcr_root/libs/sling/servlet/errorhandler/default.jsp
index 92e0d12..317c9a4 100644
--- 
a/cms/ui/src/main/resources/jcr_root/libs/sling/servlet/errorhandler/default.jsp
+++ 
b/cms/ui/src/main/resources/jcr_root/libs/sling/servlet/errorhandler/default.jsp
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */ --%>
- <%@ page language="java" contentType="text/html; charset=UTF-8" 
pageEncoding="UTF-8"%>
- <%@include file="/libs/sling-cms/global.jsp"%>
+<%@ page language="java" contentType="text/html; charset=UTF-8" 
pageEncoding="UTF-8"%>
+<%@include file="/libs/sling-cms/global.jsp"%>
 <sling:adaptTo var="errorHandler" adaptable="${slingRequest}" 
adaptTo="org.apache.sling.cms.core.models.ErrorHandler" />
 <sling:include 
path="${sling:getRelativeResource(errorHandler.handler,'jcr:content').path}.html"
 
resourceType="${sling:getRelativeResource(errorHandler.handler,'jcr:content').resourceType}"
 />
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to