You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2009/12/08 14:20:37 UTC

svn commit: r888393 - in /cocoon/cocoon3/trunk: cocoon-sample/src/test/java/org/apache/cocoon/sitemap/ cocoon-sample/src/test/resources/ cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/ cocoon-servlet/src/main/resources/META-INF/cocoon...

Author: reinhard
Date: Tue Dec  8 13:20:36 2009
New Revision: 888393

URL: http://svn.apache.org/viewvc?rev=888393&view=rev
Log:
separate reponse header data collection from the store: provide two store implementations, one based on ThreadLocals and the other on the ServletService-Framework CallStack

Added:
    cocoon/cocoon3/trunk/cocoon-sample/src/test/resources/cocoon-sample-test-collector.xml   (with props)
    cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/CallStackCollectorDataStore.java   (with props)
    cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/CollectorDataStore.java   (with props)
    cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/ThreadLocalCollectorDataStore.java   (with props)
Modified:
    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/collector/ResponseHeaderCollector.java
    cocoon/cocoon3/trunk/cocoon-servlet/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-collector.xml

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=888393&r1=888392&r2=888393&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 Tue Dec  8 13:20:36 2009
@@ -19,7 +19,6 @@
 package org.apache.cocoon.sitemap;
 
 import java.net.URL;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -30,10 +29,10 @@
 import org.apache.cocoon.sample.action.CustomException;
 import org.apache.cocoon.servlet.collector.ResponseHeaderCollector;
 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;
+import org.apache.commons.io.output.NullOutputStream;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
@@ -43,31 +42,16 @@
     private SitemapBuilder sitemapBuilder;
     private ComponentProvider componentProvider;
 
-    public void testErrorHandlingGlobal() {
-        // TODO: currently this cannot work since some components for error
-        // handling are still missing
-        // Invocation invocation =
-        // this.buildInvocation("error-handling/custom-error");
-        // InvocationResult invocationResult = this.sitemap.invoke(invocation);
-        // assertNotNull(invocationResult);
-        // assertSame(InvocationResult.COMPLETED, invocationResult);
-        //
-        // // invocation should be marked as error-invocation
-        // assertTrue(invocation.isErrorInvocation());
-        // // the throwable should be our exception
-        // assertTrue(invocation.getThrowable().toString(),
-        // invocation.getThrowable() instanceof CustomException);
-    }
-
-
     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());
 
         this.sitemap.invoke(invocation);
+
         // invocation should be marked as error-invocation
         assertTrue(invocation.isErrorInvocation());
+
         // the throwable should be our exception
         assertTrue("Expected CustomException but received " + invocation.getThrowable(),
                 invocation.getThrowable() instanceof CustomException);
@@ -120,6 +104,7 @@
         requestParameters.put("c", "3");
         HttpContextHelper.storeRequest(new MockHttpServletRequest(requestParameters), invocation.getParameters());
         this.sitemap.invoke(invocation);
+
         // invocation not should be marked as error-invocation
         assertFalse(invocation.isErrorInvocation());
     }
@@ -138,34 +123,16 @@
         assertFalse("InvocationImpl is marked as erroneous", invocation.isErrorInvocation());
     }
 
-    // TODO: steven.dolg [2008-02-21]: cannot work until expression-language is
-    // integrated correctly
-    // public void testExpressionLanguage2() {
-    // InvocationImpl invocation =
-    // this.buildInvocation("expression-language/nested2/test");
-    // this.sitemap.invoke(invocation);
-    // // invocation should not be marked as error-invocation
-    // assertFalse(invocation.isErrorInvocation());
-    // }
-
-    // TODO: steven.dolg [2008-02-21]: cannot work until expression-language is
-    // integrated correctly
-    // public void testExpressionLanguage3() {
-    // InvocationImpl invocation =
-    // this.buildInvocation("expression-language/nested3/test");
-    // this.sitemap.invoke(invocation);
-    // // invocation should not be marked as error-invocation
-    // assertFalse(invocation.isErrorInvocation());
-    // }
-
     public void testReadPipelineExplicit() {
         Invocation invocation = this.buildInvocation("read/javascript-resource-explicit");
         assertTrue(this.sitemap.invoke(invocation).isCompleted());
+
         // invocation should not be marked as error-invocation
         assertFalse(invocation.isErrorInvocation());
 
         invocation = this.buildInvocation("read/javascript-resource-explicit");
         assertTrue(this.sitemap.invoke(invocation).isCompleted());
+
         // invocation should not be marked as error-invocation
         assertFalse(invocation.isErrorInvocation());
     }
@@ -173,6 +140,7 @@
     public void testReadPipelineImplicit() {
         Invocation invocation = this.buildInvocation("read/javascript-resource-implicit.js");
         assertTrue(this.sitemap.invoke(invocation).isCompleted());
+
         // invocation should not be marked as error-invocation
         assertFalse(invocation.isErrorInvocation());
     }
@@ -185,6 +153,7 @@
         invocation.setParameters(parameters);
 
         assertTrue(this.sitemap.invoke(invocation).isCompleted());
+
         // invocation should not be marked as error-invocation
         assertFalse("InvocationImpl is marked as erroneous.", invocation.isErrorInvocation());
         assertTrue(response.hasRedirected());
@@ -200,8 +169,8 @@
                 "META-INF/cocoon/spring/cocoon-sitemap-node.xml",
                 "META-INF/cocoon/spring/cocoon-expression-language.xml",
                 "META-INF/cocoon/spring/cocoon-sample-sitemap-components.xml",
-                "META-INF/cocoon/spring/cocoon-servlet-collector.xml",
-                "META-INF/cocoon/spring/cocoon-servlet-component.xml", "META-INF/cocoon/spring/cocoon-controller.xml" });
+                "META-INF/cocoon/spring/cocoon-servlet-component.xml", "META-INF/cocoon/spring/cocoon-controller.xml",
+                "cocoon-sample-test-collector.xml" });
 
         this.componentProvider = (ComponentProvider) applicationContext
                 .getBean("org.apache.cocoon.sitemap.ComponentProvider");
@@ -209,21 +178,10 @@
         URL sitemapURL = this.getClass().getResource("/COB-INF/sitemap.xmap");
         this.sitemapBuilder = (SitemapBuilder) applicationContext.getBean("org.apache.cocoon.sitemap.SitemapBuilder");
         this.sitemap = this.sitemapBuilder.build(sitemapURL);
-
-        Map<String, String> emptyMap = Collections.emptyMap();
-        CallStackHelper.enterServlet(new MockServletContext(), new MockHttpServletRequest(emptyMap),
-                new MockHttpServletResponse());
-    }
-
-    @Override
-    protected void tearDown() throws Exception {
-        super.tearDown();
-
-        CallStackHelper.leaveServlet();
     }
 
     private Invocation buildInvocation(String request) {
-        InvocationImpl invocation = new InvocationImpl(System.out);
+        InvocationImpl invocation = new InvocationImpl(new NullOutputStream());
 
         invocation.setBaseURL(this.getClass().getResource("/COB-INF/"));
         invocation.setRequestURI(request);

Added: cocoon/cocoon3/trunk/cocoon-sample/src/test/resources/cocoon-sample-test-collector.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sample/src/test/resources/cocoon-sample-test-collector.xml?rev=888393&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sample/src/test/resources/cocoon-sample-test-collector.xml (added)
+++ cocoon/cocoon3/trunk/cocoon-sample/src/test/resources/cocoon-sample-test-collector.xml Tue Dec  8 13:20:36 2009
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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
+  und
+-->
+<!-- $Id$ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:aop="http://www.springframework.org/schema/aop"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+                      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
+
+  <aop:aspectj-autoproxy proxy-target-class="false" />
+ 
+  <bean id="org.apache.cocoon.servlet.collector.ResponseHeaderCollector" class="org.apache.cocoon.servlet.collector.ResponseHeaderCollector" />
+</beans>

Propchange: cocoon/cocoon3/trunk/cocoon-sample/src/test/resources/cocoon-sample-test-collector.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-sample/src/test/resources/cocoon-sample-test-collector.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-sample/src/test/resources/cocoon-sample-test-collector.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/CallStackCollectorDataStore.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/CallStackCollectorDataStore.java?rev=888393&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/CallStackCollectorDataStore.java (added)
+++ cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/CallStackCollectorDataStore.java Tue Dec  8 13:20:36 2009
@@ -0,0 +1,30 @@
+/*
+ * 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.servlet.collector;
+
+import org.apache.cocoon.callstack.CallStack;
+
+public class CallStackCollectorDataStore implements CollectorDataStore {
+
+    public Object get(String key) {
+        return CallStack.getCurrentFrame().getAttribute(key);
+    }
+
+    public void set(String key, Object value) {
+        CallStack.getCurrentFrame().setAttribute(key, value);
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/CallStackCollectorDataStore.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/CallStackCollectorDataStore.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/CallStackCollectorDataStore.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/CollectorDataStore.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/CollectorDataStore.java?rev=888393&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/CollectorDataStore.java (added)
+++ cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/CollectorDataStore.java Tue Dec  8 13:20:36 2009
@@ -0,0 +1,24 @@
+/*
+ * 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.servlet.collector;
+
+public interface CollectorDataStore {
+
+    Object get(String key);
+
+    void set(String key, Object value);
+}

Propchange: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/CollectorDataStore.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/CollectorDataStore.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/CollectorDataStore.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/ResponseHeaderCollector.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/ResponseHeaderCollector.java?rev=888393&r1=888392&r2=888393&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/ResponseHeaderCollector.java (original)
+++ cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/ResponseHeaderCollector.java Tue Dec  8 13:20:36 2009
@@ -18,7 +18,6 @@
 
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.cocoon.callstack.CallStack;
 import org.apache.cocoon.pipeline.Pipeline;
 import org.apache.cocoon.pipeline.component.PipelineComponent;
 import org.apache.cocoon.sitemap.Invocation;
@@ -31,6 +30,8 @@
 @Aspect
 public class ResponseHeaderCollector {
 
+    private static CollectorDataStore collectorDataStore = new ThreadLocalCollectorDataStore();
+
     private static final String KEY_LAST_MODIFIED = ResponseHeaderCollector.class.getName() + "/last-modified";
     private static final String KEY_MIME_TYPE = ResponseHeaderCollector.class.getName() + "/mime-type";
     private static final String KEY_STATUS_CODE = ResponseHeaderCollector.class.getName() + "/status-code";
@@ -73,8 +74,12 @@
         return invocationResult;
     }
 
+    public void setCollectorDataStore(CollectorDataStore collectorDataStore) {
+        ResponseHeaderCollector.collectorDataStore = collectorDataStore;
+    }
+
     public static long getLastModified() {
-        Object lastModified = CallStack.getCurrentFrame().getAttribute(KEY_LAST_MODIFIED);
+        Object lastModified = collectorDataStore.get(KEY_LAST_MODIFIED);
 
         if (lastModified == null) {
             return -1;
@@ -84,11 +89,11 @@
     }
 
     public static String getMimeType() {
-        return (String) CallStack.getCurrentFrame().getAttribute(KEY_MIME_TYPE);
+        return (String) collectorDataStore.get(KEY_MIME_TYPE);
     }
 
     public static int getStatusCode() {
-        Integer statusCode = (Integer) CallStack.getCurrentFrame().getAttribute(KEY_STATUS_CODE);
+        Integer statusCode = (Integer) collectorDataStore.get(KEY_STATUS_CODE);
 
         if (statusCode == null) {
             return HttpServletResponse.SC_OK;
@@ -98,14 +103,14 @@
     }
 
     public static void setLastModified(Long lastModified) {
-        CallStack.getCurrentFrame().setAttribute(KEY_LAST_MODIFIED, lastModified);
+        collectorDataStore.set(KEY_LAST_MODIFIED, lastModified);
     }
 
     public static void setMimeType(String mimeType) {
-        CallStack.getCurrentFrame().setAttribute(KEY_MIME_TYPE, mimeType);
+        collectorDataStore.set(KEY_MIME_TYPE, mimeType);
     }
 
     public static void setStatusCode(int statusCode) {
-        CallStack.getCurrentFrame().setAttribute(KEY_STATUS_CODE, statusCode);
+        collectorDataStore.set(KEY_STATUS_CODE, statusCode);
     }
 }

Added: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/ThreadLocalCollectorDataStore.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/ThreadLocalCollectorDataStore.java?rev=888393&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/ThreadLocalCollectorDataStore.java (added)
+++ cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/ThreadLocalCollectorDataStore.java Tue Dec  8 13:20:36 2009
@@ -0,0 +1,37 @@
+/*
+ * 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.servlet.collector;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ThreadLocalCollectorDataStore implements CollectorDataStore {
+
+    private static ThreadLocal<Map<String, Object>> threadStore = new ThreadLocal<Map<String, Object>>();
+
+    public ThreadLocalCollectorDataStore() {
+        threadStore.set(new HashMap<String, Object>());
+    }
+
+    public Object get(String key) {
+        return threadStore.get().get(key);
+    }
+
+    public void set(String key, Object value) {
+        threadStore.get().put(key, value);
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/ThreadLocalCollectorDataStore.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/ThreadLocalCollectorDataStore.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/collector/ThreadLocalCollectorDataStore.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/cocoon3/trunk/cocoon-servlet/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-collector.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-servlet/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-collector.xml?rev=888393&r1=888392&r2=888393&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-servlet/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-collector.xml (original)
+++ cocoon/cocoon3/trunk/cocoon-servlet/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-collector.xml Tue Dec  8 13:20:36 2009
@@ -26,5 +26,9 @@
 
   <aop:aspectj-autoproxy proxy-target-class="false" />
  
-  <bean id="org.apache.cocoon.servlet.collector.ResponseHeaderCollector" class="org.apache.cocoon.servlet.collector.ResponseHeaderCollector" />
+  <bean id="org.apache.cocoon.servlet.collector.ResponseHeaderCollector" class="org.apache.cocoon.servlet.collector.ResponseHeaderCollector">
+    <property name="collectorDataStore">
+      <bean class="org.apache.cocoon.servlet.collector.CallStackCollectorDataStore" />
+    </property>
+  </bean>
 </beans>