[jboss-svn-commits] JBL Code SVN: r15713 - in labs/jbossesb/trunk/product: samples/quickstarts/webservice_consumer2/src/org/jboss/soa/esb/samples/quickstart/webservice_consumer2 and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Oct 10 06:18:58 EDT 2007
Author: tfennelly
Date: 2007-10-10 06:18:58 -0400 (Wed, 10 Oct 2007)
New Revision: 15713
Added:
labs/jbossesb/trunk/product/samples/quickstarts/webservice_consumer2/src/org/jboss/soa/esb/samples/quickstart/webservice_consumer2/ProcessOrderRequest.java
Modified:
labs/jbossesb/trunk/product/samples/quickstarts/webservice_consumer2/jboss-esb.xml
labs/jbossesb/trunk/product/samples/quickstarts/webservice_consumer2/src/org/jboss/soa/esb/samples/quickstart/webservice_consumer2/MyRequestAction.java
labs/jbossesb/trunk/product/services/smooks/src/main/java/org/jboss/soa/esb/actions/converters/SmooksTransformer.java
labs/jbossesb/trunk/product/services/smooks/src/test/java/org/jboss/soa/esb/actions/converters/SmooksTransformerUnitTest.java
Log:
webservice_consumer2 quickstart Option #1 request markup does not work: http://jira.jboss.com/jira/browse/JBESB-1102
Modified: labs/jbossesb/trunk/product/samples/quickstarts/webservice_consumer2/jboss-esb.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/webservice_consumer2/jboss-esb.xml 2007-10-10 07:39:44 UTC (rev 15712)
+++ labs/jbossesb/trunk/product/samples/quickstarts/webservice_consumer2/jboss-esb.xml 2007-10-10 10:18:58 UTC (rev 15713)
@@ -25,7 +25,7 @@
<actions>
<action name="request-mapper"
class="org.jboss.soa.esb.samples.quickstart.webservice_consumer2.MyRequestAction"
- process="option2">
+ process="option1">
</action>
<action name="soapui-client-action"
class="org.jboss.soa.esb.actions.soap.SOAPClient">
Modified: labs/jbossesb/trunk/product/samples/quickstarts/webservice_consumer2/src/org/jboss/soa/esb/samples/quickstart/webservice_consumer2/MyRequestAction.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/webservice_consumer2/src/org/jboss/soa/esb/samples/quickstart/webservice_consumer2/MyRequestAction.java 2007-10-10 07:39:44 UTC (rev 15712)
+++ labs/jbossesb/trunk/product/samples/quickstarts/webservice_consumer2/src/org/jboss/soa/esb/samples/quickstart/webservice_consumer2/MyRequestAction.java 2007-10-10 10:18:58 UTC (rev 15713)
@@ -69,8 +69,10 @@
order.setLineItems(lineItems);
- //requestMap.put("processOrder.order", order);
- requestMap.put("order", order);
+ ProcessOrderRequest requestObject = new ProcessOrderRequest();
+ requestObject.setOrder(order);
+ requestMap.put("processOrder", requestObject);
+ //requestMap.put("order", order);
message.getBody().add("request-params", requestMap);
System.out.println("Request map is: " + requestMap.toString());
Added: labs/jbossesb/trunk/product/samples/quickstarts/webservice_consumer2/src/org/jboss/soa/esb/samples/quickstart/webservice_consumer2/ProcessOrderRequest.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/webservice_consumer2/src/org/jboss/soa/esb/samples/quickstart/webservice_consumer2/ProcessOrderRequest.java (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/webservice_consumer2/src/org/jboss/soa/esb/samples/quickstart/webservice_consumer2/ProcessOrderRequest.java 2007-10-10 10:18:58 UTC (rev 15713)
@@ -0,0 +1,38 @@
+/*
+ * 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.samples.quickstart.webservice_consumer2;
+
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class ProcessOrderRequest implements Serializable {
+
+ private Order order;
+
+ public Order getOrder() {
+ return order;
+ }
+
+ public void setOrder(Order order) {
+ this.order = order;
+ }
+}
Property changes on: labs/jbossesb/trunk/product/samples/quickstarts/webservice_consumer2/src/org/jboss/soa/esb/samples/quickstart/webservice_consumer2/ProcessOrderRequest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: labs/jbossesb/trunk/product/services/smooks/src/main/java/org/jboss/soa/esb/actions/converters/SmooksTransformer.java
===================================================================
--- labs/jbossesb/trunk/product/services/smooks/src/main/java/org/jboss/soa/esb/actions/converters/SmooksTransformer.java 2007-10-10 07:39:44 UTC (rev 15712)
+++ labs/jbossesb/trunk/product/services/smooks/src/main/java/org/jboss/soa/esb/actions/converters/SmooksTransformer.java 2007-10-10 10:18:58 UTC (rev 15713)
@@ -20,12 +20,10 @@
package org.jboss.soa.esb.actions.converters;
import java.io.ByteArrayInputStream;
-import java.io.InputStream;
import java.util.*;
import org.apache.log4j.Logger;
import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.util.ClassUtil;
import org.jboss.soa.esb.actions.ActionLifecycleException;
import org.jboss.soa.esb.actions.ActionPipelineProcessor;
import org.jboss.soa.esb.actions.ActionProcessingException;
@@ -37,9 +35,11 @@
import org.jboss.soa.esb.message.body.content.BytesBody;
import org.jboss.soa.esb.services.transform.TransformationException;
import org.jboss.soa.esb.services.transform.TransformationService;
+import org.jboss.internal.soa.esb.assertion.AssertArgument;
import org.milyn.Smooks;
import org.milyn.SmooksUtil;
import org.milyn.container.standalone.StandaloneExecutionContext;
+import org.milyn.container.ExecutionContext;
import org.milyn.javabean.BeanAccessor;
import org.milyn.profile.DefaultProfileSet;
import org.milyn.profile.ProfileStore;
@@ -50,10 +50,13 @@
* Smooks Transformer.
* <p/>
* This processor hooks the <a href="http://milyn.codehaus.org/Smooks">Milyn Smooks</a>
- * XML Transformation/Processing Engine into a message processing pipeline to support
- * non binary message transformations.
+ * Data Transformation/Processing Engine into a message processing pipeline.
+ *
+ * <p/>
+ * A wide range of source (XML, CSV, EDI etc) and target (XML, Java, CSV, EDI etc) formats
+ * are supported.
*
- * <h3>Action Transformation Configuration</h3>
+ * <h3>Transformation Configuration</h3>
* This action works in one of 2 ways:
* <ol>
* <li>Out of a Smooks resource configuration whose URL is specified directly on the action via the
@@ -83,25 +86,7 @@
* </action>
* </pre>
*
- * <h3>Configuartion Loading & Administration Console Integration</h3>
- * This class picks up its list of transformation resource configurations from a list file
- * specified in the "configuration.list.file.uri" parameter of the "transformation"
- * section of the ESB configuration file. This configuration
- * should specify a URI to this list file and is loaded using the {@link URIResourceLocator}.
- * The default list file is "classpath:/smooks-cdr.lst" (note classpath based URIs are supported).
- * <p/>
- * This file contains a list of URIs that reference
- * <a href="http://milyn.codehaus.org/Smooks">Smooks</a> resource configurations files.
- * Again, {@link URIResourceLocator} is used to load these configurations. "classpath:/"
- * is the default if no scheme is specified. This is also where the Administration Console
- * is integrated with this class. The list file needs to specify the following a HTTP based
- * URI for accessing the configurations under management by the Administration console:
- * <pre>
- * http://localhost:8080/jboss-esb-console/transform/smooks-config.jsp
- * </pre>
- * ... where the host and port values need to be modified appropriately.
- *
- * <h3>Action Transformation Input/Output Configuration</h3>
+ * <h3>Transformation Input/Output Configuration</h3>
* This action gets the transformation input, and sets the transformation output
* based on the "input-location" and "output-location" configuration properties.
* These properties name the {@link Body Message.Body} location where the transformation input
@@ -113,13 +98,23 @@
* {@link Body Message.Body} location named "{@link Body#DEFAULT_LOCATION defaultEntry}". If the "output-location"
* is not configured on the action, the action will set the transformation result/output
* in the {@link Body Message.Body} location named "{@link Body#DEFAULT_LOCATION defaultEntry}".
+ *
+ * <h3>Java Transformation Input/Output Configuration</h3>
+ * This action supports source (XML, CSV, EDI etc) to Java object transformation/binding. See the
+ * "Transform_*" quickstarts for examples of this and also check out the
+ * <a href="http://milyn.codehaus.org/Tutorials">Smooks Tutorials</a>.
* <p/>
- * From a Java code perspective, setting and getting on the "{@link Body#DEFAULT_LOCATION defaultEntry}"
- * is done simply by calling the no-name-arg {@link Body#add(Object)} and {@link Body#get()} methods.
+ * The constructed Java object model can be used as part of a
+ * <a href="http://milyn.codehaus.org/Model+Driven+Transformation">model driven transform</a>, or can
+ * simply be used by other ESB action instances that follow the SmooksTransformer in an action
+ * pipeline.
* <p/>
- * Smooks transforms may also be designed to populate Java objects from the input message (bind to
- * java objects). These Java objects are bound (a {@link Map}) to the message under the key
- * "<<i>output-location</i>><b>-java</b>".
+ * Such Java object graphs are available to subsequent pipeline action instances because they are
+ * attached to the ESB Message output by this action and input to the following action(s). They are bound
+ * to the Message instance Body
+ * ({@link Body#add(String, Object) Message.getBody().add(String key, Object object)}) under a key based
+ * directly on the objects "beanId"
+ * <a href="http://milyn.codehaus.org/javadoc/smooks-cartridges/javabean/org/milyn/javabean/BeanPopulator.html">as defined in the Smooks Javabean config</a>.
*
* @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
* @since Version 4.0
@@ -134,9 +129,15 @@
/**
* Key for storing/accessing any potential message Body bean HashMaps as populated
* by the Smooks Javabean Cartridge.
+ * @deprecated The Smooks {@link org.milyn.container.ExecutionContext} is
+ * attached to the message and can be accessed through the {@link }
*/
public static final String EXTRACTED_BEANS_HASH = "EXTRACTED_BEANS_HASH";
/**
+ * Key for access the Smooks Execution context on the ESB message.
+ */
+ public static final String EXEC_CONTEXT_KEY = ExecutionContext.class.getName();
+ /**
* Action config Smooks configuration key.
*/
public static final String RESOURCE_CONFIG = "resource-config";
@@ -148,6 +149,11 @@
* Config key for the message body location on which the output message is attached.
*/
public static final String OUTPUT_LOCATION = "output-location";
+ /**
+ * Config key for the name of the Smooks Execution context object to be
+ * output to the "output-location".
+ */
+ public static final String JAVA_OUTPUT = "java-output-location";
public static final String FROM = "from";
public static final String FROM_TYPE = "from-type";
@@ -155,11 +161,15 @@
public static final String TO_TYPE = "to-type";
public static final String SMOOKS_CDRL_FILE="smooks-cdrl-file";
public static final String UPDATE_TOPIC="update-topic";
-
+
+ private static final String BEANS_SPEC = "beans:";
+ private static final String BEANS_SPEC_ALL = BEANS_SPEC + "*";
+
private static Logger logger = Logger.getLogger(SmooksTransformer.class);
private SmooksInstanceManager smooksInstanceManager;
private String inputLocation;
private String outputLocation;
+ private String javaOutputLocation;
private String defaultMessageFromType;
private String defaultMessageFrom;
private String defaultMessageToType;
@@ -179,6 +189,10 @@
inputLocation = KeyValuePair.getValue(INPUT_LOCATION, properties, Body.DEFAULT_LOCATION);
// if no output location given, then assume default location in message body.
outputLocation = KeyValuePair.getValue(OUTPUT_LOCATION, properties, Body.DEFAULT_LOCATION);
+ javaOutputLocation = KeyValuePair.getValue(JAVA_OUTPUT, properties);
+ if(javaOutputLocation != null) {
+ javaOutputLocation = javaOutputLocation.trim();
+ }
// Get the default message flow properties (can be overriden by the message properties)...
defaultMessageFromType = KeyValuePair.getValue(FROM_TYPE, properties);
@@ -302,16 +316,13 @@
}
transformedMessage = SmooksUtil.filterAndSerialize(executionContext, new ByteArrayInputStream( messageBytes), smooks);
- // Javabean cartridge resources may have extract data from the message and populated some beans.
- // Get them and stick them on the message - so they can be accessed by downstream actions...
- HashMap beanHash = BeanAccessor.getBeans(executionContext);
+ HashMap beanHash = BeanAccessor.getBeans(executionContext); // Backward compatibility.
if(beanHash != null) {
message.getBody().add(EXTRACTED_BEANS_HASH, beanHash); // Backward compatibility.
- message.getBody().add(outputLocation + "-java", beanHash);
} else {
message.getBody().remove(EXTRACTED_BEANS_HASH); // Backward compatibility.
- message.getBody().remove(outputLocation + "-java");
}
+ message.getBody().add(EXEC_CONTEXT_KEY, executionContext);
if(logger.isDebugEnabled()) {
long timeTaken = System.currentTimeMillis() - start;
@@ -319,8 +330,7 @@
+ timeTaken + ". Message in:\n[" + payload.toString()+ "]. \nMessage out:\n[" + transformedMessage + "].");
}
- message.getBody().add(ActionUtils.POST_ACTION_DATA, transformedMessage);
- message.getBody().add(outputLocation, transformedMessage);
+ setTransformationOutput(message, transformedMessage, executionContext);
} else {
logger.warn("Only java.lang.String payload types supported. Input message was of type [" + payload.getClass().getName() + "]. Returning message untransformed.");
}
@@ -344,7 +354,82 @@
return message;
}
+ private void setTransformationOutput(Message message, String transformedMessage, StandaloneExecutionContext executionContext) {
+ // Set the transformation text output...
+ setTransformedMessageAsOutput(message, transformedMessage);
+
+ // Set the transformation Java output. Will be the individual
+ // java objects directly on the message and (optionally) the map itself...
+ Map beanMap = BeanAccessor.getBeans(executionContext);
+ if(beanMap != null) {
+ Iterator<Map.Entry> beans = beanMap.entrySet().iterator();
+ while (beans.hasNext()) {
+ Map.Entry entry = beans.next();
+ String key = (String) entry.getKey();
+
+ if(message.getBody().get(key) != null) {
+ logger.debug("Outputting Java object to '" + key + "'. Overwritting existing value.");
+ }
+ message.getBody().add(key, entry.getValue());
+ }
+ }
+
+ // Now the map itself, if configured for output....
+ if(javaOutputLocation != null) {
+ if(beanMap != null) {
+ String location = javaOutputLocation;
+ if(location.equals("$default")) {
+ location = Body.DEFAULT_LOCATION;
+ }
+ if(message.getBody().get(location) != null) {
+ logger.debug("Outputting Java object Map to '" + location + "'. Overwritting existing value.");
+ }
+ message.getBody().add(location, beanMap);
+ } else {
+ logger.debug("Transformation Javabean spec '" + javaOutputLocation + "' doesn't evaluate to any bean map for the current message.");
+ }
+ }
+ }
+
+ private void setTransformedMessageAsOutput(Message message, String transformedMessage) {
+ message.getBody().add(ActionUtils.POST_ACTION_DATA, transformedMessage);
+ message.getBody().add(outputLocation, transformedMessage);
+ }
+
/**
+ * Get the named bean from the specified message.
+ * <p/>
+ * The bean would have been populated by an earlier execution of the SmooksTransformer.
+ *
+ * @param name The bean name.
+ * @param message The message;
+ * @return The bean, or null if no such bean exists.
+ */
+ public static Object getBean(String name, Message message) {
+ AssertArgument.isNotNullAndNotEmpty(name, "name");
+ AssertArgument.isNotNull(message, "message");
+
+ ExecutionContext context = getExecutionContext(message);
+ if(context != null) {
+ return BeanAccessor.getBean(name, context);
+ } else {
+ logger.warn("Cannot access bean '" + name + "'. No Smooks execution context bound to message.");
+ return null;
+ }
+ }
+
+ /**
+ * Get the Smooks context from the specified message.
+ *
+ * @param message The message;
+ * @return The Smooks execution context, or null if no context is bound.
+ */
+ public static ExecutionContext getExecutionContext(Message message) {
+ AssertArgument.isNotNull(message, "message");
+ return (ExecutionContext)message.getBody().get(EXEC_CONTEXT_KEY);
+ }
+
+ /**
* Register the Message Exchange as a profile within Smooks.
* @param message The message.
* @param smooks The Smooks instance.
@@ -423,7 +508,7 @@
return profileArray;
}
- /**
+ /**
* Construct the Smooks profile string based on the supplied message flow properties.
* @param messageFromType The type string for the message source.
* @param messageFrom The EPR string for the message source.
Modified: labs/jbossesb/trunk/product/services/smooks/src/test/java/org/jboss/soa/esb/actions/converters/SmooksTransformerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/smooks/src/test/java/org/jboss/soa/esb/actions/converters/SmooksTransformerUnitTest.java 2007-10-10 07:39:44 UTC (rev 15712)
+++ labs/jbossesb/trunk/product/services/smooks/src/test/java/org/jboss/soa/esb/actions/converters/SmooksTransformerUnitTest.java 2007-10-10 10:18:58 UTC (rev 15713)
@@ -24,6 +24,7 @@
import java.net.URISyntaxException;
+import java.util.Map;
import junit.framework.TestCase;
@@ -82,6 +83,7 @@
Message message;
properties.setAttribute(SmooksTransformer.RESOURCE_CONFIG, "/org/jboss/soa/esb/actions/converters/smooks-conf.xml");
+ properties.setAttribute(SmooksTransformer.JAVA_OUTPUT, "ObjectMap");
transformer = new SmooksTransformer(properties);
transformer.initialise();
@@ -89,9 +91,12 @@
message = MessageFactory.getInstance().getMessage();
message.getBody().add("<x xprop='xval' />");
- assertNull(message.getBody().get(Body.DEFAULT_LOCATION + "-java"));
+ assertNull(message.getBody().get("orderHeader"));
message = transformer.process(message);
- assertNotNull(message.getBody().get(Body.DEFAULT_LOCATION + "-java"));
+ assertNotNull(message.getBody().get("orderHeader"));
+ assertTrue(message.getBody().get("orderHeader") instanceof XClass);
+ assertNotNull(message.getBody().get("ObjectMap"));
+ assertTrue(message.getBody().get("ObjectMap") instanceof Map);
}
private String transform(String stringMessage, String fromType, String from, String to, String toType) throws ActionProcessingException, ConfigurationException, URISyntaxException, ActionLifecycleException {
@@ -103,7 +108,6 @@
// Perform the transformation by setting the payload on the task object...
message = MessageFactory.getInstance().getMessage();
- message = MessageFactory.getInstance().getMessage();
message.getBody().add(ActionUtils.POST_ACTION_DATA, stringMessage);
message = transformer.process(message);
String resultThroughTaskObj = (String) message.getBody().get(ActionUtils.POST_ACTION_DATA);
More information about the jboss-svn-commits
mailing list