[jboss-svn-commits] JBL Code SVN: r20832 - in labs/jbossesb/branches/JBESB_4_2_1_GA_FP/product: services/smooks/src/main/java/org/jboss/soa/esb/smooks and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Jun 27 12:11:00 EDT 2008
Author: tfennelly
Date: 2008-06-27 12:11:00 -0400 (Fri, 27 Jun 2008)
New Revision: 20832
Added:
labs/jbossesb/branches/JBESB_4_2_1_GA_FP/product/services/smooks/src/test/java/org/jboss/soa/esb/smooks/ProfilingUnitTest.java
labs/jbossesb/branches/JBESB_4_2_1_GA_FP/product/services/smooks/src/test/java/org/jboss/soa/esb/smooks/profiling-esb.xml
labs/jbossesb/branches/JBESB_4_2_1_GA_FP/product/services/smooks/src/test/java/org/jboss/soa/esb/smooks/profiling-smooks-01.xml
Modified:
labs/jbossesb/branches/JBESB_4_2_1_GA_FP/product/rosetta/src/org/jboss/soa/esb/message/Properties.java
labs/jbossesb/branches/JBESB_4_2_1_GA_FP/product/services/smooks/src/main/java/org/jboss/soa/esb/smooks/SmooksAction.java
Log:
3rd part of http://jira.jboss.com/jira/browse/JBESB-1853
Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_FP/product/rosetta/src/org/jboss/soa/esb/message/Properties.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_FP/product/rosetta/src/org/jboss/soa/esb/message/Properties.java 2008-06-27 15:16:14 UTC (rev 20831)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_FP/product/rosetta/src/org/jboss/soa/esb/message/Properties.java 2008-06-27 16:11:00 UTC (rev 20832)
@@ -29,6 +29,11 @@
public interface Properties
{
+ /**
+ * Message Profile property key.
+ */
+ public static final String MESSAGE_PROFILE = "messageProfile";
+
/**
* getProperty(name)
*
Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_FP/product/services/smooks/src/main/java/org/jboss/soa/esb/smooks/SmooksAction.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_FP/product/services/smooks/src/main/java/org/jboss/soa/esb/smooks/SmooksAction.java 2008-06-27 15:16:14 UTC (rev 20831)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_FP/product/services/smooks/src/main/java/org/jboss/soa/esb/smooks/SmooksAction.java 2008-06-27 16:11:00 UTC (rev 20832)
@@ -27,14 +27,16 @@
import org.jboss.soa.esb.listeners.message.MessageDeliverException;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.MessagePayloadProxy;
+import org.jboss.soa.esb.message.Properties;
import org.milyn.Smooks;
-import org.milyn.event.report.HtmlReportGenerator;
+import org.milyn.profile.Profile;
import org.milyn.container.ExecutionContext;
import org.milyn.container.plugin.PayloadProcessor;
import org.milyn.container.plugin.ResultType;
+import org.milyn.event.report.HtmlReportGenerator;
-import java.io.Serializable;
import java.io.IOException;
+import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -57,19 +59,22 @@
* <property name="excludeNonSerializables" value="false" />
* <property name="resultType" value="STRING" />
* <property name="reportPath" value="/tmp/smooks-report.html" />
+ * <property name="messageProfile" value="fromServiceA" />
* </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>get-payload-location</i> - the body location which contains the object to be transformed. See {@link MessagePayloadProxy}.
+ * <li><i>set-payload-location</i> - the body location where the transformed object will be placed. See {@link MessagePayloadProxy}.
* <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". For more
* on specifying and controlling the Smooks filtering result, see <a href="#specify-result">Specifying the Source and Result Types</a>.
* <li><i>javaResultBeanId</i> - specifies the Smooks bean context beanId to be mapped as the result when the resultType is "JAVA". If not specified,
* the whole bean context bean Map is mapped as the result.
* <li><i>reportPath</i> - specifies the path and file name for generating a Smooks Execution Report. This is a development tool.
+ * <li><i>messageProfile</i> - specifies the default message "profile" name to be used in {@link Smooks#createExecutionContext(String) creation of the Smooks ExecutionContext}.
+ * See <a href="#profiling">Message Profiling</a>.
* </ul>
*
* <h3>Exposing the Smooks {@link ExecutionContext} to other ESB Actions</h3>
@@ -92,6 +97,17 @@
* types, which is of particular interest with respect to the Result type e.g. for streaming
* the Result to a file etc.
*
+ * <h3 id="profiling">Message Profiling</h3>
+ * Smooks Profiling allows you to use a single Smooks instance to transform multiple
+ * source messages. As an example, imagine a situation where messages of different formats
+ * are delivered to a Service. Before consuming the messages, the Service needs to transform
+ * these message payloads to a common format. To accomplish this, you can use profiling.
+ * <p/>
+ * The action can have the default profile name configured through the "messageProfile"
+ * property. Each incoming ESB message can specify it's profile name through the
+ * message property of the same name ("messageProfile"). For more on profiling, see
+ * the <a href="http://milyn.codehaus.org/Smooks+Example+-+profiling">profiling example</a>.
+ *
* @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>
*/
@@ -101,12 +117,14 @@
private Smooks smooks;
- private PayloadProcessor payloadProcessor;
+ private String defaultMessageProfile;
- private MessagePayloadProxy payloadProxy;
+ private PayloadProcessor payloadProcessor;
- private boolean excludeNonSerializables;
+ private MessagePayloadProxy payloadProxy;
+ private boolean excludeNonSerializables;
+
private String reportPath;
// public
@@ -127,6 +145,9 @@
throw new ConfigurationException("Failed to create Smooks instance for config '" + smooksConfig + "'.", e);
}
+ // Get the default profile from the config...
+ defaultMessageProfile = configTree.getAttribute(Properties.MESSAGE_PROFILE, Profile.DEFAULT_PROFILE);
+
// Create the Smooks PayloadProcessor...
String resultTypeConfig = configTree.getAttribute("resultType", "STRING");
ResultType resultType;
@@ -159,8 +180,9 @@
*/
public Message process( final Message message) throws ActionProcessingException
{
- // Create Smooks ExecutionContext.
- final ExecutionContext executionContext = createExecutionContext( smooks );
+ // Create Smooks ExecutionContext.
+ final String messageProfofile = (String) message.getProperties().getProperty(Properties.MESSAGE_PROFILE, defaultMessageProfile);
+ final ExecutionContext executionContext = smooks.createExecutionContext(messageProfofile);
if(reportPath != null) {
try {
@@ -171,12 +193,24 @@
}
// Use the Smooks PayloadProcessor to execute the transformation....
- final Object newPayload = payloadProcessor.process( extractPayload( message), executionContext );
+ final Object payload;
+ try {
+ payload = payloadProxy.getPayload(message);
+ } catch (MessageDeliverException e) {
+ throw new ActionProcessingException("MessgeDeliveryException while trying to retrieve the message payload:", e);
+ }
+ final Object newPayload = payloadProcessor.process( payload, 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 );
+ try {
+ payloadProxy.setPayload( message, newPayload );
+ } catch (MessageDeliverException e) {
+ throw new ActionProcessingException("MessgeDeliveryException while trying to retrieve the message payload:", e);
+ }
+
+ return message;
}
@Override
@@ -188,49 +222,6 @@
// protected
- /*
- * Hook for subclasses to control how the execution context is created.
- * Might be useful for Actions that use profiles for example.
- */
- protected ExecutionContext createExecutionContext( final Smooks smooks )
- {
- return smooks.createExecutionContext();
- }
-
- /*
- * Hook for subclasses to extract the message payload in
- * any way they see fit.
- */
- protected Object extractPayload(final Message message ) throws ActionProcessingException
- {
- 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 control what and where the payload
- * is added to the ESB Message object.
- */
- protected Message packagePayload( final Object payload, Message message ) throws ActionProcessingException
- {
- 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.
Copied: labs/jbossesb/branches/JBESB_4_2_1_GA_FP/product/services/smooks/src/test/java/org/jboss/soa/esb/smooks/ProfilingUnitTest.java (from rev 20682, labs/jbossesb/trunk/product/services/smooks/src/test/java/org/jboss/soa/esb/smooks/ProfilingUnitTest.java)
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_FP/product/services/smooks/src/test/java/org/jboss/soa/esb/smooks/ProfilingUnitTest.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_FP/product/services/smooks/src/test/java/org/jboss/soa/esb/smooks/ProfilingUnitTest.java 2008-06-27 16:11:00 UTC (rev 20832)
@@ -0,0 +1,71 @@
+/*
+ * 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.smooks;
+
+import junit.framework.TestCase;
+import org.jboss.internal.soa.esb.util.StreamUtils;
+import org.jboss.soa.esb.client.ServiceInvoker;
+import org.jboss.soa.esb.couriers.FaultMessageException;
+import org.jboss.soa.esb.listeners.message.MessageDeliverException;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.Properties;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.testutils.ESBConfigUtil;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class ProfilingUnitTest extends TestCase {
+
+ private ESBConfigUtil esbConfig;
+ private byte[] personXmlBytes = StreamUtils.readStream(SourceResultUnitTest.class.getResourceAsStream("message/person.xml"));
+
+ protected void setUp() throws Exception {
+ esbConfig = new ESBConfigUtil(getClass().getResourceAsStream("profiling-esb.xml"));
+ esbConfig.setESBProperties(getClass().getResourceAsStream("jbossesb-properties.xml"));
+ esbConfig.installRegistry();
+ esbConfig.startController();
+ }
+
+ protected void tearDown() throws Exception {
+ esbConfig.stopController();
+ esbConfig.uninstallRegistry();
+ esbConfig.resetESBProperties();
+ }
+
+ public void test() throws RegistryException, FaultMessageException, MessageDeliverException {
+ test("profile1", "<someone called=\"Tom Fennelly\" is=\"21\">");
+ test("profile2", "<person name=\"Tom Fennelly\" age=\"21\">");
+ }
+
+ private void test(String profile, String expected) throws MessageDeliverException, RegistryException, FaultMessageException {
+ ServiceInvoker invoker = new ServiceInvoker("Transform", "String");
+ Message message = MessageFactory.getInstance().getMessage();
+
+ // Create the message and set the profile on it...
+ message.getBody().add(new String(personXmlBytes));
+ message.getProperties().setProperty(Properties.MESSAGE_PROFILE, profile);
+
+ message = invoker.deliverSync(message, 30000);
+
+ assertEquals(expected, message.getBody().get());
+ }
+}
Copied: labs/jbossesb/branches/JBESB_4_2_1_GA_FP/product/services/smooks/src/test/java/org/jboss/soa/esb/smooks/profiling-esb.xml (from rev 20682, labs/jbossesb/trunk/product/services/smooks/src/test/java/org/jboss/soa/esb/smooks/profiling-esb.xml)
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_FP/product/services/smooks/src/test/java/org/jboss/soa/esb/smooks/profiling-esb.xml (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_FP/product/services/smooks/src/test/java/org/jboss/soa/esb/smooks/profiling-esb.xml 2008-06-27 16:11:00 UTC (rev 20832)
@@ -0,0 +1,14 @@
+<?xml version = "1.0" encoding = "UTF-8"?>
+<jbossesb xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd">
+
+ <services>
+ <service category="Transform" name="String" description="StringTest" invmScope="GLOBAL">
+ <actions mep="RequestResponse">
+ <action name="action" class="org.jboss.soa.esb.smooks.SmooksAction">
+ <property name="smooksConfig" value="/org/jboss/soa/esb/smooks/profiling-smooks-01.xml" />
+ </action>
+ </actions>
+ </service>
+ </services>
+
+</jbossesb>
\ No newline at end of file
Copied: labs/jbossesb/branches/JBESB_4_2_1_GA_FP/product/services/smooks/src/test/java/org/jboss/soa/esb/smooks/profiling-smooks-01.xml (from rev 20682, labs/jbossesb/trunk/product/services/smooks/src/test/java/org/jboss/soa/esb/smooks/profiling-smooks-01.xml)
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_FP/product/services/smooks/src/test/java/org/jboss/soa/esb/smooks/profiling-smooks-01.xml (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_FP/product/services/smooks/src/test/java/org/jboss/soa/esb/smooks/profiling-smooks-01.xml 2008-06-27 16:11:00 UTC (rev 20832)
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.0.xsd">
+
+ <profiles>
+ <profile base-profile="profile1" sub-profiles="common" />
+ <profile base-profile="profile2" sub-profiles="common" />
+ </profiles>
+
+ <resource-config selector="person" target-profile="common">
+ <resource>org.milyn.javabean.BeanPopulator</resource>
+ <param name="beanId">person</param>
+ <param name="beanClass">org.jboss.soa.esb.smooks.message.Person1</param>
+ <param name="bindings">
+ <binding property="name" selector="person/name" />
+ <binding property="age" type="Integer" selector="person/age" />
+ </param>
+ </resource-config>
+
+ <resource-config selector="person" target-profile="profile1">
+ <resource type="ftl"><!--<someone called="${person.name}" is="${person.age}">--></resource>
+ </resource-config>
+
+ <resource-config selector="person" target-profile="profile2">
+ <resource type="ftl"><!--<person name="${person.name}" age="${person.age}">--></resource>
+ </resource-config>
+
+</smooks-resource-list>
\ No newline at end of file
More information about the jboss-svn-commits
mailing list