[jboss-svn-commits] JBL Code SVN: r19766 - in labs/jbossesb/branches/JBESB_4_2_1_GA_FP1/product/services/smooks/src: test/java/org/jboss/soa/esb/actions/smooks and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Apr 29 12:24:13 EDT 2008
Author: tfennelly
Date: 2008-04-29 12:24:13 -0400 (Tue, 29 Apr 2008)
New Revision: 19766
Modified:
labs/jbossesb/branches/JBESB_4_2_1_GA_FP1/product/services/smooks/src/main/java/org/jboss/soa/esb/actions/smooks/SmooksAction.java
labs/jbossesb/branches/JBESB_4_2_1_GA_FP1/product/services/smooks/src/test/java/org/jboss/soa/esb/actions/smooks/SmooksActionUnitTest.java
Log:
http://jira.jboss.com/jira/browse/JBESB-1680
Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_FP1/product/services/smooks/src/main/java/org/jboss/soa/esb/actions/smooks/SmooksAction.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_FP1/product/services/smooks/src/main/java/org/jboss/soa/esb/actions/smooks/SmooksAction.java 2008-04-29 15:27:15 UTC (rev 19765)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_FP1/product/services/smooks/src/main/java/org/jboss/soa/esb/actions/smooks/SmooksAction.java 2008-04-29 16:24:13 UTC (rev 19766)
@@ -19,11 +19,6 @@
*/
package org.jboss.soa.esb.actions.smooks;
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.actions.AbstractActionPipelineProcessor;
import org.jboss.soa.esb.actions.ActionLifecycleException;
@@ -37,6 +32,12 @@
import org.milyn.container.plugin.PayloadProcessor;
import org.milyn.container.plugin.ResultType;
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
/**
* Smooks pipeline processor action.
* <p/>
@@ -50,6 +51,7 @@
* <property name="get-payload-location" value="input" />
* <property name="set-payload-location" value="ouput" />
* <property name="excludeNonSerializables" value="false" />
+ * <property name="resultType" value="STRING" />
* </pre>
*
* Description of configuration properties:
@@ -58,15 +60,28 @@
* <li><i>get-payload-location</i> - the body location which contains the object to be transformed.
* <li><i>set-payload-location</i> - the body location where the transformed object will be placed.
* <li><i>excludeNonSerializables</i> - if true, non serializable attributes from the Smooks ExecutionContext will no be included. Default is true.
+ * <li><i>resultType</i> - type of result expected from Smooks ("STRING", "BYTES", "JAVA", "NORESULT"). Default is "STRING".
* </ul>
* After Smooks has performed the filtering the process method will make the attributes that have been set in the
- * the ExecutionContext available for other actions in the ESB. <br>
- * These attributes (Map) can be accessed by using the {@link #EXECUTION_CONTEXT_ATTR_MAP_KEY} key like this:
+ * the ExecutionContext available for other actions in the ESB.
+ * <p/>
+ * The attributes (Map) can be accessed by using the {@link #EXECUTION_CONTEXT_ATTR_MAP_KEY} key like this:
* <pre>
* message.getBody().get( EXECUTION_CONTEXT_ATTR_MAP_KEY );
* </pre>
+ *
+ * <h3>Specifying the Source and Result Types</h3>
+ * From the ESB Message data type, this action is able to automatically determine the type of
+ * {@link javax.xml.transform.Source} to use (via the Smooks {@link PayloadProcessor}). The
+ * {@link javax.xml.transform.Result} type to be used can be specified via the "resultType"
+ * property, as outlined above.
+ * <p/>
+ * It is expected that the above mechanism will be satisfactory for most usecase, but not all.
+ * For the other usecases, this action supports {@link org.milyn.container.plugin.SourceResult}
+ * payloads on the ESB Message. This allows you to manually specify other Source and Result
+ * types, which is of particular interest with respect to the Result type e.g. for streaming
+ * the Result to a file etc.
*
- *
* @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
* @author <a href="mailto:daniel.bevenius at gmail.com">daniel.bevenius at gmail.com</a>
*/
@@ -90,15 +105,24 @@
try
{
smooks = new Smooks(smooksConfig);
- payloadProcessor = new PayloadProcessor( smooks, ResultType.STRING );
- }
+ }
catch (Exception e)
{
throw new ConfigurationException("Failed to create Smooks instance for config '" + smooksConfig + "'.", e);
}
-
+
+ // Create the Smooks PayloadProcessor...
+ String resultTypeConfig = configTree.getAttribute("resultType", "STRING");
+ ResultType resultType;
+ try {
+ resultType = ResultType.valueOf(resultTypeConfig);
+ } catch(IllegalArgumentException e) {
+ throw new ConfigurationException("Invalid 'resultType' config value '" + resultTypeConfig + "'. Valid values are: " + Arrays.asList(ResultType.values()));
+ }
+ payloadProcessor = new PayloadProcessor( smooks, resultType );
+
payloadProxy = new MessagePayloadProxy( configTree );
- excludeNonSerializables = Boolean.valueOf( configTree.getAttribute( "excludeNonSerializables", "true" ) );
+ excludeNonSerializables = Boolean.valueOf( configTree.getAttribute( "excludeNonSerializables", "true" ) );
}
/**
@@ -114,7 +138,7 @@
// Create Smooks ExecutionContext.
final ExecutionContext executionContext = createExecutionContext( smooks );
- // Create the Smooks PayloadProcessor which will execute the transformation.
+ // Use the Smooks PayloadProcessor to execute the transformation....
final Object newPayload = payloadProcessor.process( extractPayload( message), executionContext );
// Set the ExecutionContext's attributes on the message instance so other actions can access them.
@@ -188,18 +212,18 @@
if ( !excludeNonSerializables )
return smooksAttribuesMap;
- Map serObjsOnlyMap = new HashMap();
+ Map smooksExecutionContextMap = new HashMap();
- Set<Map.Entry<String,String>> s = smooksAttribuesMap.entrySet();
+ Set<Map.Entry> s = smooksAttribuesMap.entrySet();
for (Map.Entry me : s)
{
Object value = me.getValue();
if( value instanceof Serializable )
{
- serObjsOnlyMap.put( me.getKey(), value );
+ smooksExecutionContextMap.put( me.getKey(), value );
}
}
- return serObjsOnlyMap;
+ return smooksExecutionContextMap;
}
}
Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_FP1/product/services/smooks/src/test/java/org/jboss/soa/esb/actions/smooks/SmooksActionUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_FP1/product/services/smooks/src/test/java/org/jboss/soa/esb/actions/smooks/SmooksActionUnitTest.java 2008-04-29 15:27:15 UTC (rev 19765)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_FP1/product/services/smooks/src/test/java/org/jboss/soa/esb/actions/smooks/SmooksActionUnitTest.java 2008-04-29 16:24:13 UTC (rev 19766)
@@ -132,7 +132,28 @@
assertTrue( serializableObjects.containsKey( "test1" ));
assertTrue( serializableObjects.containsKey( "test2" ));
}
-
+
+ @Test
+ public void ConstructorResultType() throws ConfigurationException, ActionProcessingException
+ {
+ config.setAttribute( "resultType", "STRING" );
+ new SmooksAction( config );
+ config.setAttribute( "resultType", "BYTES" );
+ new SmooksAction( config );
+ config.setAttribute( "resultType", "JAVA" );
+ new SmooksAction( config );
+ config.setAttribute( "resultType", "NORESULT" );
+ new SmooksAction( config );
+
+ config.setAttribute( "resultType", "BLAHHH" );
+ try {
+ new SmooksAction( config );
+ fail("Expected ConfigurationException");
+ } catch (ConfigurationException e) {
+ assertEquals("Invalid 'resultType' config value 'BLAHHH'. Valid values are: [STRING, BYTES, JAVA, NORESULT]", e.getMessage());
+ }
+ }
+
@Before
public void setup()
{
More information about the jboss-svn-commits
mailing list