[jboss-svn-commits] JBL Code SVN: r19760 - in labs/jbossesb/trunk/product: samples/quickstarts/smooks_file_splitter_router and 5 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Apr 29 09:47:01 EDT 2008


Author: beve
Date: 2008-04-29 09:47:01 -0400 (Tue, 29 Apr 2008)
New Revision: 19760

Added:
   labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/orderitem-split.ftl
   labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/src/org/jboss/soa/esb/sample/quickstart/smooksfilesplitterrouter/GetFileListFromExecutionContext.java
   labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-edisax-0.3.jar
   labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-edisax-model-0.3.jar
   labs/jbossesb/trunk/product/services/smooks/lib/ext/opencsv-1.8.jar
   labs/jbossesb/trunk/product/services/smooks/src/test/java/org/jboss/soa/esb/actions/smooks/
   labs/jbossesb/trunk/product/services/smooks/src/test/java/org/jboss/soa/esb/actions/smooks/SmooksActionUnitTest.java
   labs/jbossesb/trunk/product/services/smooks/src/test/java/org/jboss/soa/esb/actions/smooks/smooks-config.xml
Removed:
   labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-edisax-0.2.1.jar
   labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-edisax-model-0.2.1.jar
   labs/jbossesb/trunk/product/services/smooks/lib/ext/opencsv-1.6.jar
   labs/jbossesb/trunk/product/services/smooks/src/main/java/org/jboss/soa/esb/actions/smooks/SmooksFileRouterAction.java
Modified:
   labs/jbossesb/trunk/product/samples/quickstarts/jms_router/jboss-esb.xml
   labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/build.xml
   labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/jboss-esb-unfiltered.xml
   labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/jboss-esb.xml
   labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/readme.txt
   labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/smooks-config.xml
   labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/src/org/jboss/soa/esb/sample/quickstart/smooksfilesplitterrouter/InputOrderGenerator.java
   labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-commons-1.0.jar
   labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-magger-0.1.3.jar
   labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-smooks-core-1.0.jar
   labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-smooks-css-1.0.jar
   labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-smooks-csv-1.0.jar
   labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-smooks-edi-1.0.jar
   labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-smooks-javabean-1.0.jar
   labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-smooks-misc-1.0.jar
   labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-smooks-routing-1.0.jar
   labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-smooks-scripting-1.0.jar
   labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-smooks-servlet-1.0.jar
   labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-smooks-templating-1.0.jar
   labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-tinak-0.8.1.jar
   labs/jbossesb/trunk/product/services/smooks/src/main/java/org/jboss/soa/esb/actions/smooks/SmooksAction.java
Log:
Work for JBESB-1680 "Make sure the official Smooks v1.0 jars are in the product before we release"


Modified: labs/jbossesb/trunk/product/samples/quickstarts/jms_router/jboss-esb.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/jms_router/jboss-esb.xml	2008-04-29 12:55:19 UTC (rev 19759)
+++ labs/jbossesb/trunk/product/samples/quickstarts/jms_router/jboss-esb.xml	2008-04-29 13:47:01 UTC (rev 19760)
@@ -41,7 +41,7 @@
             
                     <action name="printMessage" class="org.jboss.soa.esb.actions.SystemPrintln">
                       <property name="message" value="JMS Secured Quickstart message"/>
-                      <property name="printfull" value="false"/>
+                      <property name="printfull" value="true"/>
                     </action>
 					<action name="routeToReplyQueue" class="org.jboss.soa.esb.actions.routing.JMSRouter">
 						<property name="jndi-context-factory" value="org.jnp.interfaces.NamingContextFactory"/>

Modified: labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/build.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/build.xml	2008-04-29 12:55:19 UTC (rev 19759)
+++ labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/build.xml	2008-04-29 13:47:01 UTC (rev 19760)
@@ -6,7 +6,7 @@
 	</description>
 
 	<!-- Additional files to be deployed in the sar. -->
-	<property name="additional.deploys" value="smooks-config.xml" />
+	<property name="additional.deploys" value="smooks-config.xml,orderitem-split.ftl " />
 	
 	<import file="../conf/base-build.xml"/>
   

Modified: labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/jboss-esb-unfiltered.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/jboss-esb-unfiltered.xml	2008-04-29 12:55:19 UTC (rev 19759)
+++ labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/jboss-esb-unfiltered.xml	2008-04-29 13:47:01 UTC (rev 19760)
@@ -68,10 +68,12 @@
                    		<property name="logLevel"	value="info"/>
 					</action>
 
-					<action name="transform" class="org.jboss.soa.esb.actions.smooks.SmooksFileRouterAction">
+					<action name="transform" class="org.jboss.soa.esb.actions.smooks.SmooksAction">
 						<property name="smooksConfig" value="smooks-config.xml" />
 					</action>
 
+					<action name="getFileList" class="org.jboss.soa.esb.sample.quickstart.smooksfilesplitterrouter.GetFileListFromExecutionContext"/>
+
                     <action name="logBodyAfterTransform" class="org.jboss.soa.esb.actions.LogAction">
                    		<property name="logger"		value="SmooksQuickstart"/>
                    		<property name="logLevel"	value="info"/>

Modified: labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/jboss-esb.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/jboss-esb.xml	2008-04-29 12:55:19 UTC (rev 19759)
+++ labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/jboss-esb.xml	2008-04-29 13:47:01 UTC (rev 19760)
@@ -68,10 +68,12 @@
                    		<property name="logLevel"	value="info"/>
 					</action>
 
-					<action name="transform" class="org.jboss.soa.esb.actions.smooks.SmooksFileRouterAction">
+					<action name="transform" class="org.jboss.soa.esb.actions.smooks.SmooksAction">
 						<property name="smooksConfig" value="smooks-config.xml" />
 					</action>
 
+					<action name="getFileList" class="org.jboss.soa.esb.sample.quickstart.smooksfilesplitterrouter.GetFileListFromExecutionContext"/>
+
                     <action name="logBodyAfterTransform" class="org.jboss.soa.esb.actions.LogAction">
                    		<property name="logger"		value="SmooksQuickstart"/>
                    		<property name="logLevel"	value="info"/>

Added: labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/orderitem-split.ftl
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/orderitem-split.ftl	                        (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/orderitem-split.ftl	2008-04-29 13:47:01 UTC (rev 19760)
@@ -0,0 +1,11 @@
+<orderitem id="${order.orderItem.itemId}" order="${order.orderId}">
+    <customer>
+        <name>${order.customerName}</name>
+        <number>${order.customerNumber?c}</number>
+    </customer>
+    <details>
+        <productId>${order.orderItem.productId}</productId>
+        <quantity>${order.orderItem.quantity}</quantity>
+        <price>${order.orderItem.price}</price>
+    </details>
+</orderitem>
\ No newline at end of file

Modified: labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/readme.txt
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/readme.txt	2008-04-29 12:55:19 UTC (rev 19759)
+++ labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/readme.txt	2008-04-29 13:47:01 UTC (rev 19760)
@@ -3,7 +3,7 @@
  This quickstart demonstrates JBossESB ability to process large files.
  A large file is picked up by a file gateway, transformed, and sent to an FTP server.
 
- The file being process will never exist as the ESB Message object, instead the body
+ The file being process will never exist in the ESB Message object, instead the body
  will only contain the name of the file that is being processed. Note, that this
  means a Network File System (NFS) must be in place if you have multiple ESB instances
  deployed on separate machines.
@@ -13,6 +13,9 @@
  routing features available take a look here:
  http://milyn.codehaus.org/Smooks+User+Guide#SmooksUserGuide-MessageSplitting%26Routing
 
+ This example intentionally only creates one file to be created using a Smooks
+ condition. This was done to limit the number of files that get created. 
+
 Running this quickstart:
 ========================
   Please refer to 'ant help-quickstarts' for prerequisites about the quickstarts

Modified: labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/smooks-config.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/smooks-config.xml	2008-04-29 12:55:19 UTC (rev 19759)
+++ labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/smooks-config.xml	2008-04-29 13:47:01 UTC (rev 19760)
@@ -1,58 +1,47 @@
 <?xml version="1.0"?>
 <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.0.xsd">
 
-    <resource-config selector="global-parameters">
-		<param name="stream.filter.type">SAX</param>
-	</resource-config>
-	
-    <resource-config selector="$document">
-        <resource>org.milyn.routing.file.FileOutputStreamResource</resource>
-        <param name="resourceName">hugeFileRouter</param>
-        <param name="fileNamePattern">Order-${header.customerNumber}.ser</param>
-        <param name="destinationDirectory">/tmp</param>
-        <param name="listFileNamePattern">OrderFiles.lst</param>
+	<resource-config selector="global-parameters">
+        <param name="stream.filter.type">SAX</param>
     </resource-config>
-    
+
     <resource-config selector="order">
         <resource>org.milyn.javabean.BeanPopulator</resource>
         <param name="beanId">order</param>
-        <param name="beanClass">org.jboss.soa.esb.sample.quickstart.smooksfilesplitterrouter.Order</param>
+        <param name="beanClass">java.util.Hashtable</param>
         <param name="bindings">
-            <binding property="header" selector="{header}" />
-            <binding property="orderItems" selector="{orderItems}" />
+            <binding property="orderId" type="Integer" selector="order/@id"/>
+            <binding property="customerNumber" type="Long" selector="header/customer/@number"/>
+            <binding property="customerName" selector="header/customer"/>
+            <binding property="orderItem" selector="${orderItem}"/>
         </param>
     </resource-config>
 
-    <resource-config selector="order">
+    <resource-config selector="order-item">
         <resource>org.milyn.javabean.BeanPopulator</resource>
-        <param name="beanId">orderItems</param>
-        <param name="beanClass">java.util.ArrayList</param>
-    </resource-config>
-
-    <resource-config selector="header">
-        <resource>org.milyn.javabean.BeanPopulator</resource>
-        <param name="beanId">header</param>
-        <param name="beanClass">org.jboss.soa.esb.sample.quickstart.smooksfilesplitterrouter.Header</param>
+        <param name="beanId">orderItem</param>
+        <param name="beanClass">java.util.Hashtable</param>
         <param name="bindings">
-            <binding property="date" type="OrderDateLong" selector="header date" />
-            <binding property="customerNumber" type="Long" selector="header customer @number" />
-            <binding property="customerName" selector="header customer" />
+            <binding property="itemId" type="Integer" selector="order-item/@id"/>
+            <binding property="productId" type="Long" selector="order-item/product"/>
+            <binding property="quantity" type="Integer" selector="order-item/quantity"/>
+            <binding property="price" type="Double" selector="order-item/price"/>
         </param>
     </resource-config>
-    
-    <resource-config selector="header">
-        <resource>org.milyn.routing.io.OutputStreamRouter</resource>
-        <param name="visitAfter">true</param>
-        <param name="resourceName">hugeFileRouter</param>
-        <param name="beanId">header</param>
+
+    <resource-config selector="order-item">
+        <resource>org.milyn.routing.file.FileOutputStreamResource</resource>
+        <param name="resourceName">orderItemSplitStream</param>
+        <param name="fileNamePattern">order-${order.orderId}-${order.orderItem.itemId}.xml</param>
+        <param name="destinationDirectoryPattern">/tmp</param>
+        <param name="listFileNamePattern">order-${order.orderId}.lst</param>
+        <param name="highWaterMark">-1</param>
     </resource-config>
-    
-    <resource-config selector="decoder:OrderDateLong">
-        <resource>org.milyn.javabean.decoders.DateDecoder</resource>
-        <param name="format">EEE MMM dd HH:mm:ss z yyyy</param>
-        <param name="locale-language">en</param>
-        <param name="locale-country">IE</param>
+
+    <resource-config selector="order-item">
+        <resource>orderitem-split.ftl</resource>
+		<condition evaluator="org.milyn.javabean.expression.BeanMapExpressionEvaluator">order.orderItem.itemId == "1"</condition>
+        <param name="outputStreamResource">orderItemSplitStream</param>
     </resource-config>
 
-    
 </smooks-resource-list>

Added: labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/src/org/jboss/soa/esb/sample/quickstart/smooksfilesplitterrouter/GetFileListFromExecutionContext.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/src/org/jboss/soa/esb/sample/quickstart/smooksfilesplitterrouter/GetFileListFromExecutionContext.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/src/org/jboss/soa/esb/sample/quickstart/smooksfilesplitterrouter/GetFileListFromExecutionContext.java	2008-04-29 13:47:01 UTC (rev 19760)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2006, JBoss Inc., and
+ * individual contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of individual
+ * contributors.
+ * 
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ * 
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.sample.quickstart.smooksfilesplitterrouter;
+
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.soa.esb.actions.BeanConfiguredAction;
+import org.jboss.soa.esb.message.Message;
+import org.milyn.container.ExecutionContext;
+import org.milyn.routing.file.FileListAccessor;
+
+/**
+ * 
+ * @author <a href="mailto:daniel.bevenius at gmail.com">Daniel Bevenius</a>			
+ *
+ */
+public class GetFileListFromExecutionContext implements BeanConfiguredAction
+{
+	public Message process( final Message message )
+	{
+		Object object = message.getBody().get("SmooksExecutionContext");
+		if ( object != null )
+		{
+    		List<String> listFileNames = FileListAccessor.getListFileNames( (Map) object );
+    		message.getBody().add( listFileNames );
+		}
+		return message;
+	}
+
+}
\ No newline at end of file

Modified: labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/src/org/jboss/soa/esb/sample/quickstart/smooksfilesplitterrouter/InputOrderGenerator.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/src/org/jboss/soa/esb/sample/quickstart/smooksfilesplitterrouter/InputOrderGenerator.java	2008-04-29 12:55:19 UTC (rev 19759)
+++ labs/jbossesb/trunk/product/samples/quickstarts/smooks_file_splitter_router/src/org/jboss/soa/esb/sample/quickstart/smooksfilesplitterrouter/InputOrderGenerator.java	2008-04-29 13:47:01 UTC (rev 19760)
@@ -73,17 +73,16 @@
 		File file = new File ( fileName );
 		deleteFile( file );
 		FileWriter writer = new FileWriter( file, true );
-		writer.write( "<order>" + LINE_SEP );
+		writer.write( "<order id='332'>" + LINE_SEP );
 		writer.write( "<header>" + LINE_SEP);
-		writer.write( "<date>Wed Nov 15 13:45:28 EST 2006</date>" + LINE_SEP );
 		writer.write( "<customer number=\"123\">Joe</customer>" + LINE_SEP );
 		writer.write( "</header>" + LINE_SEP);
 		writer.flush();
 		writer.write( "<order-items>" + LINE_SEP );
 		System.out.print("Generating " + file.getName() + "...");
-		for ( int i = 1 ; i < nrOfOrderItems ; i ++ )
+		for ( int i = 1 ; i <= nrOfOrderItems ; i ++ )
 		{
-    		writer.write( "<order-item>" + LINE_SEP );
+    		writer.write( "<order-item id='" + i + "'>" + LINE_SEP );
     		writer.write( "<product>" + i + "</product>" + LINE_SEP );
     		writer.write( "<quantity>2</quantity>" + LINE_SEP );
     		writer.write( "<price>8.80</price>" + LINE_SEP );
@@ -96,7 +95,7 @@
 		System.out.println();
 		System.out.println("Generated " + file.getName() + " size = [" + getFileLength( file ) + "]" );
 	}
-	
+		
 	private static void deleteFile( final File file ) throws IOException
 	{
 		if ( file.exists() )

Modified: labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-commons-1.0.jar
===================================================================
(Binary files differ)

Deleted: labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-edisax-0.2.1.jar
===================================================================
(Binary files differ)

Added: labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-edisax-0.3.jar
===================================================================
(Binary files differ)


Property changes on: labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-edisax-0.3.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Deleted: labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-edisax-model-0.2.1.jar
===================================================================
(Binary files differ)

Added: labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-edisax-model-0.3.jar
===================================================================
(Binary files differ)


Property changes on: labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-edisax-model-0.3.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-magger-0.1.3.jar
===================================================================
(Binary files differ)

Modified: labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-smooks-core-1.0.jar
===================================================================
(Binary files differ)

Modified: labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-smooks-css-1.0.jar
===================================================================
(Binary files differ)

Modified: labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-smooks-csv-1.0.jar
===================================================================
(Binary files differ)

Modified: labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-smooks-edi-1.0.jar
===================================================================
(Binary files differ)

Modified: labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-smooks-javabean-1.0.jar
===================================================================
(Binary files differ)

Modified: labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-smooks-misc-1.0.jar
===================================================================
(Binary files differ)

Modified: labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-smooks-routing-1.0.jar
===================================================================
(Binary files differ)

Modified: labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-smooks-scripting-1.0.jar
===================================================================
(Binary files differ)

Modified: labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-smooks-servlet-1.0.jar
===================================================================
(Binary files differ)

Modified: labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-smooks-templating-1.0.jar
===================================================================
(Binary files differ)

Modified: labs/jbossesb/trunk/product/services/smooks/lib/ext/milyn-tinak-0.8.1.jar
===================================================================
(Binary files differ)

Deleted: labs/jbossesb/trunk/product/services/smooks/lib/ext/opencsv-1.6.jar
===================================================================
(Binary files differ)

Added: labs/jbossesb/trunk/product/services/smooks/lib/ext/opencsv-1.8.jar
===================================================================
(Binary files differ)


Property changes on: labs/jbossesb/trunk/product/services/smooks/lib/ext/opencsv-1.8.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: labs/jbossesb/trunk/product/services/smooks/src/main/java/org/jboss/soa/esb/actions/smooks/SmooksAction.java
===================================================================
--- labs/jbossesb/trunk/product/services/smooks/src/main/java/org/jboss/soa/esb/actions/smooks/SmooksAction.java	2008-04-29 12:55:19 UTC (rev 19759)
+++ labs/jbossesb/trunk/product/services/smooks/src/main/java/org/jboss/soa/esb/actions/smooks/SmooksAction.java	2008-04-29 13:47:01 UTC (rev 19760)
@@ -19,53 +19,107 @@
  */
 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;
 import org.jboss.soa.esb.actions.ActionProcessingException;
 import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.message.MessageDeliverException;
 import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.MessagePayloadProxy;
 import org.milyn.Smooks;
 import org.milyn.container.ExecutionContext;
 import org.milyn.container.plugin.PayloadProcessor;
+import org.milyn.container.plugin.ResultType;
 
 /**
  * Smooks pipeline processor action.
+ * <p/>
+ * Usage:
+ * <pre>
+ * &lt;action name="transform" class="org.jboss.soa.esb.actions.smooks.SmooksAction"&gt;
+ * 	&lt;property name="smooksConfig" value="smooks-config.xml" /&gt;
+ * &lt;/action&gt;
  *
+ * Optional properties:
+ * &lt;property name="get-payload-location" value="input" /&gt;
+ * &lt;property name="set-payload-location" value="ouput" /&gt;
+ * &lt;property name="excludeNonSerializables" value="false" /&gt;
+ * </pre>
+ * 
+ * Description of configuration properties:
+ * <ul>
+ * <li><i>smooksConfig</i> - the Smooks configuration file. Can be a path on the file system or on the classpath.
+ * <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.
+ * </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:
+ * <pre>
+ * message.getBody().get( EXECUTION_CONTEXT_ATTR_MAP_KEY );
+ * </pre>
+ * 
+ * 
  * @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>
  */
 public class SmooksAction extends AbstractActionPipelineProcessor 
 {
-
+    public static final String EXECUTION_CONTEXT_ATTR_MAP_KEY = "SmooksExecutionContext";
+    
     private Smooks smooks;
-    private PayloadProcessor payloadProcessor;
+    
+	private PayloadProcessor payloadProcessor;
 
+	private MessagePayloadProxy payloadProxy;
+
+	private boolean excludeNonSerializables;
+
     // public 
     
-    public SmooksAction(ConfigTree configTree) throws ConfigurationException 
+    public SmooksAction( final ConfigTree configTree ) throws ConfigurationException 
     {
-        String smooksConfig = configTree.getRequiredAttribute("smooksConfig");
+        final String smooksConfig = configTree.getRequiredAttribute("smooksConfig");
         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);
         }
+        
+        payloadProxy = new MessagePayloadProxy( configTree );
+        excludeNonSerializables = Boolean.valueOf( configTree.getAttribute( "excludeNonSerializables", "true" ) );
     }
     
-    @Override
-	public void initialise() throws ActionLifecycleException
+    /**
+     * Executes the actual Smooks tranformation.
+     * 
+     * @param message	The ESB Message object
+     * 
+     * @return			The ESB Message object with the output of the transformation.
+     * 					
+     */
+	public Message process( final Message message) throws ActionProcessingException 
 	{
-    	payloadProcessor = createPayloadProcessor( smooks );
-	}
-
-	public Message process(Message message) throws ActionProcessingException 
-	{
-        ExecutionContext executionContext = createExecutionContext( smooks );
-        Object payload = extractPayload( message );
-        Object newPayload = payloadProcessor.process( payload, executionContext );
+		//	Create Smooks ExecutionContext.
+        final ExecutionContext executionContext = createExecutionContext( smooks );
+        
+        //	Create the Smooks PayloadProcessor which will 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.
+        message.getBody().add( EXECUTION_CONTEXT_ATTR_MAP_KEY, getSerializableObjectsMap( executionContext.getAttributes() ) );
+        
         return packagePayload( newPayload, message );
     }
 
@@ -91,26 +145,61 @@
      * 	Hook for subclasses to extract the message payload in
      * 	any way they see fit.
      */
-    protected Object extractPayload(final Message message )
+    protected Object extractPayload(final Message message ) throws ActionProcessingException 
     {
-        return message.getBody().get();
+    	try
+		{
+			return payloadProxy.getPayload( message );
+		} 
+    	catch (MessageDeliverException e)
+		{
+    		throw new ActionProcessingException("MessgeDeliveryException while trying to retrieve the message payload:", e);
+		}
     }
     
     /*
-     * 	Hook for subclasses so they can controll what and where the payload
+     * 	Hook for subclasses so they can control what and where the payload
      * 	is added to the ESB Message object.
      */
-    protected Message packagePayload( final Object payload, Message message )
+    protected Message packagePayload( final Object payload, Message message ) throws ActionProcessingException
     {
-        if ( payload != null )
-        {
-            message.getBody().add( payload );
-        }
-        return message;
+    	try
+		{
+			payloadProxy.setPayload( message, payload );
+            return message;
+		} 
+    	catch (MessageDeliverException e)
+		{
+    		throw new ActionProcessingException("MessgeDeliveryException while trying to retrieve the message payload:", e);
+			
+		}
     }
+
+    /**
+     * Will return a Map containing only the Serializable objects 
+     * that exist in the passed-in Map if {@link #excludeNonSerializables} is true.
+     * 
+     * @param smooksAttribuesMap 	- Map containing attributes from the Smooks ExecutionContext
+     * @return Map	- Map containing only the Serializable objects from the passed-in map.
+     */
+    @SuppressWarnings( "unchecked" )
+	protected Map getSerializableObjectsMap( final Map smooksAttribuesMap )
+	{
+    	if ( !excludeNonSerializables )
+    		return smooksAttribuesMap;
+    	
+		Map serObjsOnlyMap = new HashMap();
+		
+		Set<Map.Entry<String,String>> s = smooksAttribuesMap.entrySet();
+		for (Map.Entry me : s) 
+		{
+			Object value = me.getValue();
+			if( value instanceof Serializable )
+			{
+				serObjsOnlyMap.put( me.getKey(), value );
+			}
+		}
+		return serObjsOnlyMap;
+	}
     
-    protected PayloadProcessor createPayloadProcessor( final Smooks smooks )
-    {
-    	return new PayloadProcessor( smooks );
-    }
 }

Deleted: labs/jbossesb/trunk/product/services/smooks/src/main/java/org/jboss/soa/esb/actions/smooks/SmooksFileRouterAction.java
===================================================================
--- labs/jbossesb/trunk/product/services/smooks/src/main/java/org/jboss/soa/esb/actions/smooks/SmooksFileRouterAction.java	2008-04-29 12:55:19 UTC (rev 19759)
+++ labs/jbossesb/trunk/product/services/smooks/src/main/java/org/jboss/soa/esb/actions/smooks/SmooksFileRouterAction.java	2008-04-29 13:47:01 UTC (rev 19760)
@@ -1,56 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and others contributors as indicated
- * by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA  02110-1301, USA.
- *
- * (C) 2005-2006, JBoss Inc.
- */
-package org.jboss.soa.esb.actions.smooks;
-
-import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.milyn.Smooks;
-import org.milyn.container.plugin.PayloadProcessor;
-import org.milyn.routing.file.FileRouterPayloadProcessor;
-
-/**
- * SmooksFileRouterAction is an ESB action for performing a Smooks tranform
- * and 'routing' the results to a file.
- * </p> 
- * 
- * A call to message.getBody().get() after this action has done it work will return
- * a single String which is the path to a file. This file contains a list of files
- * that were generated during the transform. The reason for this not being a list of 
- * files is to avoid memory issue which large transforms which generate may files.
- * 
- * @author <a href="mailto:daniel.bevenius at gmail.com">Daniel Bevenius</a>			
- *
- */
-public class SmooksFileRouterAction extends SmooksAction 
-{
-	public SmooksFileRouterAction(ConfigTree configTree) throws ConfigurationException 
-    {
-    	super( configTree );
-    }
-
-	//	protected
-	
-	@Override
-	protected PayloadProcessor createPayloadProcessor( final Smooks smooks )
-	{
-		return new FileRouterPayloadProcessor( smooks );
-	}
-
-}

Added: labs/jbossesb/trunk/product/services/smooks/src/test/java/org/jboss/soa/esb/actions/smooks/SmooksActionUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/smooks/src/test/java/org/jboss/soa/esb/actions/smooks/SmooksActionUnitTest.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/smooks/src/test/java/org/jboss/soa/esb/actions/smooks/SmooksActionUnitTest.java	2008-04-29 13:47:01 UTC (rev 19760)
@@ -0,0 +1,160 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2006, JBoss Inc., and
+ * individual contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of individual
+ * contributors.
+ * 
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ * 
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.actions.smooks;
+
+import static org.junit.Assert.*;
+
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.MessagePayloadProxy;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.junit.Before;
+import org.junit.Test;
+
+import junit.framework.JUnit4TestAdapter;
+
+/**
+ * Unit test for {@link SmooksAction}
+ * 
+ * @author <a href="mailto:daniel.bevenius at gmail.com">Daniel Bevenius</a>			
+ *
+ */
+public class SmooksActionUnitTest
+{
+	private String expectedString = "<test></test>";
+	private ConfigTree config;
+	
+	@Test
+	public void process() throws ConfigurationException, ActionProcessingException
+	{
+		SmooksAction action = new SmooksAction( config );
+		Message message = MessageFactory.getInstance().getMessage();
+		message.getBody().add( expectedString );
+		
+		Message process = action.process( message );
+		
+		String actualString = (String)process.getBody().get();
+		assertEquals( expectedString, actualString );
+	}
+	
+	@Test
+	public void processWithPayloadLocation() throws ConfigurationException, ActionProcessingException
+	{
+		config.setAttribute( MessagePayloadProxy.GET_PAYLOAD_LOCATION, "input" );
+		SmooksAction action = new SmooksAction( config );
+		Message message = MessageFactory.getInstance().getMessage();
+		message.getBody().add( "input", expectedString );
+		
+		Message process = action.process( message );
+		
+		String actualString = (String)process.getBody().get();
+		assertEquals( expectedString, actualString );
+	}
+	
+	@Test
+	public void processWithOutLocation() throws ConfigurationException, ActionProcessingException
+	{
+		config.setAttribute( MessagePayloadProxy.SET_PAYLOAD_LOCATION, "output" );
+		SmooksAction action = new SmooksAction( config );
+		Message message = MessageFactory.getInstance().getMessage();
+		message.getBody().add( expectedString );
+		
+		Message process = action.process( message );
+		
+		String actualString = (String)process.getBody().get( "output" );
+		assertEquals( expectedString, actualString );
+	}
+	
+	@Test
+	public void getExecutionContextAttributes() throws ConfigurationException, ActionProcessingException
+	{
+		SmooksAction action = new SmooksAction( config );
+		Message message = MessageFactory.getInstance().getMessage();
+		message.getBody().add( expectedString );
+		
+		Message process = action.process( message );
+		
+		Object object = process.getBody().get( SmooksAction.EXECUTION_CONTEXT_ATTR_MAP_KEY );
+		assertTrue( object instanceof Map );
+	}
+	
+	@Test
+	@SuppressWarnings("unchecked")
+	public void getExecutionContextAttributesNonSerializable() throws ConfigurationException, ActionProcessingException
+	{
+		Map map = new Hashtable();
+		map.put( "test1", "testing" );
+		map.put( "test2", new NonSerializableClass() );
+		SmooksAction action = new SmooksAction( config );
+		
+		Map serializableObjects = action.getSerializableObjectsMap( map );
+		
+		assertTrue( serializableObjects.containsKey( "test1" ));
+		assertTrue( !serializableObjects.containsKey( "test2" ));
+	}
+	
+	@Test
+	@SuppressWarnings("unchecked")
+	public void getExecutionContextAttributesWithSerializable() throws ConfigurationException, ActionProcessingException
+	{
+		Map map = new Hashtable();
+		map.put( "test1", "testing" );
+		map.put( "test2", new NonSerializableClass() );
+		config.setAttribute( "excludeNonSerializables", "false" );
+		SmooksAction action = new SmooksAction( config );
+		
+		Map serializableObjects = action.getSerializableObjectsMap( map );
+		
+		assertTrue( serializableObjects.containsKey( "test1" ));
+		assertTrue( serializableObjects.containsKey( "test2" ));
+	}
+	
+	@Before
+	public void setup()
+	{
+		config = createConfigTree();
+		
+	}
+	
+	public static junit.framework.Test suite()
+	{
+		return new JUnit4TestAdapter( SmooksActionUnitTest.class );
+	}
+	
+	private ConfigTree createConfigTree()
+	{
+		ConfigTree config = new ConfigTree( "SmooksActionTest" );
+		config.setAttribute( "smooksConfig", "/org/jboss/soa/esb/actions/smooks/smooks-config.xml" );
+		return config;
+	}
+	
+	private static class NonSerializableClass 
+	{
+		
+	}
+
+}

Added: labs/jbossesb/trunk/product/services/smooks/src/test/java/org/jboss/soa/esb/actions/smooks/smooks-config.xml
===================================================================
--- labs/jbossesb/trunk/product/services/smooks/src/test/java/org/jboss/soa/esb/actions/smooks/smooks-config.xml	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/smooks/src/test/java/org/jboss/soa/esb/actions/smooks/smooks-config.xml	2008-04-29 13:47:01 UTC (rev 19760)
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.0.xsd">
+
+    <resource-config selector="global-parameters">
+        <param name="stream.filter.type">DOM</param>
+    </resource-config>
+	
+</smooks-resource-list>




More information about the jboss-svn-commits mailing list