camunda-community-hub / camunda-platform-7-camel

Community Extension to add Apache Camel support for Camunda Platform 7
Apache License 2.0
82 stars 57 forks source link

'sendTo' throws IllegalArgumentException #36

Closed stephanpelikan closed 6 years ago

stephanpelikan commented 6 years ago

Given: A task which uses 'sendTo' to call a certain Camel route. The response is stored into a process variable 'incrementalFilename'. If the Camel route could not find this incremental file, the out body of the route is null and therefore the newly created process variable stores null as its value. Afterwards another task of the same process uses 'sendTo' to call another Camel route. This task wants to receive all process variables by using the syntax ${camel.sendTo('direct:myRoute')}.

In this situation an exception with this cause is thrown:

Caused by: java.lang.IllegalArgumentException: Process variable 'incrementalFilename' no found!
        at org.camunda.bpm.camel.common.CamelServiceCommonImpl.sendToInternal(CamelServiceCommonImpl.java:66)
        at org.camunda.bpm.camel.common.CamelServiceCommonImpl.sendTo(CamelServiceCommonImpl.java:55)
        at org.camunda.bpm.camel.common.CamelServiceCommonImpl.sendTo(CamelServiceCommonImpl.java:34)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_144]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_144]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_144]
        at java.lang.reflect.Method.invoke(Method.java:498) [rt.jar:1.8.0_144]
        at org.camunda.bpm.engine.impl.javax.el.BeanELResolver.invoke(BeanELResolver.java:479) [camunda-engine-7.6.3-ee.jar:7.6.3-ee]
        ... 163 more

What happens? If one requires to get all process variables then simply the sentTo is transformed into the same mode if a list of the current process variables was given as the second parameter. In this mode every process variable is mandetory and therefore the given exception is thrown.

Possible solution: Treat the situtation "all process variables" in another way and suppress those expection because it might be OK for a process variable to store a null value.

To be discussed: Create a possiblity to also get named process variables even if they are null because the Camel route deals this.

stephanpelikan commented 6 years ago

The pull request contains the feature to declare process variables as optional using the question mark as a postfix. e.g. 'mayBeNullVar?,mustNotBeNullVar'