1
votes

I have a Mule flow, with a custom interceptor, which constructs an Object and forwards it to a JMS outboud endpoint. The JMS endpoint throws an exception trying to convert the Object to a JMS StreamMessage. What I want is for the endpoint to convert the Object to a JMS ObjectMessage, instead. How would that be done?

here's my flow;

<spring:beans>
    <spring:bean id="connectionFactoryFactory" name="connectionFactoryFactory"
        class="ConnectionFactoryFactory">
        <spring:property name="properties">
            <spring:props>
                <spring:prop key="imqAddressList">mqtcp://localhost:30001/jms</spring:prop>
                <spring:prop key="imqReconnectAttempts">-1</spring:prop>
            </spring:props>
        </spring:property>
    </spring:bean>

    <spring:bean id="connectionFactory" name="connectionFactory"
        factory-bean="connectionFactoryFactory" factory-method="createConnectionFactory" />
</spring:beans>

<jms:connector name="JMSConnector" connectionFactory-ref="connectionFactory"
    specification="1.1" doc:name="JMS" />

<flow name="Request" doc:name="Request">
    <quartz:inbound-endpoint responseTimeout="10000"
        doc:name="InfoRequest" jobName="InfoRequest" repeatInterval="5000">
        <quartz:event-generator-job />
    </quartz:inbound-endpoint>
    <custom-interceptor class="StateRequest"/>
    <jms:outbound-endpoint connector-ref="JMSConnector"
        doc:name="JMS" topic="requests"/>
</flow>

I have also tried adding an Object to JMS Message Transformer;

<jms:object-to-jmsmessage-transformer returnClass="javax.jms.ObjectMessage" name="Object_to_JmsMessage" doc:name="Object to JmsMessage"/>

    <jms:outbound-endpoint connector-ref="JMSConnector"
        doc:name="JMS" topic="requests" transformer-refs="Object_to_JmsMessage"/>
1
Why using an interceptor? Do you want to potentially stop the flow from keeping its execution?David Dossot
Also what is the type returned by the interceptor? Does it implement Serializable?David Dossot
Yes, there are times when I don't need to request the additional information. The interceptor creates an object of Request implements Serializable. I have serialized the object and sent the bytes, which I presume created a BytesMessage, but the server implementer tells me his code will accept only an ObjectMessage.CAB
The server implementer sucks :) ObjectMessages rely on Java Serialization and thus are tightly coupling, something you do not want in a messaging environment. According to the source code, if the Mule Message payload is a Serializable (and not a List nor a String), Mule will automatically create an ObjectMessage without the need to configure any transformer manually...David Dossot
Totally! Look no further: this class is a List so Mule serializes it as a StreamMessage. Unfortunately this behavior is in a static class so it's hard to swap with another one. Either create your own JMS ObjectMessage from code or subclass AbstractJmsTransformer to create your own flavor of ObjectToJMSMessage that would call JmsMessageUtils.serializableToMessage for payloads of type Request.David Dossot

1 Answers

0
votes

Because Request extends LinkedList<RequestId> implements Serializable, Mule will automatically convert this type to a StreamMessage.

Unfortunately this behavior is in a static class so it's hard to swap with another one. Either create your own JMS ObjectMessage from code or subclass AbstractJmsTransformer to create your own flavor of ObjectToJMSMessage that would call JmsMessageUtils.serializableToMessage for payloads of type Request.