You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by tv...@apache.org on 2016/01/16 17:31:46 UTC
svn commit: r1725002 - in /turbine/core/trunk: ./ conf/ src/changes/
src/java/org/apache/turbine/ src/java/org/apache/turbine/pipeline/
src/test/org/apache/turbine/pipeline/
Author: tv
Date: Sat Jan 16 16:31:45 2016
New Revision: 1725002
URL: http://svn.apache.org/viewvc?rev=1725002&view=rev
Log:
Replace xstream with JAXB when reading the pipeline descriptor.
Added:
turbine/core/trunk/src/java/org/apache/turbine/pipeline/XmlValve.java (with props)
turbine/core/trunk/src/java/org/apache/turbine/pipeline/XmlValveAdapter.java (with props)
Modified:
turbine/core/trunk/conf/turbine-classic-pipeline.xml
turbine/core/trunk/pom.xml
turbine/core/trunk/src/changes/changes.xml
turbine/core/trunk/src/java/org/apache/turbine/Turbine.java
turbine/core/trunk/src/java/org/apache/turbine/pipeline/TurbinePipeline.java
turbine/core/trunk/src/test/org/apache/turbine/pipeline/PipelineCreationTest.java
Modified: turbine/core/trunk/conf/turbine-classic-pipeline.xml
URL: http://svn.apache.org/viewvc/turbine/core/trunk/conf/turbine-classic-pipeline.xml?rev=1725002&r1=1725001&r2=1725002&view=diff
==============================================================================
--- turbine/core/trunk/conf/turbine-classic-pipeline.xml (original)
+++ turbine/core/trunk/conf/turbine-classic-pipeline.xml Sat Jan 16 16:31:45 2016
@@ -17,16 +17,16 @@
specific language governing permissions and limitations
under the License.
-->
-<org.apache.turbine.pipeline.TurbinePipeline>
+<pipeline name="default">
<valves>
- <org.apache.turbine.pipeline.DetermineActionValve/>
- <org.apache.turbine.pipeline.DetermineTargetValve/>
- <org.apache.turbine.pipeline.DefaultSessionTimeoutValve/>
- <org.apache.turbine.pipeline.DefaultLoginValve/>
- <org.apache.turbine.pipeline.DefaultSessionValidationValve/>
- <org.apache.turbine.pipeline.DefaultACLCreationValve/>
- <org.apache.turbine.pipeline.ExecutePageValve/>
- <org.apache.turbine.pipeline.CleanUpValve/>
- <org.apache.turbine.pipeline.DetermineRedirectRequestedValve/>
+ <valve>org.apache.turbine.pipeline.DetermineActionValve</valve>
+ <valve>org.apache.turbine.pipeline.DetermineTargetValve</valve>
+ <valve>org.apache.turbine.pipeline.DefaultSessionTimeoutValve</valve>
+ <valve>org.apache.turbine.pipeline.DefaultLoginValve</valve>
+ <valve>org.apache.turbine.pipeline.DefaultSessionValidationValve</valve>
+ <valve>org.apache.turbine.pipeline.DefaultACLCreationValve</valve>
+ <valve>org.apache.turbine.pipeline.ExecutePageValve</valve>
+ <valve>org.apache.turbine.pipeline.CleanUpValve</valve>
+ <valve>org.apache.turbine.pipeline.DetermineRedirectRequestedValve</valve>
</valves>
-</org.apache.turbine.pipeline.TurbinePipeline>
+</pipeline>
Modified: turbine/core/trunk/pom.xml
URL: http://svn.apache.org/viewvc/turbine/core/trunk/pom.xml?rev=1725002&r1=1725001&r2=1725002&view=diff
==============================================================================
--- turbine/core/trunk/pom.xml (original)
+++ turbine/core/trunk/pom.xml Sat Jan 16 16:31:45 2016
@@ -1028,11 +1028,6 @@
<type>jar</type>
</dependency>
<dependency>
- <groupId>com.thoughtworks.xstream</groupId>
- <artifactId>xstream</artifactId>
- <version>1.4.4</version>
- </dependency>
- <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
@@ -1113,7 +1108,7 @@
<properties>
<!-- TODO: Change for release -->
- <turbine.site.path>turbine/turbine-4.0-M2</turbine.site.path>
+ <turbine.site.path>turbine/development/turbine-4.0</turbine.site.path>
</properties>
</project>
Modified: turbine/core/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/changes/changes.xml?rev=1725002&r1=1725001&r2=1725002&view=diff
==============================================================================
--- turbine/core/trunk/src/changes/changes.xml (original)
+++ turbine/core/trunk/src/changes/changes.xml Sat Jan 16 16:31:45 2016
@@ -25,6 +25,9 @@
<body>
<release version="4.0" date="in Subversion">
+ <action type="update" dev="tv">
+ Replace xstream with JAXB when reading the pipeline descriptor.
+ </action>
<action type="add" dev="tv">
Add annotation support for configuration values
</action>
Modified: turbine/core/trunk/src/java/org/apache/turbine/Turbine.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/Turbine.java?rev=1725002&r1=1725001&r2=1725002&view=diff
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/Turbine.java (original)
+++ turbine/core/trunk/src/java/org/apache/turbine/Turbine.java Sat Jan 16 16:31:45 2016
@@ -38,11 +38,14 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
import javax.xml.parsers.FactoryConfigurationError;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.DefaultConfigurationBuilder;
import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.commons.logging.Log;
@@ -65,9 +68,6 @@ import org.apache.turbine.util.TurbineCo
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.util.uri.URIConstants;
-import com.thoughtworks.xstream.XStream;
-import com.thoughtworks.xstream.io.xml.StaxDriver;
-
/**
* Turbine is the main servlet for the entire system. It is <code>final</code>
* because you should <i>not</i> ever need to subclass this servlet. If you
@@ -380,7 +380,6 @@ public class Turbine
// Retrieve the pipeline class and then initialize it. The pipeline
// handles the processing of a webrequest/response cycle.
-
String descriptorPath =
configuration.getString(
"pipeline.default.descriptor",
@@ -390,8 +389,10 @@ public class Turbine
log.debug("Using descriptor path: " + descriptorPath);
Reader reader = new BufferedReader(new FileReader(descriptorPath));
- XStream pipelineMapper = new XStream(new StaxDriver()); // does not require XPP3 library
- pipeline = (Pipeline) pipelineMapper.fromXML(reader);
+ JAXBContext jaxb = JAXBContext.newInstance(TurbinePipeline.class);
+ Unmarshaller unmarshaller = jaxb.createUnmarshaller();
+ pipeline = (Pipeline) unmarshaller.unmarshal(reader);
+ IOUtils.closeQuietly(reader);
log.debug("Initializing pipeline");
Modified: turbine/core/trunk/src/java/org/apache/turbine/pipeline/TurbinePipeline.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/pipeline/TurbinePipeline.java?rev=1725002&r1=1725001&r2=1725002&view=diff
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/pipeline/TurbinePipeline.java (original)
+++ turbine/core/trunk/src/java/org/apache/turbine/pipeline/TurbinePipeline.java Sat Jan 16 16:31:45 2016
@@ -1,6 +1,5 @@
package org.apache.turbine.pipeline;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -20,11 +19,18 @@ package org.apache.turbine.pipeline;
* under the License.
*/
-
import java.io.IOException;
import java.util.Iterator;
import java.util.concurrent.CopyOnWriteArrayList;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
import org.apache.turbine.annotation.AnnotationProcessor;
import org.apache.turbine.util.TurbineException;
@@ -36,48 +42,40 @@ import org.apache.turbine.util.TurbineEx
* @author <a href="mailto:jvanzyl@zenplex.com">Jason van Zyl</a>
* @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
*/
+@XmlRootElement(name="pipeline")
+@XmlAccessorType(XmlAccessType.NONE)
public class TurbinePipeline
- implements Pipeline, ValveContext
+ implements Pipeline, ValveContext
{
/**
* The "Turbine Classic" pipeline.
*/
public static final String CLASSIC_PIPELINE =
- "WEB-INF/conf/turbine-classic-pipeline.xml";
+ "WEB-INF/conf/turbine-classic-pipeline.xml";
/**
* Name of this pipeline.
*/
+ @XmlAttribute
private String name;
/**
* The set of Valves associated with this Pipeline.
*/
- private transient CopyOnWriteArrayList<Valve> valves = new CopyOnWriteArrayList<Valve>();
+ private CopyOnWriteArrayList<Valve> valves = new CopyOnWriteArrayList<Valve>();
/**
- * The per-thread execution state for processing through this
- * pipeline.
+ * The per-thread execution state for processing through this pipeline.
*/
- private transient ThreadLocal<Iterator<Valve>> state = new ThreadLocal<Iterator<Valve>>();
+ private ThreadLocal<Iterator<Valve>> state = new ThreadLocal<Iterator<Valve>>();
/**
* @see org.apache.turbine.pipeline.Pipeline#initialize()
*/
@Override
public void initialize()
- throws Exception
+ throws Exception
{
- if (state == null)
- {
- state = new ThreadLocal<Iterator<Valve>>();
- }
-
- if (valves == null)
- {
- valves = new CopyOnWriteArrayList<Valve>();
- }
-
// Valve implementations are added to this Pipeline using the
// Mapper.
@@ -92,7 +90,8 @@ public class TurbinePipeline
/**
* Set the name of this pipeline.
*
- * @param name Name of this pipeline.
+ * @param name
+ * Name of this pipeline.
*/
public void setName(String name)
{
@@ -123,12 +122,25 @@ public class TurbinePipeline
* @see org.apache.turbine.pipeline.Pipeline#getValves()
*/
@Override
+ @XmlElementWrapper(name="valves")
+ @XmlElement(name="valve")
+ @XmlJavaTypeAdapter(XmlValveAdapter.class)
public Valve[] getValves()
{
return valves.toArray(new Valve[0]);
}
/**
+ * Set new valves during deserialization
+ *
+ * @param valves the valves to set
+ */
+ protected void setValves(Valve[] valves)
+ {
+ this.valves = new CopyOnWriteArrayList<Valve>(valves);
+ }
+
+ /**
* @see org.apache.turbine.pipeline.Pipeline#removeValve(Valve)
*/
@Override
@@ -142,7 +154,7 @@ public class TurbinePipeline
*/
@Override
public void invoke(PipelineData pipelineData)
- throws TurbineException, IOException
+ throws TurbineException, IOException
{
// Initialize the per-thread state for this thread
state.set(valves.iterator());
@@ -156,7 +168,7 @@ public class TurbinePipeline
*/
@Override
public void invokeNext(PipelineData pipelineData)
- throws TurbineException, IOException
+ throws TurbineException, IOException
{
// Identify the current valve for the current request thread
Iterator<Valve> current = state.get();
Added: turbine/core/trunk/src/java/org/apache/turbine/pipeline/XmlValve.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/pipeline/XmlValve.java?rev=1725002&view=auto
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/pipeline/XmlValve.java (added)
+++ turbine/core/trunk/src/java/org/apache/turbine/pipeline/XmlValve.java Sat Jan 16 16:31:45 2016
@@ -0,0 +1,58 @@
+package org.apache.turbine.pipeline;
+
+/*
+ * 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.
+ */
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlValue;
+
+/**
+ * A JAXB Class for holding the class name of a valve.
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ */
+@XmlType(name="valve")
+@XmlAccessorType(XmlAccessType.NONE)
+public class XmlValve
+{
+ @XmlValue
+ private String clazz;
+
+ /**
+ * Get the class attribute
+ *
+ * @return the class name implementing this valve
+ */
+ public String getClazz()
+ {
+ return clazz;
+ }
+
+ /**
+ * Set the class attribute
+ *
+ * @param clazz the class name to set
+ */
+ public void setClazz(String clazz)
+ {
+ this.clazz = clazz;
+ }
+}
\ No newline at end of file
Propchange: turbine/core/trunk/src/java/org/apache/turbine/pipeline/XmlValve.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: turbine/core/trunk/src/java/org/apache/turbine/pipeline/XmlValveAdapter.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/pipeline/XmlValveAdapter.java?rev=1725002&view=auto
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/pipeline/XmlValveAdapter.java (added)
+++ turbine/core/trunk/src/java/org/apache/turbine/pipeline/XmlValveAdapter.java Sat Jan 16 16:31:45 2016
@@ -0,0 +1,52 @@
+package org.apache.turbine.pipeline;
+
+/*
+ * 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.
+ */
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+/**
+ * Creates Valve objects.
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ */
+public class XmlValveAdapter extends XmlAdapter<XmlValve, Valve>
+{
+ /**
+ * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
+ */
+ @Override
+ public Valve unmarshal(XmlValve xmlValve) throws Exception
+ {
+ Class<?> valveClass = Class.forName(xmlValve.getClazz());
+ return (Valve) valveClass.newInstance();
+ }
+
+ /**
+ * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
+ */
+ @Override
+ public XmlValve marshal(Valve valve) throws Exception
+ {
+ XmlValve xmlValve = new XmlValve();
+ xmlValve.setClazz(valve.getClass().getName());
+
+ return xmlValve;
+ }
+}
Propchange: turbine/core/trunk/src/java/org/apache/turbine/pipeline/XmlValveAdapter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: turbine/core/trunk/src/test/org/apache/turbine/pipeline/PipelineCreationTest.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/test/org/apache/turbine/pipeline/PipelineCreationTest.java?rev=1725002&r1=1725001&r2=1725002&view=diff
==============================================================================
--- turbine/core/trunk/src/test/org/apache/turbine/pipeline/PipelineCreationTest.java (original)
+++ turbine/core/trunk/src/test/org/apache/turbine/pipeline/PipelineCreationTest.java Sat Jan 16 16:31:45 2016
@@ -1,6 +1,5 @@
package org.apache.turbine.pipeline;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -20,15 +19,18 @@ package org.apache.turbine.pipeline;
* under the License.
*/
-
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import org.junit.Test;
+import java.io.StringReader;
+import java.io.StringWriter;
-import com.thoughtworks.xstream.XStream;
-import com.thoughtworks.xstream.io.xml.DomDriver;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests TurbinePipeline.
@@ -40,27 +42,40 @@ public class PipelineCreationTest
{
private Pipeline pipeline;
- public void setUp(){
+ @Before
+ public void setUp()
+ {
pipeline = new TurbinePipeline();
pipeline.addValve(new SimpleValve());
pipeline.addValve(new DetermineActionValve());
}
- @Test public void testSavingPipelineWXstream() throws Exception
+ @Test
+ public void testSavingPipeline() throws Exception
{
- XStream xstream = new XStream(new DomDriver()); // does not require XPP3 library
-
- /* String xml = */ xstream.toXML(pipeline);
- //System.out.println(xml);
- //Pipeline pipeline = (Pipeline)xstream.fromXML(xml);
+ JAXBContext context = JAXBContext.newInstance(TurbinePipeline.class);
+ Marshaller marshaller = context.createMarshaller();
+ StringWriter writer = new StringWriter();
+ marshaller.marshal(pipeline, writer);
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
+ + "<pipeline><valves>"
+ + "<valve>org.apache.turbine.pipeline.SimpleValve</valve>"
+ + "<valve>org.apache.turbine.pipeline.DetermineActionValve</valve>"
+ + "</valves></pipeline>", writer.toString());
}
- @Test public void testReadingPipelineWXstream() throws Exception{
- String xml="<org.apache.turbine.pipeline.TurbinePipeline> <valves> <org.apache.turbine.pipeline.SimpleValve/> <org.apache.turbine.pipeline.DetermineActionValve/> </valves></org.apache.turbine.pipeline.TurbinePipeline>";
- XStream xstream = new XStream(new DomDriver()); // does not require XPP3 library
- Object o = xstream.fromXML(xml);
- Pipeline pipeline = (Pipeline)o;
- assertEquals(pipeline.getValves().length,2);
+ @Test
+ public void testReadingPipeline() throws Exception
+ {
+ String xml = "<pipeline name=\"default\"><valves>"
+ + "<valve>org.apache.turbine.pipeline.SimpleValve</valve>"
+ + "<valve>org.apache.turbine.pipeline.DetermineActionValve</valve>"
+ + "</valves></pipeline>";
+ JAXBContext context = JAXBContext.newInstance(TurbinePipeline.class);
+ Unmarshaller unmarshaller = context.createUnmarshaller();
+ StringReader reader = new StringReader(xml);
+ Pipeline pipeline = (Pipeline) unmarshaller.unmarshal(reader);
+ assertEquals(2, pipeline.getValves().length);
assertTrue(pipeline.getValves()[0] instanceof SimpleValve);
assertTrue(pipeline.getValves()[1] instanceof DetermineActionValve);
}