incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r1221900 - in /sling/trunk: bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/ launchpad/builder/src/main/bundles/ launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/ ...
Date Wed, 21 Dec 2011 22:02:15 GMT
Author: justin
Date: Wed Dec 21 22:02:14 2011
New Revision: 1221900

URL: http://svn.apache.org/viewvc?rev=1221900&view=rev
Log:
SLING-2340 - separating use cases for forward into normal and forwarding to an error page

Modified:
    sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/PageContextImpl.java
    sling/trunk/launchpad/builder/src/main/bundles/list.xml
    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JspForwardTest.java
    sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/forward-test.jsp

Modified: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/PageContextImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/PageContextImpl.java?rev=1221900&r1=1221899&r2=1221900&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/PageContextImpl.java
(original)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/PageContextImpl.java
Wed Dec 21 22:02:14 2011
@@ -50,6 +50,7 @@ import javax.servlet.jsp.tagext.BodyCont
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.apache.sling.scripting.jsp.SlingPageException;
+import org.apache.sling.scripting.jsp.jasper.Constants;
 import org.apache.sling.scripting.jsp.jasper.compiler.Localizer;
 import org.apache.sling.scripting.jsp.jasper.el.ELContextImpl;
 import org.apache.sling.scripting.jsp.jasper.el.ExpressionEvaluatorImpl;
@@ -690,9 +691,65 @@ public class PageContextImpl extends Pag
 
 		final String path = getAbsolutePathRelativeToContext(relativeUrlPath);
 
-		throw new SlingPageException(path);
+		final String includeUri = (String) request.getAttribute(Constants.INC_SERVLET_PATH);
+
+        if (includeUri != null)
+            request.removeAttribute(Constants.INC_SERVLET_PATH);
+        try {
+            context.getRequestDispatcher(path).forward(request, response);
+        } finally {
+            if (includeUri != null) {
+                request.setAttribute(Constants.INC_SERVLET_PATH, includeUri);
+            }
+        }
  	}
 
+    public void forwardToErrorPage(final String relativeUrlPath) throws ServletException,
+            IOException {
+        if (SecurityUtil.isPackageProtectionEnabled()) {
+            try {
+                AccessController.doPrivileged(new PrivilegedExceptionAction() {
+                    public Object run() throws Exception {
+                        doForwardToErrorPage(relativeUrlPath);
+                        return null;
+                    }
+                });
+            } catch (PrivilegedActionException e) {
+                Exception ex = e.getException();
+                if (ex instanceof IOException) {
+                    throw (IOException) ex;
+                } else {
+                    throw (ServletException) ex;
+                }
+            }
+        } else {
+            doForwardToErrorPage(relativeUrlPath);
+        }
+    }
+
+    private void doForwardToErrorPage(String relativeUrlPath) throws ServletException,
+            IOException {
+
+        // JSP.4.5 If the buffer was flushed, throw IllegalStateException
+        try {
+            out.clear();
+        } catch (IOException ex) {
+            IllegalStateException ise = new IllegalStateException(Localizer
+                    .getMessage("jsp.error.attempt_to_clear_flushed_buffer"));
+            ise.initCause(ex);
+            throw ise;
+        }
+
+        // Make sure that the response object is not the wrapper for include
+        while (response instanceof ServletResponseWrapperInclude) {
+            response = ((ServletResponseWrapperInclude) response).getResponse();
+        }
+
+        final String path = getAbsolutePathRelativeToContext(relativeUrlPath);
+
+        throw new SlingPageException(path);
+    }
+
 	public BodyContent pushBody() {
 		return (BodyContent) pushBody(null);
 	}
@@ -798,7 +855,7 @@ public class PageContextImpl extends Pag
 			request.setAttribute("javax.servlet.error.servlet_name", config
 					.getServletName());
 			try {
-				forward(errorPageURL);
+				forwardToErrorPage(errorPageURL);
 			} catch (IllegalStateException ise) {
 				include(errorPageURL);
 			}

Modified: sling/trunk/launchpad/builder/src/main/bundles/list.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/builder/src/main/bundles/list.xml?rev=1221900&r1=1221899&r2=1221900&view=diff
==============================================================================
--- sling/trunk/launchpad/builder/src/main/bundles/list.xml (original)
+++ sling/trunk/launchpad/builder/src/main/bundles/list.xml Wed Dec 21 22:02:14 2011
@@ -180,7 +180,7 @@
         <bundle>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.scripting.jsp</artifactId>
-            <version>2.0.17-SNAPSHOT</version>
+            <version>2.0.19-SNAPSHOT</version>
         </bundle>
         <bundle>
             <groupId>org.apache.sling</groupId>

Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JspForwardTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JspForwardTest.java?rev=1221900&r1=1221899&r2=1221900&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JspForwardTest.java
(original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JspForwardTest.java
Wed Dec 21 22:02:14 2011
@@ -36,6 +36,7 @@ import org.apache.sling.servlets.post.Sl
     private String nodeUrlC;
     private String nodeUrlD;
     private String nodeUrlE;
+    private String nodeUrlF;
     private String scriptPath;
     private String forcedResourceType;
     private Set<String> toDelete = new HashSet<String>();
@@ -66,8 +67,14 @@ import org.apache.sling.servlets.post.Sl
         props.put("pathToInclude", pathToInclude + ".html");
         nodeUrlE = testClient.createNode(url, props);
 
+        // Node F is like E but uses jsp:include
+        props.put("pathToInclude", pathToInclude + ".html");
+        props.put("forwardStyle", "jsp");
+        nodeUrlF = testClient.createNode(url, props);
+
         // Node C is used for the infinite loop detection test
         props.remove("pathToInclude");
+        props.remove("forwardStyle");
         props.put("testInfiniteLoop","true");
         nodeUrlC = testClient.createNode(url, props);
 
@@ -117,6 +124,13 @@ import org.apache.sling.servlets.post.Sl
         assertTrue("Text of node A is not included (" + content + ")",!content.contains(testTextB));
     }
 
+    public void testWithJspForward() throws IOException {
+        final String content = getContent(nodeUrlF + ".html", CONTENT_TYPE_HTML);
+        assertTrue("Content includes JSP marker",content.contains("JSP template"));
+        assertTrue("Content contains formatted test text",content.contains("<p class=\"main\">"
+ testTextA + "</p>"));
+        assertTrue("Text of node A is not included (" + content + ")",!content.contains(testTextB));
+    }
+
     public void testInfiniteLoopDetection() throws IOException {
         // Node C has a property that causes an infinite include loop,
         // Sling must indicate the problem in its response

Modified: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/forward-test.jsp
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/forward-test.jsp?rev=1221900&r1=1221899&r2=1221900&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/forward-test.jsp
(original)
+++ sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/forward-test.jsp
Wed Dec 21 22:02:14 2011
@@ -39,6 +39,7 @@ private String getProperty(javax.jcr.Nod
 String pathToInclude = getProperty(currentNode, "pathToInclude");
 String forceResourceType = getProperty(currentNode, "forceResourceType");
 String testInfiniteLoop = getProperty(currentNode, "testInfiniteLoop");
+String forwardStyle = getProperty(currentNode, "forwardStyle");
 
 // Test 3: Forced Resource Type
 if(pathToInclude != null && forceResourceType != null) {
@@ -49,7 +50,11 @@ else
 
 // Test 1: Simple Forward 
 if(pathToInclude != null) {
-    %><sling:forward path="<%= pathToInclude %>"/><%
+    if ("jsp".equals(forwardStyle)) {
+        %><jsp:forward page="<%= pathToInclude %>"/><%
+    } else {
+        %><sling:forward path="<%= pathToInclude %>"/><%
+    }
 }
 
 else



Mime
View raw message