Ce contenu n'est pas disponible dans la langue sélectionnée.
10.4. Chaining Transformers
JBoss Fuse Service Works 6.0 allows you to chain transformers. Say you have a transformer that transforms from A to B and another that transforms from B to C. If you then have an invocation where the consumer is using type A and the provider is using type C, then the runtime will invoke the A->B and the B->C transformers to achieve A->C.
For example, for a SOAP message, you could define two transformers:
<transform:transform.java from="{http://web.service.com/}GetStatisticsResponse" to="{urn:web.service.com}StatisticsCData" bean="CDataReturn"/> <transform:transform.jaxb from="{urn:web.service.com}StatisticsCData" to="java:com.sample.model.Statistics" contextPath="com.sample.model"/>
The first transformer transforms the SOAP reply which contains the
GetStatisticsResponse
element into an intermediate object which is just the content of the return element (CDATA containing the element), implemented in Java as follows:
@Named("CDataReturn") public class CDataExtractor { @Transformer(from = "{http://web.service.com/}GetStatisticsResponse", to = "{urn:web.service.com}StatisticsCData") public String transform(Element from) { String value = null; NodeList nodes = from.getElementsByTagName("return"); if(nodes.getLength() > 0 ){ value = nodes.item(0).getChildNodes().item(0).getNodeValue(); } return value; } }
The second transformer then takes care of transforming from the element to the Statistics Java model using JAXB.
JBoss Fuse Service Works 6.0 knows, from the contracts on the reference definitions, that it needs to go from
{http://web.service.com/}GetStatisticsResponse
to java:com.sample.model.Statistics
and will automatically invoke both transformers to make that happen.
See Unable to transform from SOAP response with CDATA block to a POJO in FSW 6 for more information.