2
votes

I am trying to split a '@' separated string and process every token through same route.

camel-context.xml:

<split streaming="true">
  <tokenize token="@"/>
  <to uri="validateResubmitTransactionIdProcessor"/>
</split>

Following is processor code snippet:

epublic class ValidateResubmitTransactionIdProcessor implements Processor {
public void process(Exchange exchng) throws Exception {
    Object[] args =  exchng.getIn().getBody(Object[].class);
}}

I get following exception:

eCaused by: org.apache.camel.InvalidPayloadException: No body available of type: org.apache.camel.Exchange but has value: 11484 of type: java.lang.String on: Message: 11484. Caused by: No type converter available to convert from type: java.lang.String to the required type: org.apache.camel.Exchange with value 11484. Exchange[Message: 11484]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: java.lang.String to the required type: org.apache.camel.Exchange with value 11484] at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:101) at org.apache.camel.builder.ExpressionBuilder$35.evaluate(ExpressionBuilder.java:847) Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: java.lang.String to the required type: org.apache.camel.Exchange with value 11484 at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:169) at org.apache.camel.core.osgi.OsgiTypeConverter.mandatoryConvertTo(OsgiTypeConverter.java:110) at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:99)nter

I am not sure if I am using splitter the right way. Also, do know how can I convert java.lang.String to Exchange. This doesn't seems to be supported by camel.

1

1 Answers

2
votes

The Splitter EIP creates a kind of loop and your processer gets called for every token. The body of the exchange thus contains a simple String, not a list.

UPDATE: See this example:

    CamelContext context = new DefaultCamelContext();
    context.addRoutes(new RouteBuilder() {
        public void configure() {
            from("direct:start")
            .split().tokenize("@").streaming()
            .process(new MyProcessor())
            ;
        }
    });
    context.start();
    context.createProducerTemplate().sendBody("direct:start", "1@2@3");

Your Processor method can look like this:

public void process(final Exchange exchange) throws Exception
{
    System.out.println(exchange.getIn().getBody());
}

This will output three lines with the digits.