[
https://issues.apache.org/jira/browse/CAMEL-6481?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13692806#comment-13692806
]
Antoine DESSAIGNE commented on CAMEL-6481:
------------------------------------------
Hi,
I don't agree that it's not a bug. The following code won't work:
{noformat}
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").choice()
.when(simple("${body.length} == 2")).to("mock:processWith2")
.when(simple("${body.length} == 3")).to("mock:processWith3");
}
});
context.start();
context.createProducerTemplate().send("direct:start", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(new String[] {"First value", "Second value"});
}
});
{noformat}
According to the [simple documentation|http://camel.apache.org/simple.html],
$\{body.length} should use an OGNL expression after the dot. In the [OGNL
documentation|http://commons.apache.org/proper/commons-ognl/language-guide.html#Referring_to_Properties]
it's documented as a valid use case and should work.
But maybe there's something I didn't understood. Can you help me out ?
> Can't access to length of Array (java) from simple language
> -----------------------------------------------------------
>
> Key: CAMEL-6481
> URL: https://issues.apache.org/jira/browse/CAMEL-6481
> Project: Camel
> Issue Type: Improvement
> Components: camel-core
> Affects Versions: 2.11.0
> Reporter: Jérôme Decq
> Assignee: Claus Ibsen
> Priority: Minor
>
> Cannot evaluate length on java.lang.String[] in simple
> I suspect this is because this is part of the language itself. But still, why
> not?
> h3. repro step
> run this:
> {noformat}
> ?xml version="1.0" encoding="UTF-8"?>
> <routes xmlns="http://camel.apache.org/schema/spring" >
> <route>
> <from uri="timer:test?repeatCount=1"/>
> <setBody>
> <groovy>[[2, "Chaine_avec_des_underscores", 12, "c"], ["d4",
> "e5", "f6"]]</groovy>
> </setBody>
> <split>
> <simple>${body}</simple>
> <setHeader headerName="splittedColumn1">
> <simple>${body[1].split("_")}</simple>
> </setHeader>
> <log message="${header.splittedColumn1.length}"/>
> </split>
> </route>
> </routes>
> {noformat}
> errors with:
> {noformat}
> org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to
> invoke method: .length on null due to:
> org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to
> invoke method: length on null due to:
> org.apache.camel.component.bean.MethodNotFoundException: Method with name:
> length not found on bean: [Ljava.lang.String;@33318365 of type:
> [Ljava.lang.String;. Exchange[Message: [d4, e5, f6]]{noformat}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira