[jboss-svn-commits] JBL Code SVN: r17961 - in labs/jbossesb/branches/JBESB_4_2_1_GA_CP/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:11:46 EST 2008
Author: kevin.conner at jboss.com
Date: 2008-01-18 13:11:46 -0500 (Fri, 18 Jan 2008)
New Revision: 17961
Modified:
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/docs/MessageActionGuide.odt
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/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/branches/JBESB_4_2_1_GA_CP/product/docs/MessageActionGuide.odt
===================================================================
(Binary files differ)
Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPClient.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPClient.java 2008-01-18 17:43:18 UTC (rev 17960)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPClient.java 2008-01-18 18:11:46 UTC (rev 17961)
@@ -62,6 +62,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;
@@ -215,7 +216,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>
+ * <property name="responseXStreamConfig">
+ * <fieldAlias name="header" class="com.acme.order.Order" fieldName="headerFieldName" />
+ * <annotation class="com.acme.order.Order" />
+ * </property>
+ * </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>
@@ -283,12 +295,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);
@@ -547,7 +559,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");
@@ -561,5 +573,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