Reputation:
I'm trying to use the payload-type-router in xml based config of a legacy app and the application neither route to the specific channel nor throw any error at that instance. can we route the message of type List<?> using payload-type-router using XML configuration. I have n't found much examples in the doc as it only mentions routing using Integer, String classes but not with List.
<int:payload-type-router input-channel="run-router-channel">
<int:mapping type="com.foo.req.BlRunnerRequest" channel="runner-channel"/>
<int:mapping type="java.util.List" channel="run-channel"/> <!-- can spring integration support this approach-->
</int:payload-type-router>
Thanks in advance. What could be the alternatives for this kind of routing in XML ?
Upvotes: 0
Views: 362
Reputation: 121442
Yes. We can. I have just modified the unit test in the project to this:
<payload-type-router id="router" input-channel="routingChannel">
<mapping type="java.lang.String" channel="channel1" />
<mapping type="java.lang.Integer" channel="channel2" />
<mapping type="java.lang.Number[]" channel="channel3" />
<mapping type="java.lang.Long[]" channel="channel4" />
<mapping type="java.util.List" channel="channel5" />
</payload-type-router>
The I do this in the test method:
testService.foo(new GenericMessage<>(new ArrayList()));
PollableChannel channel5 = (PollableChannel) context.getBean("channel5");
assertThat(channel5.receive(100).getPayload()).isInstanceOf(List.class);
Probably something else is going on in your case and that request payload is really not a java.util.List
.
Also router has this logic when it cannot deliver the message to some channel:
if (!sent) {
getDefaultOutputChannel();
if (this.defaultOutputChannel != null) {
this.messagingTemplate.send(this.defaultOutputChannel, message);
}
else {
throw new MessageDeliveryException(message, "No channel resolved by router '" + this
+ "' and no 'defaultOutputChannel' defined.");
}
}
Since I don't see a defaultOutputChannel
configuration from your code snippet, that only means a MessageDeliveryException
is thrown. If you don't see it in your case, then you swallow it somehow.
Upvotes: 1