1
votes

Issue: message-converter on JMS outbound-channel-adapter is sending the object I unMarshall as bytes instead of JMS TextMessage. Is it possible to set the message-converter to explicitly tell it to send as JMS TextMessage and not bytes? I thought of putting a transformer step in-between the splitter and outbound that will just return a string but seems inefficient.

Reference Documentation: JMS Support

Code:

<?xml version="1.0" encoding="UTF-8"?>
<beans 
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:int="http://www.springframework.org/schema/integration"
    xmlns:jms="http://www.springframework.org/schema/integration/jms"
    xmlns:stream="http://www.springframework.org/schema/integration/stream"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:oxm="http://www.springframework.org/schema/oxm"
    xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/integration
            http://www.springframework.org/schema/integration/spring-integration.xsd
            http://www.springframework.org/schema/integration/jms
            http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
            http://www.springframework.org/schema/integration/stream
            http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/jee
            http://www.springframework.org/schema/jee/spring-jee.xsd
            http://www.springframework.org/schema/oxm
            http://www.springframework.org/schema/oxm/spring-oxm.xsd">


        <int:chain id="fooChain" input-channel="requestChannel">    

            <!-- Performs processing action - Returns List<Foo> objects -->
            <int:service-activator ref="fooListener" method="processFoo"/>

            <int:splitter />

            <!-- Covert messages and send to mq queue -->       
            <jms:outbound-channel-adapter 
                id="fooRequestsChannel"
                destination="externalAppRequestQueue"
                message-converter="fooMessageConverter">
            </jms:outbound-channel-adapter>

        </int:chain> 


        <bean id="oxmFooMessageConverter" class="org.springframework.jms.support.converter.MarshallingMessageConverter">
              <property name="marshaller" ref="fooMarshaller" />
              <property name="unmarshaller" ref="fooMarshaller" />
               <!-- SOLUTION ADDED HERE: START --> 
              <property name="targetType" value="TEXT"/>
               <!-- SOLUTION ADDED HERE: END-->
        </bean>


         <oxm:jaxb2-marshaller id="fooMarshaller">  
            <oxm:class-to-be-bound name="com.test.foo" />
         </oxm:jaxb2-marshaller>

    </beans>

Solution:

Add the following property to oxmFooMessageConverter above. The JMS message will be sent as TEXT string to the queue and not bytes. Above example updated.

<property name="targetType" value="TEXT"/>
1

1 Answers

0
votes

M-m-m. What is the question? You did that already: message-converter="fooMessageConverter".

What is a problem do you have ?

The MarshallingMessageConverter has an option if you want String:

/**
 * Specify whether {@link #toMessage(Object, Session)} should marshal to
 * a {@link BytesMessage} or a {@link TextMessage}.
 * <p>The default is {@link MessageType#BYTES}, i.e. this converter marshals
 * to a {@link BytesMessage}. Note that the default version of this converter
 * supports {@link MessageType#BYTES} and {@link MessageType#TEXT} only.
 * @see MessageType#BYTES
 * @see MessageType#TEXT
 */
public void setTargetType(MessageType targetType) {
    Assert.notNull(targetType, "MessageType must not be null");
    this.targetType = targetType;
}