I have an inbound org.mule.api.MuleMessage with a huge payload. Payload needs to be split based on some logic. With split payloads I'm forming list of org.mule.api.MuleMessage, where in each message has same headers but different payload. I need to send each message from the list as a separate message in outbound queue.
I am using <collection-splitter>, but it gives me following error :
org.mule.api.transformer.TransformerMessagingException: Invalid type passed to StreamMessage: DefaultMuleMessage . Allowed types are: Boolean Byte Short Character Integer Long Float DoubleString and byte[] (javax.jms.MessageFormatException) (org.mule.api.transformer.TransformerException). Message payload is of type: ArrayList
I'm using following configuration :
<flow name="Inbound flow">
<inbound-endpoint ref="In" />
<pooled-component>
<spring-object bean="inboundAdapterProcessor" />
<pooling-profile initialisationPolicy="INITIALISE_ALL" maxActive="${component.maxActive}" />
</pooled-component>
<collection-splitter enableCorrelation="IF_NOT_SET" />
<outbound-endpoint ref="Out"/>
</flow>
"In" and "Out" are nothing but jms queue endpoints.
Java Code :
public Object onCall(MuleEventContext eventContext) throws Exception {
List<MuleMessage> messages = new ArrayList<MuleMessage>();
MuleMessage message = eventContext.getMessage();
String payload = message.getPayloadAsString();
//split the payload based on some logic
String[] payloads = getSplitPayload(payload);
int i= 0;
while(i<payloads.lenght){
//create DefaultMuleMessage here
MuleMessage splitMessage = new DefaultMuleMessage(/*passing appropriate params here*/);
//set the same headers
//set the payload
splitMessage.setPaylod(payloads[i]);
messages.add(splitMessage);
}
return messages;
}
Kindly advise. Your help is much appreciated.Thanks in advance.