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 2008/04/01 19:39:17 UTC

svn commit: r643483 - in /cocoon/whiteboard/corona/trunk: corona-core/src/main/resources/ corona-core/src/test/java/org/apache/cocoon/corona/pipeline/ corona-servlet/ corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ corona-servlet/src/mai...

Author: reinhard
Date: Tue Apr  1 10:39:08 2008
New Revision: 643483

URL: http://svn.apache.org/viewvc?rev=643483&view=rev
Log:
move setting of status code to the 'servlet layer' [doing pair programming with Steven Dolg]

Added:
    cocoon/whiteboard/corona/trunk/corona-core/src/main/resources/test.xml   (with props)
    cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/node/
    cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/node/StatusCodeCollector.java   (with props)
    cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-node.xml   (with props)
Modified:
    cocoon/whiteboard/corona/trunk/corona-core/src/test/java/org/apache/cocoon/corona/pipeline/PipelineTest.java
    cocoon/whiteboard/corona/trunk/corona-servlet/pom.xml
    cocoon/whiteboard/corona/trunk/corona-servlet/rcl.properties
    cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapServlet.java
    cocoon/whiteboard/corona/trunk/corona-servlet/src/test/java/org/apache/cocoon/corona/sitemap/SitemapBuilderTest.java
    cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/InvocationImpl.java
    cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/resources/META-INF/cocoon/spring/applicationContext.xml
    cocoon/whiteboard/corona/trunk/parent/pom.xml

Added: cocoon/whiteboard/corona/trunk/corona-core/src/main/resources/test.xml
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-core/src/main/resources/test.xml?rev=643483&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-core/src/main/resources/test.xml (added)
+++ cocoon/whiteboard/corona/trunk/corona-core/src/main/resources/test.xml Tue Apr  1 10:39:08 2008
@@ -0,0 +1 @@
+<test/>
\ No newline at end of file

Propchange: cocoon/whiteboard/corona/trunk/corona-core/src/main/resources/test.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-core/src/main/resources/test.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-core/src/main/resources/test.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: cocoon/whiteboard/corona/trunk/corona-core/src/test/java/org/apache/cocoon/corona/pipeline/PipelineTest.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-core/src/test/java/org/apache/cocoon/corona/pipeline/PipelineTest.java?rev=643483&r1=643482&r2=643483&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-core/src/test/java/org/apache/cocoon/corona/pipeline/PipelineTest.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-core/src/test/java/org/apache/cocoon/corona/pipeline/PipelineTest.java Tue Apr  1 10:39:08 2008
@@ -36,7 +36,7 @@
 
         FileReaderComponent fileReaderComponent = new FileReaderComponent();
         Map<String, Object> parameters = new HashMap<String, Object>();
-        parameters.put("src", "/META-INF/cocoon/spring/applicationContext.xml");
+        parameters.put("src", "/test.xml");
         fileReaderComponent.setParameters(parameters);
         pipeline.addComponent(fileReaderComponent);
 

Modified: cocoon/whiteboard/corona/trunk/corona-servlet/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/pom.xml?rev=643483&r1=643482&r2=643483&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-servlet/pom.xml (original)
+++ cocoon/whiteboard/corona/trunk/corona-servlet/pom.xml Tue Apr  1 10:39:08 2008
@@ -57,6 +57,18 @@
       <artifactId>cocoon-spring-configurator</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-aop</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.aspectj</groupId>
+      <artifactId>aspectjrt</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.aspectj</groupId>
+      <artifactId>aspectjweaver</artifactId>
+    </dependency>
+    <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>servlet-api</artifactId>
       <scope>provided</scope>

Modified: cocoon/whiteboard/corona/trunk/corona-servlet/rcl.properties
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/rcl.properties?rev=643483&r1=643482&r2=643483&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-servlet/rcl.properties (original)
+++ cocoon/whiteboard/corona/trunk/corona-servlet/rcl.properties Tue Apr  1 10:39:08 2008
@@ -17,5 +17,5 @@
 org.apache.cocoon.corona.demo.servlet%classes-dir=./target/classes
 
 # Cocoon Corona Core
-%classes-dir=../corona-core/target/classes
-%exclude-lib=org.apache.cocoon:corona-core
\ No newline at end of file
+#%classes-dir=../corona-core/target/classes
+#%exclude-lib=org.apache.cocoon:corona-core
\ No newline at end of file

Modified: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapServlet.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapServlet.java?rev=643483&r1=643482&r2=643483&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapServlet.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/SitemapServlet.java Tue Apr  1 10:39:08 2008
@@ -31,6 +31,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.cocoon.corona.servlet.node.StatusCodeCollector;
 import org.apache.cocoon.corona.servlet.util.HttpContextHelper;
 import org.apache.cocoon.corona.sitemap.Invocation;
 import org.apache.cocoon.corona.sitemap.InvocationImpl;
@@ -48,6 +49,8 @@
 
     private BeanFactory beanFactory;
 
+    private StatusCodeCollector statusCodeCollector;
+
     @Override
     public void init(ServletConfig servletConfig) throws ServletException {
         super.init(servletConfig);
@@ -56,13 +59,14 @@
             SitemapBuilder sitemapBuilder = (SitemapBuilder) this.beanFactory.getBean(SitemapBuilder.class.getName());
             URL url = servletConfig.getServletContext().getResource("/sitemap.xmap");
             this.sitemap = sitemapBuilder.build(url);
+            this.statusCodeCollector = (StatusCodeCollector) beanFactory.getBean(StatusCodeCollector.class.getName());
         } catch (Exception e) {
             throw new ServletException(e);
         }
     }
 
     @Override
-    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         try {
             InvocationImpl invocation = (InvocationImpl) this.beanFactory.getBean(Invocation.class.getName());
             // parameters
@@ -76,6 +80,8 @@
             invocation.setOutputStream(response.getOutputStream());
 
             this.sitemap.invoke(invocation);
+
+            response.setStatus(this.statusCodeCollector.getStatusCode());
         } catch (Exception e) {
             PrintWriter writer = new PrintWriter(response.getOutputStream());
             e.printStackTrace(writer);

Added: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/node/StatusCodeCollector.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/node/StatusCodeCollector.java?rev=643483&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/node/StatusCodeCollector.java (added)
+++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/node/StatusCodeCollector.java Tue Apr  1 10:39:08 2008
@@ -0,0 +1,57 @@
+/*
+ * 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.corona.servlet.node;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.cocoon.corona.sitemap.node.InvocationResult;
+import org.apache.cocoon.corona.sitemap.node.SerializeNode;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+
+@Aspect
+public class StatusCodeCollector {
+
+    private static ThreadLocal<Integer> threadLocal = new ThreadLocal<Integer>();
+
+    @Around("execution(org.apache.cocoon.corona.sitemap.node.InvocationResult org.apache.cocoon.corona.sitemap.node.SerializeNode.invoke(org.apache.cocoon.corona.sitemap.Invocation))")
+    public Object interceptInvoke(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
+        SerializeNode target = (SerializeNode) proceedingJoinPoint.getTarget();
+        String statusCode = target.getParameters().get("status-code");
+
+        InvocationResult invocationResult = (InvocationResult) proceedingJoinPoint.proceed();
+
+        if (invocationResult.isProcessed() && statusCode != null) {
+            threadLocal.set(Integer.valueOf(statusCode));
+        }
+
+        return invocationResult;
+    }
+
+    public int getStatusCode() {
+        Integer integer = threadLocal.get();
+
+        if (integer == null) {
+            return HttpServletResponse.SC_OK;
+        }
+
+        return integer.intValue();
+    }
+}

Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/node/StatusCodeCollector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/node/StatusCodeCollector.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/node/StatusCodeCollector.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-node.xml
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-node.xml?rev=643483&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-node.xml (added)
+++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-node.xml Tue Apr  1 10:39:08 2008
@@ -0,0 +1,31 @@
+<?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.corona.servlet.node.StatusCodeCollector" class="org.apache.cocoon.corona.servlet.node.StatusCodeCollector" />
+
+</beans>

Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-node.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-node.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-node.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: cocoon/whiteboard/corona/trunk/corona-servlet/src/test/java/org/apache/cocoon/corona/sitemap/SitemapBuilderTest.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/test/java/org/apache/cocoon/corona/sitemap/SitemapBuilderTest.java?rev=643483&r1=643482&r2=643483&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-servlet/src/test/java/org/apache/cocoon/corona/sitemap/SitemapBuilderTest.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-servlet/src/test/java/org/apache/cocoon/corona/sitemap/SitemapBuilderTest.java Tue Apr  1 10:39:08 2008
@@ -27,6 +27,7 @@
 import junit.framework.TestCase;
 
 import org.apache.cocoon.corona.pipeline.action.CustomException;
+import org.apache.cocoon.corona.servlet.node.StatusCodeCollector;
 import org.apache.cocoon.corona.servlet.util.HttpContextHelper;
 import org.apache.cocoon.corona.sitemap.node.InvocationResult;
 import org.apache.cocoon.corona.sitemap.node.Sitemap;
@@ -41,6 +42,8 @@
 
     private ComponentProvider componentProvider;
 
+    private StatusCodeCollector statusCodeCollector;
+
     public void testErrorHandlingGlobal() {
         // TODO: currently this cannot work since some components for error
         // handling are still missing
@@ -69,7 +72,7 @@
         assertTrue("Expected CustomException but received " + invocation.getThrowable(),
                 invocation.getThrowable() instanceof CustomException);
 
-        assertEquals(501, mockHttpServletResponse.getStatusCode());
+        assertEquals(501, this.statusCodeCollector.getStatusCode());
     }
 
     public void testGenerator() {
@@ -83,7 +86,7 @@
 
         // invocation should not be marked as error-invocation
         assertFalse(invocation.isErrorInvocation());
-        assertEquals(401, mockHttpServletResponse.getStatusCode());
+        assertEquals(401, this.statusCodeCollector.getStatusCode());
     }
 
     public void testNoMatchingPipeline() {
@@ -174,7 +177,10 @@
                 "META-INF/cocoon/spring/applicationContext.xml", "META-INF/cocoon/spring/corona-pipeline-action.xml",
                 "META-INF/cocoon/spring/corona-pipeline-component.xml", "META-INF/cocoon/spring/corona-pipeline.xml",
                 "META-INF/cocoon/spring/corona-sitemap-node.xml",
-                "META-INF/cocoon/spring/corona-expression-language.xml" });
+                "META-INF/cocoon/spring/corona-expression-language.xml",
+                "META-INF/cocoon/spring/corona-servlet-node.xml"});
+
+        this.statusCodeCollector = (StatusCodeCollector) applicationContext.getBean(StatusCodeCollector.class.getName());
 
         this.componentProvider = (ComponentProvider) applicationContext
                 .getBean("org.apache.cocoon.corona.sitemap.ComponentProvider");

Modified: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/InvocationImpl.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/InvocationImpl.java?rev=643483&r1=643482&r2=643483&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/InvocationImpl.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/InvocationImpl.java Tue Apr  1 10:39:08 2008
@@ -48,6 +48,9 @@
 
     private Throwable throwable;
 
+    public InvocationImpl() {
+    }
+
     /**
      * Create a {@link InvocationImpl} object using the given output stream.
      *

Modified: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/resources/META-INF/cocoon/spring/applicationContext.xml
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/resources/META-INF/cocoon/spring/applicationContext.xml?rev=643483&r1=643482&r2=643483&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/resources/META-INF/cocoon/spring/applicationContext.xml (original)
+++ cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/resources/META-INF/cocoon/spring/applicationContext.xml Tue Apr  1 10:39:08 2008
@@ -21,14 +21,11 @@
 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
 
-  <bean name="org.apache.cocoon.corona.pipeline.resource.ResourceResolver" class="org.apache.cocoon.corona.pipeline.resource.ClassPathResourceResolver" />
-
   <bean name="org.apache.cocoon.corona.sitemap.ComponentProvider" class="org.apache.cocoon.corona.sitemap.SpringComponentProvider">
     <property name="actionFactory" ref="org.apache.cocoon.corona.sitemap.spring.ActionFactory" />
     <property name="languageInterpreterFactory" ref="org.apache.cocoon.corona.sitemap.expression.LanguageInterpreterFactory" />
     <property name="pipelineComponentFactory" ref="org.apache.cocoon.corona.sitemap.spring.PipelineComponentFactory" />
     <property name="pipelineFactory" ref="org.apache.cocoon.corona.sitemap.spring.PipelineFactory" />
-    <property name="resourceResolver" ref="org.apache.cocoon.corona.pipeline.resource.ResourceResolver" />
   </bean>
 
   <bean name="org.apache.cocoon.corona.sitemap.Invocation" class="org.apache.cocoon.corona.sitemap.InvocationImpl" scope="prototype">

Modified: cocoon/whiteboard/corona/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/parent/pom.xml?rev=643483&r1=643482&r2=643483&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/parent/pom.xml (original)
+++ cocoon/whiteboard/corona/trunk/parent/pom.xml Tue Apr  1 10:39:08 2008
@@ -88,6 +88,17 @@
         <version>2.5.1</version>
       </dependency>
 
+      <dependency>
+        <groupId>org.aspectj</groupId>
+        <artifactId>aspectjrt</artifactId>
+        <version>1.5.4</version>
+      </dependency>
+      <dependency>
+        <groupId>org.aspectj</groupId>
+        <artifactId>aspectjweaver</artifactId>
+        <version>1.5.4</version>
+      </dependency>
+
       <!-- Corona internal dependencies -->
       <dependency>
         <groupId>org.apache.cocoon</groupId>