cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r785003 - in /cocoon/cocoon3/trunk: cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/ cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/ cocoon-sample/src/test/java/org/apache/cocoon/sitemap/ cocoon-servlet/src...
Date Mon, 15 Jun 2009 22:02:43 GMT
Author: reinhard
Date: Mon Jun 15 22:02:42 2009
New Revision: 785003

URL: http://svn.apache.org/viewvc?rev=785003&view=rev
Log:
Don't lose the status-code produced by the called servlet-service in REST controller instances.
This replaces the hack from r783149 and uses the already available CallStack from the Cocoon
Servlet-Service framework.

Added:
    cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RestResponseMetaData.java
  (with props)
    cocoon/cocoon3/trunk/cocoon-sample/src/test/java/org/apache/cocoon/sitemap/MockServletContext.java
  (with props)
Modified:
    cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/SpringRESTController.java
    cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RedirectResponse.java
    cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RestResponse.java
    cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/Status.java
    cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/URLResponse.java
    cocoon/cocoon3/trunk/cocoon-sample/src/test/java/org/apache/cocoon/sitemap/SitemapBuilderTest.java
    cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/XMLSitemapServlet.java
    cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/node/StatusCodeCollector.java

Modified: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/SpringRESTController.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/SpringRESTController.java?rev=785003&r1=785002&r2=785003&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/SpringRESTController.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/SpringRESTController.java
Mon Jun 15 22:02:42 2009
@@ -41,6 +41,7 @@
 import org.apache.cocoon.rest.controller.annotation.RequestParameter;
 import org.apache.cocoon.rest.controller.annotation.SitemapParameter;
 import org.apache.cocoon.rest.controller.response.RestResponse;
+import org.apache.cocoon.rest.controller.response.RestResponseMetaData;
 import org.apache.cocoon.rest.controller.util.AnnotationCollector;
 import org.apache.cocoon.servlet.node.StatusCodeCollector;
 import org.apache.cocoon.servlet.util.HttpContextHelper;
@@ -84,20 +85,14 @@
             HttpServletRequest request = HttpContextHelper.getRequest(inputParameters);
             RestResponse restResponse = this.methodDelegator.delegate(request, controller);
 
-            // store the status code
-            int statusCode = StatusCodeCollector.getStatusCode();
-
             // execute the rest response
-            String contentType = restResponse.execute(outputStream, inputParameters);
+            RestResponseMetaData restResponseMetaData = restResponse.execute(outputStream,
inputParameters);
 
-            // restore the status code in the case the status-code wasn't explicitly set
by the
-            // rest-response execution
-            if (StatusCodeCollector.getStatusCode() == 0) {
-                StatusCodeCollector.setStatusCode(statusCode);
-            }
+            // set the status-code with the result produced by the restResponse execution
+            StatusCodeCollector.setStatusCode(restResponseMetaData.getStatusCode());
 
             // return the content type
-            return contentType;
+            return restResponseMetaData.getContentType();
         } catch (Exception e) {
             throw ExceptionHandler.getInvocationException(e);
         }

Modified: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RedirectResponse.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RedirectResponse.java?rev=785003&r1=785002&r2=785003&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RedirectResponse.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RedirectResponse.java
Mon Jun 15 22:02:42 2009
@@ -32,7 +32,8 @@
         this.location = location;
     }
 
-    public String execute(OutputStream outputStream, Map<String, Object> inputParameters)
throws Exception {
+    public RestResponseMetaData execute(OutputStream outputStream, Map<String, Object>
inputParameters)
+            throws Exception {
         HttpServletResponse response = HttpContextHelper.getResponse(inputParameters);
         response.sendRedirect(this.location);
 

Modified: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RestResponse.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RestResponse.java?rev=785003&r1=785002&r2=785003&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RestResponse.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RestResponse.java
Mon Jun 15 22:02:42 2009
@@ -21,5 +21,5 @@
 
 public interface RestResponse {
 
-    String execute(OutputStream outputStream, Map<String, Object> inputParameters)
throws Exception;
+    RestResponseMetaData execute(OutputStream outputStream, Map<String, Object> inputParameters)
throws Exception;
 }

Added: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RestResponseMetaData.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RestResponseMetaData.java?rev=785003&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RestResponseMetaData.java
(added)
+++ cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RestResponseMetaData.java
Mon Jun 15 22:02:42 2009
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.rest.controller.response;
+
+import javax.servlet.http.HttpServletResponse;
+
+public class RestResponseMetaData {
+
+    private String contentType;
+    private int statusCode;
+
+    public RestResponseMetaData() {
+        this(null, HttpServletResponse.SC_OK);
+    }
+
+    public RestResponseMetaData(int status) {
+        this(null, status);
+    }
+
+    public RestResponseMetaData(String contentType, int statusCode) {
+        super();
+
+        this.contentType = contentType;
+        this.statusCode = statusCode;
+    }
+
+    public String getContentType() {
+        return this.contentType;
+    }
+
+    public int getStatusCode() {
+        return this.statusCode;
+    }
+
+    public void setContentType(String contentType) {
+        this.contentType = contentType;
+    }
+
+    public void setStatusCode(int statusCode) {
+        this.statusCode = statusCode;
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RestResponseMetaData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RestResponseMetaData.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/RestResponseMetaData.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/Status.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/Status.java?rev=785003&r1=785002&r2=785003&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/Status.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/Status.java
Mon Jun 15 22:02:42 2009
@@ -19,8 +19,6 @@
 import java.io.OutputStream;
 import java.util.Map;
 
-import org.apache.cocoon.servlet.node.StatusCodeCollector;
-
 public class Status implements RestResponse {
 
     private int status;
@@ -33,8 +31,7 @@
         return this.status;
     }
 
-    public String execute(OutputStream outputStream, Map<String, Object> inputParameters)
{
-        StatusCodeCollector.setStatusCode(this.status);
-        return null;
+    public RestResponseMetaData execute(OutputStream outputStream, Map<String, Object>
inputParameters) {
+        return new RestResponseMetaData(this.status);
     }
 }

Modified: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/URLResponse.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/URLResponse.java?rev=785003&r1=785002&r2=785003&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/URLResponse.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/URLResponse.java
Mon Jun 15 22:02:42 2009
@@ -17,6 +17,7 @@
 package org.apache.cocoon.rest.controller.response;
 
 import java.io.OutputStream;
+import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
@@ -68,7 +69,8 @@
         return this.url;
     }
 
-    public String execute(OutputStream outputStream, Map<String, Object> inputParameters)
throws Exception {
+    public RestResponseMetaData execute(OutputStream outputStream, Map<String, Object>
inputParameters)
+            throws Exception {
         URLConnection servletConnection = null;
         try {
             ControllerContextHelper.storeContext(this.data, inputParameters);
@@ -76,7 +78,15 @@
             servletConnection = this.url.openConnection();
             IOUtils.copy(servletConnection.getInputStream(), outputStream);
 
-            return servletConnection.getContentEncoding();
+            RestResponseMetaData restResponseMetaData = new RestResponseMetaData();
+
+            if (servletConnection instanceof HttpURLConnection) {
+                HttpURLConnection httpURLConnection = (HttpURLConnection) servletConnection;
+                restResponseMetaData.setStatusCode(httpURLConnection.getResponseCode());
+            }
+
+            restResponseMetaData.setContentType(servletConnection.getContentEncoding());
+            return restResponseMetaData;
         } finally {
             URLConnectionUtils.closeQuietly(servletConnection);
         }

Added: cocoon/cocoon3/trunk/cocoon-sample/src/test/java/org/apache/cocoon/sitemap/MockServletContext.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sample/src/test/java/org/apache/cocoon/sitemap/MockServletContext.java?rev=785003&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sample/src/test/java/org/apache/cocoon/sitemap/MockServletContext.java
(added)
+++ cocoon/cocoon3/trunk/cocoon-sample/src/test/java/org/apache/cocoon/sitemap/MockServletContext.java
Mon Jun 15 22:02:42 2009
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.sitemap;
+
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Set;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+public class MockServletContext implements ServletContext {
+
+    public Object getAttribute(String name) {
+        return null;
+    }
+
+    public Enumeration getAttributeNames() {
+        return null;
+    }
+
+    public ServletContext getContext(String uripath) {
+        return null;
+    }
+
+    public String getInitParameter(String name) {
+        return null;
+    }
+
+    public Enumeration getInitParameterNames() {
+        return null;
+    }
+
+    public int getMajorVersion() {
+        return 0;
+    }
+
+    public String getMimeType(String file) {
+        return null;
+    }
+
+    public int getMinorVersion() {
+        return 0;
+    }
+
+    public RequestDispatcher getNamedDispatcher(String name) {
+        return null;
+    }
+
+    public String getRealPath(String path) {
+        return null;
+    }
+
+    public RequestDispatcher getRequestDispatcher(String path) {
+        return null;
+    }
+
+    public URL getResource(String path) throws MalformedURLException {
+        return null;
+    }
+
+    public InputStream getResourceAsStream(String path) {
+        return null;
+    }
+
+    public Set getResourcePaths(String path) {
+        return null;
+    }
+
+    public String getServerInfo() {
+        return null;
+    }
+
+    public Servlet getServlet(String name) throws ServletException {
+        return null;
+    }
+
+    public String getServletContextName() {
+        return null;
+    }
+
+    public Enumeration getServletNames() {
+        return null;
+    }
+
+    public Enumeration getServlets() {
+        return null;
+    }
+
+    public void log(String msg) {
+    }
+
+    public void log(Exception exception, String msg) {
+    }
+
+    public void log(String message, Throwable throwable) {
+    }
+
+    public void removeAttribute(String name) {
+    }
+
+    public void setAttribute(String name, Object object) {
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-sample/src/test/java/org/apache/cocoon/sitemap/MockServletContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-sample/src/test/java/org/apache/cocoon/sitemap/MockServletContext.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-sample/src/test/java/org/apache/cocoon/sitemap/MockServletContext.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/cocoon3/trunk/cocoon-sample/src/test/java/org/apache/cocoon/sitemap/SitemapBuilderTest.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sample/src/test/java/org/apache/cocoon/sitemap/SitemapBuilderTest.java?rev=785003&r1=785002&r2=785003&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sample/src/test/java/org/apache/cocoon/sitemap/SitemapBuilderTest.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-sample/src/test/java/org/apache/cocoon/sitemap/SitemapBuilderTest.java
Mon Jun 15 22:02:42 2009
@@ -19,6 +19,7 @@
 package org.apache.cocoon.sitemap;
 
 import java.net.URL;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -29,6 +30,7 @@
 import org.apache.cocoon.sample.action.CustomException;
 import org.apache.cocoon.servlet.node.StatusCodeCollector;
 import org.apache.cocoon.servlet.util.HttpContextHelper;
+import org.apache.cocoon.servletservice.CallStackHelper;
 import org.apache.cocoon.sitemap.node.InvocationResult;
 import org.apache.cocoon.sitemap.node.SitemapNode;
 import org.apache.cocoon.sitemap.objectmodel.ObjectModel;
@@ -57,10 +59,13 @@
         // invocation.getThrowable() instanceof CustomException);
     }
 
-    public void testErrorHandlingPipeline() {
+    @SuppressWarnings("unchecked")
+    public void testErrorHandlingPipeline() throws Exception {
         Invocation invocation = this.buildInvocation("error-handling/custom-error-per-pipeline-error-handling");
         MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
         HttpContextHelper.storeResponse(mockHttpServletResponse, invocation.getParameters());
+        CallStackHelper.enterServlet(new MockServletContext(), new MockHttpServletRequest(Collections.EMPTY_MAP),
+                mockHttpServletResponse);
 
         this.sitemap.invoke(invocation);
         // invocation should be marked as error-invocation
@@ -70,13 +75,18 @@
                 invocation.getThrowable() instanceof CustomException);
 
         assertEquals(501, StatusCodeCollector.getStatusCode());
+        CallStackHelper.leaveServlet();
     }
 
-    public void testGenerator() {
+    @SuppressWarnings("unchecked")
+    public void testGenerator() throws Exception {
         Invocation invocation = this.buildInvocation("sax-pipeline/unauthorized");
         MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
         HttpContextHelper.storeResponse(mockHttpServletResponse, invocation.getParameters());
 
+        CallStackHelper.enterServlet(new MockServletContext(), new MockHttpServletRequest(Collections.EMPTY_MAP),
+                mockHttpServletResponse);
+
         InvocationResult invocationResult = this.sitemap.invoke(invocation);
         assertNotNull(invocationResult);
         assertSame(InvocationResult.COMPLETED, invocationResult);
@@ -84,9 +94,15 @@
         // invocation should not be marked as error-invocation
         assertFalse(invocation.isErrorInvocation());
         assertEquals(401, StatusCodeCollector.getStatusCode());
+
+        CallStackHelper.leaveServlet();
     }
 
-    public void testNoMatchingPipeline() {
+    @SuppressWarnings("unchecked")
+    public void testNoMatchingPipeline() throws Exception {
+        CallStackHelper.enterServlet(new MockServletContext(), new MockHttpServletRequest(Collections.EMPTY_MAP),
+                new MockHttpServletResponse());
+
         Invocation invocation = this.buildInvocation("unknown");
         InvocationResult invocationResult = this.sitemap.invoke(invocation);
 
@@ -94,20 +110,33 @@
         assertTrue(invocation.isErrorInvocation());
         assertTrue("Expected NoMatchingPipelineException but received " + invocation.getThrowable(),
invocation
                 .getThrowable() instanceof NoMatchingPipelineException);
+
+        CallStackHelper.leaveServlet();
     }
 
-    public void testController() {
+    @SuppressWarnings("unchecked")
+    public void testController() throws Exception {
+        CallStackHelper.enterServlet(new MockServletContext(), new MockHttpServletRequest(Collections.EMPTY_MAP),
+                new MockHttpServletResponse());
+
         Invocation invocation = this.buildInvocation("controller/invoke");
         InvocationResult invocationResult = this.sitemap.invoke(invocation);
         assertNotNull(invocationResult);
         assertTrue(invocationResult.isCompleted());
+
+        CallStackHelper.leaveServlet();
     }
 
-    public void testXSLT() {
+    @SuppressWarnings("unchecked")
+    public void testXSLT() throws Exception {
+        CallStackHelper.enterServlet(new MockServletContext(), new MockHttpServletRequest(Collections.EMPTY_MAP),
+                new MockHttpServletResponse());
+
         Invocation invocation = this.buildInvocation("xslt/main");
         InvocationResult invocationResult = this.sitemap.invoke(invocation);
-
         assertNotNull(invocationResult);
+
+        CallStackHelper.leaveServlet();
     }
 
     public void testObjectModelPipeline() {

Modified: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/XMLSitemapServlet.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/XMLSitemapServlet.java?rev=785003&r1=785002&r2=785003&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/XMLSitemapServlet.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/XMLSitemapServlet.java
Mon Jun 15 22:02:42 2009
@@ -99,7 +99,6 @@
             Settings settings = (Settings) this.beanFactory.getBean(Settings.class.getName());
 
             MimeTypeCollector.clearMimeType();
-            StatusCodeCollector.clearStatusCode();
             LastModifiedCollector.clearLastModified();
 
             // assemble parameters

Modified: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/node/StatusCodeCollector.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/node/StatusCodeCollector.java?rev=785003&r1=785002&r2=785003&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/node/StatusCodeCollector.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/node/StatusCodeCollector.java
Mon Jun 15 22:02:42 2009
@@ -20,6 +20,7 @@
 
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.cocoon.callstack.CallStack;
 import org.apache.cocoon.servlet.XMLSitemapServlet;
 import org.apache.cocoon.sitemap.Invocation;
 import org.apache.cocoon.sitemap.node.InvocationResult;
@@ -32,7 +33,7 @@
 /**
  * This {@link Aspect} is used to collect the status-code property from a {@link SerializeNode}
because the sitemap
  * interpreter doesn't have any dependencies on the Servlet API and doesn't 'know' about
the concepts of HTTP.
- * 
+ *
  * A servlet that uses the the {@link Sitemap} (e.g. the {@link XMLSitemapServlet}) can use
this collector to read the
  * status code and set it on the servlet response object. The collector can also be used
to directly manipulate the
  * status code of the current thread by using the {@link #setStatusCode(int)} method.
@@ -40,24 +41,20 @@
 @Aspect
 public class StatusCodeCollector {
 
-    private static final ThreadLocal<Integer> THREAD_LOCAL = new ThreadLocal<Integer>();
-
-    public static void clearStatusCode() {
-        THREAD_LOCAL.set(null);
-    }
+    private static final String CALL_FRAME_KEY = StatusCodeCollector.class.getName() + "/status-code";
 
     public static int getStatusCode() {
-        Integer integer = THREAD_LOCAL.get();
+        Integer statusCode = (Integer) CallStack.getCurrentFrame().getAttribute(CALL_FRAME_KEY);
 
-        if (integer == null) {
+        if (statusCode == null) {
             return HttpServletResponse.SC_OK;
         }
 
-        return integer.intValue();
+        return statusCode;
     }
 
     public static void setStatusCode(int statusCode) {
-        THREAD_LOCAL.set(statusCode);
+        CallStack.getCurrentFrame().setAttribute(CALL_FRAME_KEY, statusCode);
     }
 
     @Around("execution(* org.apache.cocoon.sitemap.node.SerializeNode.invoke(..)) &&
args(invocation)")
@@ -68,7 +65,7 @@
         InvocationResult invocationResult = (InvocationResult) proceedingJoinPoint.proceed();
 
         if (invocationResult.isContinued() && statusCode != null) {
-            THREAD_LOCAL.set(Integer.valueOf(statusCode));
+            setStatusCode(Integer.valueOf(statusCode));
         }
 
         return invocationResult;



Mime
View raw message