[jboss-svn-commits] JBL Code SVN: r17962 - in labs/jbossesb/trunk/product: services/soap/src/main/java/org/jboss/soa/esb/actions/soap and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Jan 18 13:12:15 EST 2008


Author: kevin.conner at jboss.com
Date: 2008-01-18 13:12:15 -0500 (Fri, 18 Jan 2008)
New Revision: 17962

Modified:
   labs/jbossesb/trunk/product/docs/MessageActionGuide.odt
   labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPClient.java
Log:
Add XStream field mappings and annotation support: JBESB-1334

Modified: labs/jbossesb/trunk/product/docs/MessageActionGuide.odt
===================================================================
(Binary files differ)

Modified: labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPClient.java
===================================================================
--- labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPClient.java	2008-01-18 18:11:46 UTC (rev 17961)
+++ labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPClient.java	2008-01-18 18:12:15 UTC (rev 17962)
@@ -40,6 +40,7 @@
 import org.xml.sax.SAXException;
 
 import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.annotations.Annotations;
 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
 import com.thoughtworks.xstream.io.xml.QNameMap;
 import com.thoughtworks.xstream.io.xml.StaxDriver;
@@ -149,7 +150,7 @@
  * Option 2 (above) provides a quick-and-dirty way to populate a SOAP message without having to create an Object
  * model ala Option 1.  The OGNL expressions that correspond with the SOAP operation parameters are exactly the same
  * as for Option 1, except that there's not Object Graph Navigation involved.  The OGNL expression is simply used as
- * the key into the {@link Map}, with the corresponding key-value being the parameter. 
+ * the key into the {@link Map}, with the corresponding key-value being the parameter.
  *
  * <h2>SOAP Response Message Consumption</h2>
  * The SOAP response object instance can be is attached to the ESB {@link Message} instance in one of the
@@ -193,7 +194,18 @@
  * In the above example, we also include an example of how to specify non-default named locations for the request
  * parameters {@link Map} and response object instance.
  * <p/>
- * To have the SOAP reponse data extracted into an OGNL keyed map (Option 2 above) and attached to the ESB
+ * We also provide, in addition to the above <a href="http://xstream.codehaus.org">XStream</a> configuration options,
+ * the ability to specify field name mappings and <a href="http://xstream.codehaus.org">XStream</a> annotated classes.
+ * <pre>
+ *      &lt;property name="responseXStreamConfig"&gt;
+ *          &lt;fieldAlias name="header" class="com.acme.order.Order" fieldName="headerFieldName" /&gt;
+ *          &lt;annotation class="com.acme.order.Order" /&gt;
+ *      &lt;/property&gt;
+ * </pre>
+ * Field mappings can be used to map XML elements onto Java fields on those occasions when the local name of the element
+ * does not correspond to the field name in the Java class.
+ * <p/>
+ * To have the SOAP response data extracted into an OGNL keyed map (Option 2 above) and attached to the ESB
  * {@link Message}, simply replace the "responseXStreamConfig" property with the "responseAsOgnlMap" property
  * having a value of "true" as follows:
  * <pre>
@@ -216,10 +228,10 @@
  * with a Smooks transformation configuration property as follows:
  * <pre>
  *     &lt;property name="smooksTransform" value="/transforms/order-transform.xml" /&gt;</pre>
- * 
+ *
  * The value of the "smooksTransform" property is resolved by first checking it as a filesystem based resource.
- * Failing that, it's checked as a classpath resource and failing that, as a URI based resource. 
- * 
+ * Failing that, it's checked as a classpath resource and failing that, as a URI based resource.
+ *
  * <h3>Specifying a different SOAP schema</h3>
  * <pre>
  *    &lt;property name="SOAPNS" value="http://www.w3.org/2009/09/soap-envelope"/&gt;
@@ -261,12 +273,12 @@
             }
         }
         ConfigTree[] xstreamAliases = config.getChildren("alias");
-        if(xstreamAliases != null && xstreamAliases.length != 0) {
-            configureXStreamDeserializer(xstreamAliases);
-        }
+        ConfigTree[] xstreamFieldAliases = config.getChildren("fieldAlias");
+        ConfigTree[] xstreamAnnotations = config.getChildren("annotation");
+        configureXStreamDeserializer(xstreamAliases, xstreamFieldAliases, xstreamAnnotations);
         soapNs = config.getAttribute("SOAPNS");
 
-        // Extract the HttpClient creation properties from the ConfigTree.  Thesee are passed
+        // Extract the HttpClient creation properties from the ConfigTree.  These are passed
         // to the HttpClientFacatory...
         extractHttpClientProps(config);
         httpclient = HttpClientFactory.createHttpClient(httpClientProps);
@@ -296,7 +308,7 @@
     public void initialise() throws ActionLifecycleException {
         super.initialise();
         // Create the SoapUIInvoker instance for this SOAPClient...
-        soapUIInvoker = new SoapUIInvoker();        
+        soapUIInvoker = new SoapUIInvoker();
     }
     
     @Override
@@ -358,7 +370,7 @@
 
         return message;
     }
-    
+
     public String getSoapNS()
 	{
 		return soapNs;
@@ -460,7 +472,7 @@
 
         return map;
     }
-
+    
     private void populateResponseOgnlMap(Map<String, String> map, Element element) {
         NodeList children = element.getChildNodes();
         int childCount = children.getLength();
@@ -509,7 +521,7 @@
 
     private static DocumentBuilderFactory createDocumentBuilderFactory() {
         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-        
+
         factory.setNamespaceAware(true);
         factory.setExpandEntityReferences(true);
 
@@ -520,7 +532,7 @@
         return docBuilderFactory.newDocumentBuilder();
     }
 
-    private void configureXStreamDeserializer(ConfigTree[] xstreamAliases) throws ConfigurationException {
+    private void configureXStreamDeserializer(ConfigTree[] xstreamAliases, ConfigTree[] xstreamFieldAliases, ConfigTree[] xstreamAnnotations) throws ConfigurationException {
         responseXStreamDeserialzer = new XStream();
         for(ConfigTree xstreamAlias : xstreamAliases) {
             String aliasName = xstreamAlias.getRequiredAttribute("name");
@@ -534,5 +546,25 @@
                 throw new ConfigurationException("Invalid SOAP response deserializer config. XStream alias type '" + aliasTypeName + "' not found.");
             }
         }
+        for(ConfigTree xstreamFieldAlias : xstreamFieldAliases) {
+            final String alias = xstreamFieldAlias.getRequiredAttribute("name");
+            final String typeName = xstreamFieldAlias.getRequiredAttribute("class");
+            final String fieldName = xstreamFieldAlias.getRequiredAttribute("fieldName");
+            try {
+                final Class type = ClassUtil.forName(typeName, getClass());
+                responseXStreamDeserialzer.aliasField(alias, type, fieldName);
+            } catch (final ClassNotFoundException cnfe) {
+                throw new ConfigurationException("Invalid SOAP response deserializer config. XStream alias type '" + typeName + "' not found.");
+            }
+        }
+        for(ConfigTree xstreamAnnotation : xstreamAnnotations) {
+            final String typeName = xstreamAnnotation.getRequiredAttribute("class");
+            try {
+                final Class type = ClassUtil.forName(typeName, getClass());
+                Annotations.configureAliases(responseXStreamDeserialzer, type) ;
+            } catch (final ClassNotFoundException cnfe) {
+                throw new ConfigurationException("Invalid SOAP response deserializer config. XStream alias type '" + typeName + "' not found.");
+            }
+        }
     }
 }




More information about the jboss-svn-commits mailing list