Java Reference
In-Depth Information
Modifying a Message's Payload
The configuration of a transformer component is very much in keeping with everything you've
seen so far:
package com.apress.springenterpriserecipes.springintegration;
import org.springframework.integration.annotation.Transformer;
import org.springframework.integration.core.Message;
import java.util.Map;
public class InboundJMSMessageToCustomerTransformer {
@Transformer
public Customer transformJMSMapToCustomer(
Message<Map<String, Object>> inboundSpringIntegrationMessage) {
Map<String, Object> jmsMessagePayload =
inboundSpringIntegrationMessage.getPayload();
Customer customer = new Customer();
customer.setFirstName((String) jmsMessagePayload.get("firstName"));
customer.setLastName((String) jmsMessagePayload.get("lastName"));
customer.setId((Long) jmsMessagePayload.get("id"));
return customer;
}
}
Nothing terribly complex happening here: a Message of type Map<String,Object> is passed in. The
values are manually extracted and used to build an object of type Customer . The Customer object is
returned, which has the effect of passing it out on the reply channel for this component. The next
component in the configuration will receive this object as its input Message .
The solution is mostly the same as you've seen, but there is a new transformer element:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans=" http://www.springframework.org/schema/beans"
>
<context:annotation-config/>
<beans:bean id="connectionFactory"
class="org.springframework.jms.connection.CachingConnectionFactory">
<beans:property name="targetConnectionFactory">
<beans:bean class="org.apache.activemq.ActiveMQConnectionFactory">
<beans:property name="brokerURL" value=" tcp://localhost:8753"/>
</beans:bean>
</beans:property>
<beans:property name="sessionCacheSize" value="10"/>
<beans:property name="cacheProducers" value="false"/>
</beans:bean>
<beans:bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<beans:property name="connectionFactory" ref="connectionFactory"/>
</beans:bean>
Search WWH ::




Custom Search