Author: niallp
Date: Thu May 29 08:31:29 2008
New Revision: 661360

URL: http://svn.apache.org/viewvc?rev=661360&view=rev
Log:
Fix CHAIN-44 - CatalogFactory instance varibale prevents ChainProcessor from 
being serializable

Added:
    
commons/proper/chain/trunk/src/test/org/apache/commons/chain/web/servlet/ChainProcessorTestCase.java
   (with props)
Modified:
    commons/proper/chain/trunk/RELEASE-NOTES.txt
    
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ChainProcessor.java
    commons/proper/chain/trunk/xdocs/changes.xml

Modified: commons/proper/chain/trunk/RELEASE-NOTES.txt
URL: 
http://svn.apache.org/viewvc/commons/proper/chain/trunk/RELEASE-NOTES.txt?rev=661360&r1=661359&r2=661360&view=diff
==============================================================================
--- commons/proper/chain/trunk/RELEASE-NOTES.txt (original)
+++ commons/proper/chain/trunk/RELEASE-NOTES.txt Thu May 29 08:31:29 2008
@@ -33,6 +33,7 @@
       
 BUG REPORTS ADDRESSED:
 =====================
+o CHAIN-44: CatalogFactory instance varibale prevents ChainProcessor from 
being serializable.
 o CHAIN-43: ChainListener URL translation does not work as expected. 
 o CHAIN-42: Various scope mappers use incorrect equalization.
 o CHAIN-41: Ant build fails due to usage of old Digester.

Modified: 
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ChainProcessor.java
URL: 
http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ChainProcessor.java?rev=661360&r1=661359&r2=661360&view=diff
==============================================================================
--- 
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ChainProcessor.java
 (original)
+++ 
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ChainProcessor.java
 Thu May 29 08:31:29 2008
@@ -119,12 +119,6 @@
     private String command = null;
 
 
-    /**
-     * <p>The [EMAIL PROTECTED] CatalogFactory} for this application.</p>
-     */
-    private CatalogFactory factory = null;
-
-
     // --------------------------------------------------------- Servlet 
Methods
 
 
@@ -137,7 +131,6 @@
         attribute = null;
         catalog = null;
         command = null;
-        factory = null;
 
     }
 
@@ -156,7 +149,6 @@
         if (command == null) {
             command = COMMAND_DEFAULT;
         }
-        factory = CatalogFactory.getInstance();
 
     }
 
@@ -183,9 +175,9 @@
             theCatalog = (Catalog) getServletContext().getAttribute
                 (this.attribute);
         } else if (catalog != null) {
-            theCatalog = factory.getCatalog(catalog);
+            theCatalog = CatalogFactory.getInstance().getCatalog(catalog);
         } else {
-            theCatalog = factory.getCatalog();
+            theCatalog = CatalogFactory.getInstance().getCatalog();
         }
         if (attribute == null) {
             request.setAttribute(CATALOG_DEFAULT, theCatalog);

Added: 
commons/proper/chain/trunk/src/test/org/apache/commons/chain/web/servlet/ChainProcessorTestCase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/test/org/apache/commons/chain/web/servlet/ChainProcessorTestCase.java?rev=661360&view=auto
==============================================================================
--- 
commons/proper/chain/trunk/src/test/org/apache/commons/chain/web/servlet/ChainProcessorTestCase.java
 (added)
+++ 
commons/proper/chain/trunk/src/test/org/apache/commons/chain/web/servlet/ChainProcessorTestCase.java
 Thu May 29 08:31:29 2008
@@ -0,0 +1,127 @@
+/*
+ * 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.commons.chain.web.servlet;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import javax.servlet.ServletConfig;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ *  Test case for [EMAIL PROTECTED] ChainProcessor}.
+ */
+public class ChainProcessorTestCase extends TestCase {
+
+    // ---------------------------------------------------------- Constructors
+
+    /**
+     * Construct a new instance of this test case.
+     *
+     * @param name Name of the test case
+     */
+    public ChainProcessorTestCase(String name) {
+        super(name);
+    }
+
+    /**
+     * Return the tests included in this test suite.
+     * @return the test suite
+     */
+    public static Test suite() {
+        return new TestSuite(ChainProcessorTestCase.class);
+    }
+
+
+    /**
+     * Set up instance variables required by this test case.
+     */
+    public void setUp() {
+    }
+
+    /**
+     * Tear down instance variables required by this test case.
+     */
+    public void tearDown() {
+    }
+
+    /**
+     * Test serialization.
+     */
+    public void testSerialize() {
+
+        // Initialize a ChainProcessor
+        ChainProcessor processor = initServlet(new ChainProcessor(), new 
MockServletConfig("test"));
+
+        // Serialize/Deserialize & test value
+        processor = (ChainProcessor)serializeDeserialize(processor, "First 
Test");
+    }
+
+    /**
+     * Initialize the ChainProcessor.
+     *
+     * @param processor The chain processor instance
+     * @param config The servlet config to initialize with
+     * @return The chain processor
+     */
+    private ChainProcessor initServlet(ChainProcessor processor, ServletConfig 
config) {
+        try {
+            processor.init(config);
+        } catch (Throwable t) {
+            t.printStackTrace();
+            fail("ChainProcessor init() threw " + t);
+        }
+        return processor;
+    }
+
+    /**
+     * Do serialization and deserialization.
+     */
+    private Object serializeDeserialize(Object target, String text) {
+
+        // Serialize the test object
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        try {
+            ObjectOutputStream oos = new ObjectOutputStream(baos);
+            oos.writeObject(target);
+            oos.flush();
+            oos.close();
+        } catch (Exception e) {
+            fail(text + ": Exception during serialization: " + e);
+        }
+
+        // Deserialize the test object
+        Object result = null;
+        try {
+            ByteArrayInputStream bais =
+                new ByteArrayInputStream(baos.toByteArray());
+            ObjectInputStream ois = new ObjectInputStream(bais);
+            result = ois.readObject();
+            bais.close();
+        } catch (Exception e) {
+            fail(text + ": Exception during deserialization: " + e);
+        }
+        return result;
+
+    }
+}

Propchange: 
commons/proper/chain/trunk/src/test/org/apache/commons/chain/web/servlet/ChainProcessorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
commons/proper/chain/trunk/src/test/org/apache/commons/chain/web/servlet/ChainProcessorTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: commons/proper/chain/trunk/xdocs/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/chain/trunk/xdocs/changes.xml?rev=661360&r1=661359&r2=661360&view=diff
==============================================================================
--- commons/proper/chain/trunk/xdocs/changes.xml (original)
+++ commons/proper/chain/trunk/xdocs/changes.xml Thu May 29 08:31:29 2008
@@ -55,6 +55,9 @@
       <action dev="niallp" type="update" issue="CHAIN-4" due-to="Joe Germuska">
          Update servlet implementation classes to be aware of CatalogFactory
       </action>
+      <action dev="niallp" type="fix" issue="CHAIN-44" due-to="FindBugs">
+         CatalogFactory instance varibale prevents ChainProcessor from being 
serializable.
+      </action>
       <action dev="niallp" type="fix" issue="CHAIN-43" due-to="Ales Dolecek">
          ChainListener URL translation does not work as expected.
       </action>


Reply via email to