I maybe doing something wrong here but i don't seem to be getting the expected result when using the split().method combination. The incoming xml varies slightly between incoming messages and the elementKey node within it describes what the XML node within in it we are looking for.
from("direct:fromWhereEver")
...
.setHeader("dynamicToken", xpath("//*[local-name()='elementKey']/text()").stringResult())
...
.split().method(DynamicSplitToken.class, "extractTokens")
.to("direct:outgoing")
.routeId("BhahBlah")
I have the following defined in a method for use by the route
public class DynamicSplitToken {
public static Expression extractTokens(Exchange exchange){
String splitToken = exchange.getIn().getHeader("dynamicToken").toString();
TokenizeLanguage tok = new TokenizeLanguage();
tok.setXml(true);
tok.setIncludeTokens(true);
tok.setToken(splitToken);
return tok.createExpression();
}
}
Now the xml tags are pulled from the message no problem, BUT the resultant "body" that is extracted and pushed through contains <tagname>...</tagname>
that matches the elementKey above with no child nodes/elements in between. I would expect to receive everything between the tags as well, similar to if i used the following
.split().tokenizeXML("tagname")
When using this method i get the full content of tags and all nodes between the tags, unforunately i can't pass a {header.dynaimcToken} to the tokenizeXML ProcessorDefinition otherwise i wouldn't need to ask for help here.
Where have i gone wrong here, i know im missing an important step after the method processor, but unsure what
For now we are stuck with camel 2.9 (fuse-esb) if that makes a difference
Cheers Mark
method()
must not return an Expresssion
but something that is iterable such as java.util.List
, see here. Your original solution was quite close, but you have to evaluate
the expression and return its result such as:
protected static class DynamicSplitToken {
@SuppressWarnings("unchecked")
public static List<String> extractTokens(final Exchange exchange) {
final String splitToken = exchange.getIn().getHeader("dynamicToken").toString();
final TokenizeLanguage tok = new TokenizeLanguage();
tok.setXml(true);
tok.setIncludeTokens(true);
tok.setToken(splitToken);
final Expression expression = tok.createExpression();
return expression.evaluate(exchange, List.class);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With