You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Carl van Denzen <ca...@vandenzen.nl> on 2021/04/20 21:43:51 UTC

Camel 3.9.0 Groovy CamelLoopIndex

Hi,

It looks like something has changed between Camel 3.8.0 and 3.9.0 with 
Groovy or CamelLoopIndex.

Up to and including Camel 3.8.0 my route succesfully runs the loop.

In Camel 3.9.0 the loop fails. A wild guess is that something changed in 
accessing exchange.properties.CamelLoopIndex.

Does anyone know how to solve this?

Steps to reproduce:

Start Karaf V4.3.1

repo-add camel 3.9.0

feature:install camel

feature:install camel-groovy

Then copy the blueprint.xml to the Karaf deploy directory and look at 
the Karaf log (log:display or log:tail).

Excerpt of logging:

23:37:49.260 INFO [Camel (simple) thread #1 - timer://inittimer] 
getOHItems body=
23:37:49.262 INFO [Camel (simple) thread #1 - timer://inittimer] 
getOHItems OHItems=[Ljava.lang.String;@53870163
23:37:49.310 INFO [Camel (simple) thread #1 - timer://inittimer] 
getOHItems: OHItemsResult=[Ljava.lang.String;@53870163
23:37:49.321 INFO [Camel (simple) thread #1 - timer://inittimer] 
getOHItems: OHItemsResultlength=4
23:37:49.419 ERROR [Camel (simple) thread #1 - timer://inittimer] Failed 
delivery for (MessageId: EA6BC0C06725249-0000000000000002 on ExchangeId: 
EA6BC0C06725249-0000000000000002). Exhausted after delivery attempt: 1 
caught: groovy.lang.GroovyRuntimeException: Ambiguous method overloading 
for method [Ljava.lang.String;#getAt.
Cannot resolve which method to invoke for [null] due to overlapping 
prototypes between:
         [interface groovy.lang.Range]
         [interface java.util.Collection]

Message History (complete message history is disabled)
---------------------------------------------------------------------------------------------------------------------------------------
RouteId              ProcessorId Processor Elapsed (ms)
[start1            ] [start1            ] 
[from[timer://inittimer?repeatCount=1] ] [       811]
         ...
[getOHItems        ] [setHeader2        ] [setHeader[OHItem] ] [         0]

Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------

groovy.lang.GroovyRuntimeException: Ambiguous method overloading for 
method [Ljava.lang.String;#getAt.
Cannot resolve which method to invoke for [null] due to overlapping 
prototypes between:
         [interface groovy.lang.Range]
         [interface java.util.Collection]
         at 
groovy.lang.MetaClassImpl.doChooseMostSpecificParams(MetaClassImpl.java:3338) 
~[!/:3.0.3]
         at 
groovy.lang.MetaClassImpl.chooseMostSpecificParams(MetaClassImpl.java:3314) 
~[!/:3.0.3]
         at 
groovy.lang.MetaClassImpl.chooseMethodInternal(MetaClassImpl.java:3304) 
~[!/:3.0.3]
         at 
groovy.lang.MetaClassImpl.chooseMethod(MetaClassImpl.java:3248) ~[!/:3.0.3]
         at 
groovy.lang.MetaClassImpl.getMethodWithCachingInternal(MetaClassImpl.java:1402) 
~[!/:3.0.3]
         at 
groovy.lang.MetaClassImpl.createPojoCallSite(MetaClassImpl.java:3485) 
~[!/:3.0.3]
         at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.createPojoSite(CallSiteArray.java:123) 
~[!/:3.0.3]
         at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:160) 
~[!/:3.0.3]
         at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) 
~[!/:3.0.3]
         at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) 
~[!/:3.0.3]
         at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139) 
~[!/:3.0.3]
         at 
Script_79c547dcc1121c0ac97f26e7a65ca1f4.run(Script_79c547dcc1121c0ac97f26e7a65ca1f4.groovy:1) 
~[?:?]
         at 
org.apache.camel.language.groovy.GroovyExpression.evaluate(GroovyExpression.java:52) 
~[!/:3.9.0]
         at 
org.apache.camel.processor.SetHeaderProcessor.process(SetHeaderProcessor.java:48) 
[!/:3.9.0]
         at 
org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleTask.run(RedeliveryErrorHandler.java:439) 
[!/:3.9.0]
         at 
org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:181) 
[!/:3.9.0]
         at 
org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:62) 
[!/:3.9.0]
         at 
org.apache.camel.processor.Pipeline.process(Pipeline.java:167) [!/:3.9.0]
         at 
org.apache.camel.impl.engine.CamelInternalProcessor.process(CamelInternalProcessor.java:388) 
[!/:3.9.0]
         at 
org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:209) 
[!/:3.9.0]
         at 
org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:76) 
[!/:3.9.0]
         at java.util.TimerThread.mainLoop(Timer.java:556) [?:?]
         at java.util.TimerThread.run(Timer.java:506) [?:?]
23:37:49.426 WARN [Camel (simple) thread #1 - timer://inittimer] Error 
processing exchange. Exchange[EA6BC0C06725249-0000000000000002]. Caused 
by: [groovy.lang.GroovyRuntimeException - Ambiguous method overloading 
for method [Ljava.lang.String;#getAt.

=====================================================================================================================

For the same test in Camel 3.8.0 do the following:

Stop Karaf

rm -rf data

Start Karaf

repo-add camel 3.8.0

feature:install camel

feature:install camel-groovy

Excerpt of logging:


23:34:09.633 INFO [Camel (simple) thread #1 - timer://inittimer] 
getOHItems body=
23:34:09.635 INFO [Camel (simple) thread #1 - timer://inittimer] 
getOHItems OHItems=[Ljava.lang.String;@60288c1f
23:34:09.694 INFO [Camel (simple) thread #1 - timer://inittimer] 
getOHItems: OHItemsResult=[Ljava.lang.String;@60288c1f
23:34:09.704 INFO [Camel (simple) thread #1 - timer://inittimer] 
getOHItems: OHItemsResultlength=4
23:34:09.800 INFO [Camel (simple) thread #1 - timer://inittimer] header 
OHItem is f1_nw_display_backlight_min
23:34:09.814 INFO [Camel (simple) thread #1 - timer://inittimer] header 
OHItem is f1_nw_display_backlight_max
23:34:09.814 INFO [Camel (simple) thread #1 - timer://inittimer] header 
OHItem is f1_nw_display_backlight_bias
23:34:09.815 INFO [Camel (simple) thread #1 - timer://inittimer] header 
OHItem is f1_nw_display_backlight_multiplier

======================================================================================================================

blueprint.xml (for the curious: OH is for OpenHab):

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="
              http://www.osgi.org/xmlns/blueprint/v1.0.0 
https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
              http://camel.apache.org/schema/blueprint 
http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">


     <camelContext xmlns="http://camel.apache.org/schema/blueprint" 
id="simple">
         <route id="t14">
             <from uri="timer:simple?repeatCount=1"/>
             <setBody>
                 <simple>Hello World</simple>
             </setBody>
             <log message="${body}"/>
         </route>


        <!-- ** Multiple items.
          Input: header OHItems, array of Strings (names of items)
          Output: body, array of Strings -->
         <route id="getOHItems" autoStartup="true" streamCache="true">
             <from uri="direct:getOHItems"/>
             <log message="getOHItems body=${body}"/>
             <log message="getOHItems OHItems=${header.OHItems}"/>
             <setHeader name="OHItemsResult">
                 <groovy>new String[request.headers.OHItems.length]</groovy>
             </setHeader>
             <log message="getOHItems: OHItemsResult=${headers.OHItems}"/>
             <log message="getOHItems: 
OHItemsResultlength=${headers.OHItems.length}"/>
             <loop>
<groovy>result=request.headers.OHItems.length</groovy>
                 <!-- log message="getOHItems: 
CamelLoopIndex=exchange.properties.CamelLoopIndex"/ -->
                 <setHeader name="OHItem">
<groovy>request.headers.OHItems[exchange.properties.CamelLoopIndex]</groovy>
                 </setHeader>
                 <log message="header OHItem is ${header.OHItem}"/>
                 <!-- Result is in body -->
                 <setHeader name="dummy">
<groovy>request.headers.OHItemsResult[exchange.properties.CamelLoopIndex]=request.body</groovy>
                 </setHeader>
             </loop>
             <setBody>
<groovy>request.headers.OHItemsResult</groovy>
             </setBody>
         </route>

        <route id="start1" autoStartup="true">
             <from uri="timer:inittimer?repeatCount=1"/>
             <setHeader name="OHItems">
                 <groovy>new 
String[]{"f1_nw_display_backlight_min","f1_nw_display_backlight_max",
"f1_nw_display_backlight_bias","f1_nw_display_backlight_multiplier"}
                 </groovy>
             </setHeader>
             <to uri="direct:getOHItems"/>
       </route>

     </camelContext>
</blueprint>


Operating system Debian

Java -version

openjdk version "11.0.9.1" 2020-11-04
OpenJDK Runtime Environment (build 11.0.9.1+1-post-Debian-1deb10u2)
OpenJDK 64-Bit Server VM (build 11.0.9.1+1-post-Debian-1deb10u2, mixed 
mode, sharing)


Re: Camel 3.9.0 Groovy CamelLoopIndex

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

See the upgrade guide
https://camel.apache.org/manual/latest/camel-3x-upgrade-guide-3_9.html#_exchange_properties

On Tue, Apr 20, 2021 at 11:44 PM Carl van Denzen <ca...@vandenzen.nl> wrote:
>
> Hi,
>
> It looks like something has changed between Camel 3.8.0 and 3.9.0 with
> Groovy or CamelLoopIndex.
>
> Up to and including Camel 3.8.0 my route succesfully runs the loop.
>
> In Camel 3.9.0 the loop fails. A wild guess is that something changed in
> accessing exchange.properties.CamelLoopIndex.
>
> Does anyone know how to solve this?
>
> Steps to reproduce:
>
> Start Karaf V4.3.1
>
> repo-add camel 3.9.0
>
> feature:install camel
>
> feature:install camel-groovy
>
> Then copy the blueprint.xml to the Karaf deploy directory and look at
> the Karaf log (log:display or log:tail).
>
> Excerpt of logging:
>
> 23:37:49.260 INFO [Camel (simple) thread #1 - timer://inittimer]
> getOHItems body=
> 23:37:49.262 INFO [Camel (simple) thread #1 - timer://inittimer]
> getOHItems OHItems=[Ljava.lang.String;@53870163
> 23:37:49.310 INFO [Camel (simple) thread #1 - timer://inittimer]
> getOHItems: OHItemsResult=[Ljava.lang.String;@53870163
> 23:37:49.321 INFO [Camel (simple) thread #1 - timer://inittimer]
> getOHItems: OHItemsResultlength=4
> 23:37:49.419 ERROR [Camel (simple) thread #1 - timer://inittimer] Failed
> delivery for (MessageId: EA6BC0C06725249-0000000000000002 on ExchangeId:
> EA6BC0C06725249-0000000000000002). Exhausted after delivery attempt: 1
> caught: groovy.lang.GroovyRuntimeException: Ambiguous method overloading
> for method [Ljava.lang.String;#getAt.
> Cannot resolve which method to invoke for [null] due to overlapping
> prototypes between:
>          [interface groovy.lang.Range]
>          [interface java.util.Collection]
>
> Message History (complete message history is disabled)
> ---------------------------------------------------------------------------------------------------------------------------------------
> RouteId              ProcessorId Processor Elapsed (ms)
> [start1            ] [start1            ]
> [from[timer://inittimer?repeatCount=1] ] [       811]
>          ...
> [getOHItems        ] [setHeader2        ] [setHeader[OHItem] ] [         0]
>
> Stacktrace
> ---------------------------------------------------------------------------------------------------------------------------------------
>
> groovy.lang.GroovyRuntimeException: Ambiguous method overloading for
> method [Ljava.lang.String;#getAt.
> Cannot resolve which method to invoke for [null] due to overlapping
> prototypes between:
>          [interface groovy.lang.Range]
>          [interface java.util.Collection]
>          at
> groovy.lang.MetaClassImpl.doChooseMostSpecificParams(MetaClassImpl.java:3338)
> ~[!/:3.0.3]
>          at
> groovy.lang.MetaClassImpl.chooseMostSpecificParams(MetaClassImpl.java:3314)
> ~[!/:3.0.3]
>          at
> groovy.lang.MetaClassImpl.chooseMethodInternal(MetaClassImpl.java:3304)
> ~[!/:3.0.3]
>          at
> groovy.lang.MetaClassImpl.chooseMethod(MetaClassImpl.java:3248) ~[!/:3.0.3]
>          at
> groovy.lang.MetaClassImpl.getMethodWithCachingInternal(MetaClassImpl.java:1402)
> ~[!/:3.0.3]
>          at
> groovy.lang.MetaClassImpl.createPojoCallSite(MetaClassImpl.java:3485)
> ~[!/:3.0.3]
>          at
> org.codehaus.groovy.runtime.callsite.CallSiteArray.createPojoSite(CallSiteArray.java:123)
> ~[!/:3.0.3]
>          at
> org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:160)
> ~[!/:3.0.3]
>          at
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
> ~[!/:3.0.3]
>          at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
> ~[!/:3.0.3]
>          at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
> ~[!/:3.0.3]
>          at
> Script_79c547dcc1121c0ac97f26e7a65ca1f4.run(Script_79c547dcc1121c0ac97f26e7a65ca1f4.groovy:1)
> ~[?:?]
>          at
> org.apache.camel.language.groovy.GroovyExpression.evaluate(GroovyExpression.java:52)
> ~[!/:3.9.0]
>          at
> org.apache.camel.processor.SetHeaderProcessor.process(SetHeaderProcessor.java:48)
> [!/:3.9.0]
>          at
> org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleTask.run(RedeliveryErrorHandler.java:439)
> [!/:3.9.0]
>          at
> org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:181)
> [!/:3.9.0]
>          at
> org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:62)
> [!/:3.9.0]
>          at
> org.apache.camel.processor.Pipeline.process(Pipeline.java:167) [!/:3.9.0]
>          at
> org.apache.camel.impl.engine.CamelInternalProcessor.process(CamelInternalProcessor.java:388)
> [!/:3.9.0]
>          at
> org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:209)
> [!/:3.9.0]
>          at
> org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:76)
> [!/:3.9.0]
>          at java.util.TimerThread.mainLoop(Timer.java:556) [?:?]
>          at java.util.TimerThread.run(Timer.java:506) [?:?]
> 23:37:49.426 WARN [Camel (simple) thread #1 - timer://inittimer] Error
> processing exchange. Exchange[EA6BC0C06725249-0000000000000002]. Caused
> by: [groovy.lang.GroovyRuntimeException - Ambiguous method overloading
> for method [Ljava.lang.String;#getAt.
>
> =====================================================================================================================
>
> For the same test in Camel 3.8.0 do the following:
>
> Stop Karaf
>
> rm -rf data
>
> Start Karaf
>
> repo-add camel 3.8.0
>
> feature:install camel
>
> feature:install camel-groovy
>
> Excerpt of logging:
>
>
> 23:34:09.633 INFO [Camel (simple) thread #1 - timer://inittimer]
> getOHItems body=
> 23:34:09.635 INFO [Camel (simple) thread #1 - timer://inittimer]
> getOHItems OHItems=[Ljava.lang.String;@60288c1f
> 23:34:09.694 INFO [Camel (simple) thread #1 - timer://inittimer]
> getOHItems: OHItemsResult=[Ljava.lang.String;@60288c1f
> 23:34:09.704 INFO [Camel (simple) thread #1 - timer://inittimer]
> getOHItems: OHItemsResultlength=4
> 23:34:09.800 INFO [Camel (simple) thread #1 - timer://inittimer] header
> OHItem is f1_nw_display_backlight_min
> 23:34:09.814 INFO [Camel (simple) thread #1 - timer://inittimer] header
> OHItem is f1_nw_display_backlight_max
> 23:34:09.814 INFO [Camel (simple) thread #1 - timer://inittimer] header
> OHItem is f1_nw_display_backlight_bias
> 23:34:09.815 INFO [Camel (simple) thread #1 - timer://inittimer] header
> OHItem is f1_nw_display_backlight_multiplier
>
> ======================================================================================================================
>
> blueprint.xml (for the curious: OH is for OpenHab):
>
> <?xml version="1.0" encoding="UTF-8"?>
> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>             xsi:schemaLocation="
>               http://www.osgi.org/xmlns/blueprint/v1.0.0
> https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
>               http://camel.apache.org/schema/blueprint
> http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
>
>
>      <camelContext xmlns="http://camel.apache.org/schema/blueprint"
> id="simple">
>          <route id="t14">
>              <from uri="timer:simple?repeatCount=1"/>
>              <setBody>
>                  <simple>Hello World</simple>
>              </setBody>
>              <log message="${body}"/>
>          </route>
>
>
>         <!-- ** Multiple items.
>           Input: header OHItems, array of Strings (names of items)
>           Output: body, array of Strings -->
>          <route id="getOHItems" autoStartup="true" streamCache="true">
>              <from uri="direct:getOHItems"/>
>              <log message="getOHItems body=${body}"/>
>              <log message="getOHItems OHItems=${header.OHItems}"/>
>              <setHeader name="OHItemsResult">
>                  <groovy>new String[request.headers.OHItems.length]</groovy>
>              </setHeader>
>              <log message="getOHItems: OHItemsResult=${headers.OHItems}"/>
>              <log message="getOHItems:
> OHItemsResultlength=${headers.OHItems.length}"/>
>              <loop>
> <groovy>result=request.headers.OHItems.length</groovy>
>                  <!-- log message="getOHItems:
> CamelLoopIndex=exchange.properties.CamelLoopIndex"/ -->
>                  <setHeader name="OHItem">
> <groovy>request.headers.OHItems[exchange.properties.CamelLoopIndex]</groovy>
>                  </setHeader>
>                  <log message="header OHItem is ${header.OHItem}"/>
>                  <!-- Result is in body -->
>                  <setHeader name="dummy">
> <groovy>request.headers.OHItemsResult[exchange.properties.CamelLoopIndex]=request.body</groovy>
>                  </setHeader>
>              </loop>
>              <setBody>
> <groovy>request.headers.OHItemsResult</groovy>
>              </setBody>
>          </route>
>
>         <route id="start1" autoStartup="true">
>              <from uri="timer:inittimer?repeatCount=1"/>
>              <setHeader name="OHItems">
>                  <groovy>new
> String[]{"f1_nw_display_backlight_min","f1_nw_display_backlight_max",
> "f1_nw_display_backlight_bias","f1_nw_display_backlight_multiplier"}
>                  </groovy>
>              </setHeader>
>              <to uri="direct:getOHItems"/>
>        </route>
>
>      </camelContext>
> </blueprint>
>
>
> Operating system Debian
>
> Java -version
>
> openjdk version "11.0.9.1" 2020-11-04
> OpenJDK Runtime Environment (build 11.0.9.1+1-post-Debian-1deb10u2)
> OpenJDK 64-Bit Server VM (build 11.0.9.1+1-post-Debian-1deb10u2, mixed
> mode, sharing)
>


-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: Camel 3.9.0 Groovy CamelLoopIndex

Posted by Carl van Denzen <ca...@vandenzen.nl>.
Hi Claus,


Thank you for your quick response, my problem is solved.

I did read the upgrade guide, but didn't realize it affected my code.

Only the [exchange.allProperties.CamelLoopIndex] solution seems to work 
in groovy.

Carl.

On 21-04-2021 06:19, Claus Ibsen wrote:
> Hi
>
> Try with
> [exchange.property(CamelLoopIndex)]
>
> Or
>
> [exchange.allProperties.CamelLoopIndex]
>
>
> On Tue, Apr 20, 2021 at 11:44 PM Carl van Denzen <ca...@vandenzen.nl> wrote:
>> Hi,
>>
>> It looks like something has changed between Camel 3.8.0 and 3.9.0 with
>> Groovy or CamelLoopIndex.
>>
>> Up to and including Camel 3.8.0 my route succesfully runs the loop.
>>
>> In Camel 3.9.0 the loop fails. A wild guess is that something changed in
>> accessing exchange.properties.CamelLoopIndex.
>>
>> Does anyone know how to solve this?
>>
>> Steps to reproduce:
>>
>> Start Karaf V4.3.1
>>
>> repo-add camel 3.9.0
>>
>> feature:install camel
>>
>> feature:install camel-groovy
>>
>> Then copy the blueprint.xml to the Karaf deploy directory and look at
>> the Karaf log (log:display or log:tail).
>>
>> Excerpt of logging:
>>
>> 23:37:49.260 INFO [Camel (simple) thread #1 - timer://inittimer]
>> getOHItems body=
>> 23:37:49.262 INFO [Camel (simple) thread #1 - timer://inittimer]
>> getOHItems OHItems=[Ljava.lang.String;@53870163
>> 23:37:49.310 INFO [Camel (simple) thread #1 - timer://inittimer]
>> getOHItems: OHItemsResult=[Ljava.lang.String;@53870163
>> 23:37:49.321 INFO [Camel (simple) thread #1 - timer://inittimer]
>> getOHItems: OHItemsResultlength=4
>> 23:37:49.419 ERROR [Camel (simple) thread #1 - timer://inittimer] Failed
>> delivery for (MessageId: EA6BC0C06725249-0000000000000002 on ExchangeId:
>> EA6BC0C06725249-0000000000000002). Exhausted after delivery attempt: 1
>> caught: groovy.lang.GroovyRuntimeException: Ambiguous method overloading
>> for method [Ljava.lang.String;#getAt.
>> Cannot resolve which method to invoke for [null] due to overlapping
>> prototypes between:
>>           [interface groovy.lang.Range]
>>           [interface java.util.Collection]
>>
>> Message History (complete message history is disabled)
>> ---------------------------------------------------------------------------------------------------------------------------------------
>> RouteId              ProcessorId Processor Elapsed (ms)
>> [start1            ] [start1            ]
>> [from[timer://inittimer?repeatCount=1] ] [       811]
>>           ...
>> [getOHItems        ] [setHeader2        ] [setHeader[OHItem] ] [         0]
>>
>> Stacktrace
>> ---------------------------------------------------------------------------------------------------------------------------------------
>>
>> groovy.lang.GroovyRuntimeException: Ambiguous method overloading for
>> method [Ljava.lang.String;#getAt.
>> Cannot resolve which method to invoke for [null] due to overlapping
>> prototypes between:
>>           [interface groovy.lang.Range]
>>           [interface java.util.Collection]
>>           at
>> groovy.lang.MetaClassImpl.doChooseMostSpecificParams(MetaClassImpl.java:3338)
>> ~[!/:3.0.3]
>>           at
>> groovy.lang.MetaClassImpl.chooseMostSpecificParams(MetaClassImpl.java:3314)
>> ~[!/:3.0.3]
>>           at
>> groovy.lang.MetaClassImpl.chooseMethodInternal(MetaClassImpl.java:3304)
>> ~[!/:3.0.3]
>>           at
>> groovy.lang.MetaClassImpl.chooseMethod(MetaClassImpl.java:3248) ~[!/:3.0.3]
>>           at
>> groovy.lang.MetaClassImpl.getMethodWithCachingInternal(MetaClassImpl.java:1402)
>> ~[!/:3.0.3]
>>           at
>> groovy.lang.MetaClassImpl.createPojoCallSite(MetaClassImpl.java:3485)
>> ~[!/:3.0.3]
>>           at
>> org.codehaus.groovy.runtime.callsite.CallSiteArray.createPojoSite(CallSiteArray.java:123)
>> ~[!/:3.0.3]
>>           at
>> org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:160)
>> ~[!/:3.0.3]
>>           at
>> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
>> ~[!/:3.0.3]
>>           at
>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
>> ~[!/:3.0.3]
>>           at
>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
>> ~[!/:3.0.3]
>>           at
>> Script_79c547dcc1121c0ac97f26e7a65ca1f4.run(Script_79c547dcc1121c0ac97f26e7a65ca1f4.groovy:1)
>> ~[?:?]
>>           at
>> org.apache.camel.language.groovy.GroovyExpression.evaluate(GroovyExpression.java:52)
>> ~[!/:3.9.0]
>>           at
>> org.apache.camel.processor.SetHeaderProcessor.process(SetHeaderProcessor.java:48)
>> [!/:3.9.0]
>>           at
>> org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleTask.run(RedeliveryErrorHandler.java:439)
>> [!/:3.9.0]
>>           at
>> org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:181)
>> [!/:3.9.0]
>>           at
>> org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:62)
>> [!/:3.9.0]
>>           at
>> org.apache.camel.processor.Pipeline.process(Pipeline.java:167) [!/:3.9.0]
>>           at
>> org.apache.camel.impl.engine.CamelInternalProcessor.process(CamelInternalProcessor.java:388)
>> [!/:3.9.0]
>>           at
>> org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:209)
>> [!/:3.9.0]
>>           at
>> org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:76)
>> [!/:3.9.0]
>>           at java.util.TimerThread.mainLoop(Timer.java:556) [?:?]
>>           at java.util.TimerThread.run(Timer.java:506) [?:?]
>> 23:37:49.426 WARN [Camel (simple) thread #1 - timer://inittimer] Error
>> processing exchange. Exchange[EA6BC0C06725249-0000000000000002]. Caused
>> by: [groovy.lang.GroovyRuntimeException - Ambiguous method overloading
>> for method [Ljava.lang.String;#getAt.
>>
>> =====================================================================================================================
>>
>> For the same test in Camel 3.8.0 do the following:
>>
>> Stop Karaf
>>
>> rm -rf data
>>
>> Start Karaf
>>
>> repo-add camel 3.8.0
>>
>> feature:install camel
>>
>> feature:install camel-groovy
>>
>> Excerpt of logging:
>>
>>
>> 23:34:09.633 INFO [Camel (simple) thread #1 - timer://inittimer]
>> getOHItems body=
>> 23:34:09.635 INFO [Camel (simple) thread #1 - timer://inittimer]
>> getOHItems OHItems=[Ljava.lang.String;@60288c1f
>> 23:34:09.694 INFO [Camel (simple) thread #1 - timer://inittimer]
>> getOHItems: OHItemsResult=[Ljava.lang.String;@60288c1f
>> 23:34:09.704 INFO [Camel (simple) thread #1 - timer://inittimer]
>> getOHItems: OHItemsResultlength=4
>> 23:34:09.800 INFO [Camel (simple) thread #1 - timer://inittimer] header
>> OHItem is f1_nw_display_backlight_min
>> 23:34:09.814 INFO [Camel (simple) thread #1 - timer://inittimer] header
>> OHItem is f1_nw_display_backlight_max
>> 23:34:09.814 INFO [Camel (simple) thread #1 - timer://inittimer] header
>> OHItem is f1_nw_display_backlight_bias
>> 23:34:09.815 INFO [Camel (simple) thread #1 - timer://inittimer] header
>> OHItem is f1_nw_display_backlight_multiplier
>>
>> ======================================================================================================================
>>
>> blueprint.xml (for the curious: OH is for OpenHab):
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>              xsi:schemaLocation="
>>                http://www.osgi.org/xmlns/blueprint/v1.0.0
>> https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
>>                http://camel.apache.org/schema/blueprint
>> http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
>>
>>
>>       <camelContext xmlns="http://camel.apache.org/schema/blueprint"
>> id="simple">
>>           <route id="t14">
>>               <from uri="timer:simple?repeatCount=1"/>
>>               <setBody>
>>                   <simple>Hello World</simple>
>>               </setBody>
>>               <log message="${body}"/>
>>           </route>
>>
>>
>>          <!-- ** Multiple items.
>>            Input: header OHItems, array of Strings (names of items)
>>            Output: body, array of Strings -->
>>           <route id="getOHItems" autoStartup="true" streamCache="true">
>>               <from uri="direct:getOHItems"/>
>>               <log message="getOHItems body=${body}"/>
>>               <log message="getOHItems OHItems=${header.OHItems}"/>
>>               <setHeader name="OHItemsResult">
>>                   <groovy>new String[request.headers.OHItems.length]</groovy>
>>               </setHeader>
>>               <log message="getOHItems: OHItemsResult=${headers.OHItems}"/>
>>               <log message="getOHItems:
>> OHItemsResultlength=${headers.OHItems.length}"/>
>>               <loop>
>> <groovy>result=request.headers.OHItems.length</groovy>
>>                   <!-- log message="getOHItems:
>> CamelLoopIndex=exchange.properties.CamelLoopIndex"/ -->
>>                   <setHeader name="OHItem">
>> <groovy>request.headers.OHItems[exchange.properties.CamelLoopIndex]</groovy>
>>                   </setHeader>
>>                   <log message="header OHItem is ${header.OHItem}"/>
>>                   <!-- Result is in body -->
>>                   <setHeader name="dummy">
>> <groovy>request.headers.OHItemsResult[exchange.properties.CamelLoopIndex]=request.body</groovy>
>>                   </setHeader>
>>               </loop>
>>               <setBody>
>> <groovy>request.headers.OHItemsResult</groovy>
>>               </setBody>
>>           </route>
>>
>>          <route id="start1" autoStartup="true">
>>               <from uri="timer:inittimer?repeatCount=1"/>
>>               <setHeader name="OHItems">
>>                   <groovy>new
>> String[]{"f1_nw_display_backlight_min","f1_nw_display_backlight_max",
>> "f1_nw_display_backlight_bias","f1_nw_display_backlight_multiplier"}
>>                   </groovy>
>>               </setHeader>
>>               <to uri="direct:getOHItems"/>
>>         </route>
>>
>>       </camelContext>
>> </blueprint>
>>
>>
>> Operating system Debian
>>
>> Java -version
>>
>> openjdk version "11.0.9.1" 2020-11-04
>> OpenJDK Runtime Environment (build 11.0.9.1+1-post-Debian-1deb10u2)
>> OpenJDK 64-Bit Server VM (build 11.0.9.1+1-post-Debian-1deb10u2, mixed
>> mode, sharing)
>>
>

Re: Camel 3.9.0 Groovy CamelLoopIndex

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Try with
[exchange.property(CamelLoopIndex)]

Or

[exchange.allProperties.CamelLoopIndex]


On Tue, Apr 20, 2021 at 11:44 PM Carl van Denzen <ca...@vandenzen.nl> wrote:
>
> Hi,
>
> It looks like something has changed between Camel 3.8.0 and 3.9.0 with
> Groovy or CamelLoopIndex.
>
> Up to and including Camel 3.8.0 my route succesfully runs the loop.
>
> In Camel 3.9.0 the loop fails. A wild guess is that something changed in
> accessing exchange.properties.CamelLoopIndex.
>
> Does anyone know how to solve this?
>
> Steps to reproduce:
>
> Start Karaf V4.3.1
>
> repo-add camel 3.9.0
>
> feature:install camel
>
> feature:install camel-groovy
>
> Then copy the blueprint.xml to the Karaf deploy directory and look at
> the Karaf log (log:display or log:tail).
>
> Excerpt of logging:
>
> 23:37:49.260 INFO [Camel (simple) thread #1 - timer://inittimer]
> getOHItems body=
> 23:37:49.262 INFO [Camel (simple) thread #1 - timer://inittimer]
> getOHItems OHItems=[Ljava.lang.String;@53870163
> 23:37:49.310 INFO [Camel (simple) thread #1 - timer://inittimer]
> getOHItems: OHItemsResult=[Ljava.lang.String;@53870163
> 23:37:49.321 INFO [Camel (simple) thread #1 - timer://inittimer]
> getOHItems: OHItemsResultlength=4
> 23:37:49.419 ERROR [Camel (simple) thread #1 - timer://inittimer] Failed
> delivery for (MessageId: EA6BC0C06725249-0000000000000002 on ExchangeId:
> EA6BC0C06725249-0000000000000002). Exhausted after delivery attempt: 1
> caught: groovy.lang.GroovyRuntimeException: Ambiguous method overloading
> for method [Ljava.lang.String;#getAt.
> Cannot resolve which method to invoke for [null] due to overlapping
> prototypes between:
>          [interface groovy.lang.Range]
>          [interface java.util.Collection]
>
> Message History (complete message history is disabled)
> ---------------------------------------------------------------------------------------------------------------------------------------
> RouteId              ProcessorId Processor Elapsed (ms)
> [start1            ] [start1            ]
> [from[timer://inittimer?repeatCount=1] ] [       811]
>          ...
> [getOHItems        ] [setHeader2        ] [setHeader[OHItem] ] [         0]
>
> Stacktrace
> ---------------------------------------------------------------------------------------------------------------------------------------
>
> groovy.lang.GroovyRuntimeException: Ambiguous method overloading for
> method [Ljava.lang.String;#getAt.
> Cannot resolve which method to invoke for [null] due to overlapping
> prototypes between:
>          [interface groovy.lang.Range]
>          [interface java.util.Collection]
>          at
> groovy.lang.MetaClassImpl.doChooseMostSpecificParams(MetaClassImpl.java:3338)
> ~[!/:3.0.3]
>          at
> groovy.lang.MetaClassImpl.chooseMostSpecificParams(MetaClassImpl.java:3314)
> ~[!/:3.0.3]
>          at
> groovy.lang.MetaClassImpl.chooseMethodInternal(MetaClassImpl.java:3304)
> ~[!/:3.0.3]
>          at
> groovy.lang.MetaClassImpl.chooseMethod(MetaClassImpl.java:3248) ~[!/:3.0.3]
>          at
> groovy.lang.MetaClassImpl.getMethodWithCachingInternal(MetaClassImpl.java:1402)
> ~[!/:3.0.3]
>          at
> groovy.lang.MetaClassImpl.createPojoCallSite(MetaClassImpl.java:3485)
> ~[!/:3.0.3]
>          at
> org.codehaus.groovy.runtime.callsite.CallSiteArray.createPojoSite(CallSiteArray.java:123)
> ~[!/:3.0.3]
>          at
> org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:160)
> ~[!/:3.0.3]
>          at
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
> ~[!/:3.0.3]
>          at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
> ~[!/:3.0.3]
>          at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
> ~[!/:3.0.3]
>          at
> Script_79c547dcc1121c0ac97f26e7a65ca1f4.run(Script_79c547dcc1121c0ac97f26e7a65ca1f4.groovy:1)
> ~[?:?]
>          at
> org.apache.camel.language.groovy.GroovyExpression.evaluate(GroovyExpression.java:52)
> ~[!/:3.9.0]
>          at
> org.apache.camel.processor.SetHeaderProcessor.process(SetHeaderProcessor.java:48)
> [!/:3.9.0]
>          at
> org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleTask.run(RedeliveryErrorHandler.java:439)
> [!/:3.9.0]
>          at
> org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:181)
> [!/:3.9.0]
>          at
> org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:62)
> [!/:3.9.0]
>          at
> org.apache.camel.processor.Pipeline.process(Pipeline.java:167) [!/:3.9.0]
>          at
> org.apache.camel.impl.engine.CamelInternalProcessor.process(CamelInternalProcessor.java:388)
> [!/:3.9.0]
>          at
> org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:209)
> [!/:3.9.0]
>          at
> org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:76)
> [!/:3.9.0]
>          at java.util.TimerThread.mainLoop(Timer.java:556) [?:?]
>          at java.util.TimerThread.run(Timer.java:506) [?:?]
> 23:37:49.426 WARN [Camel (simple) thread #1 - timer://inittimer] Error
> processing exchange. Exchange[EA6BC0C06725249-0000000000000002]. Caused
> by: [groovy.lang.GroovyRuntimeException - Ambiguous method overloading
> for method [Ljava.lang.String;#getAt.
>
> =====================================================================================================================
>
> For the same test in Camel 3.8.0 do the following:
>
> Stop Karaf
>
> rm -rf data
>
> Start Karaf
>
> repo-add camel 3.8.0
>
> feature:install camel
>
> feature:install camel-groovy
>
> Excerpt of logging:
>
>
> 23:34:09.633 INFO [Camel (simple) thread #1 - timer://inittimer]
> getOHItems body=
> 23:34:09.635 INFO [Camel (simple) thread #1 - timer://inittimer]
> getOHItems OHItems=[Ljava.lang.String;@60288c1f
> 23:34:09.694 INFO [Camel (simple) thread #1 - timer://inittimer]
> getOHItems: OHItemsResult=[Ljava.lang.String;@60288c1f
> 23:34:09.704 INFO [Camel (simple) thread #1 - timer://inittimer]
> getOHItems: OHItemsResultlength=4
> 23:34:09.800 INFO [Camel (simple) thread #1 - timer://inittimer] header
> OHItem is f1_nw_display_backlight_min
> 23:34:09.814 INFO [Camel (simple) thread #1 - timer://inittimer] header
> OHItem is f1_nw_display_backlight_max
> 23:34:09.814 INFO [Camel (simple) thread #1 - timer://inittimer] header
> OHItem is f1_nw_display_backlight_bias
> 23:34:09.815 INFO [Camel (simple) thread #1 - timer://inittimer] header
> OHItem is f1_nw_display_backlight_multiplier
>
> ======================================================================================================================
>
> blueprint.xml (for the curious: OH is for OpenHab):
>
> <?xml version="1.0" encoding="UTF-8"?>
> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>             xsi:schemaLocation="
>               http://www.osgi.org/xmlns/blueprint/v1.0.0
> https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
>               http://camel.apache.org/schema/blueprint
> http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
>
>
>      <camelContext xmlns="http://camel.apache.org/schema/blueprint"
> id="simple">
>          <route id="t14">
>              <from uri="timer:simple?repeatCount=1"/>
>              <setBody>
>                  <simple>Hello World</simple>
>              </setBody>
>              <log message="${body}"/>
>          </route>
>
>
>         <!-- ** Multiple items.
>           Input: header OHItems, array of Strings (names of items)
>           Output: body, array of Strings -->
>          <route id="getOHItems" autoStartup="true" streamCache="true">
>              <from uri="direct:getOHItems"/>
>              <log message="getOHItems body=${body}"/>
>              <log message="getOHItems OHItems=${header.OHItems}"/>
>              <setHeader name="OHItemsResult">
>                  <groovy>new String[request.headers.OHItems.length]</groovy>
>              </setHeader>
>              <log message="getOHItems: OHItemsResult=${headers.OHItems}"/>
>              <log message="getOHItems:
> OHItemsResultlength=${headers.OHItems.length}"/>
>              <loop>
> <groovy>result=request.headers.OHItems.length</groovy>
>                  <!-- log message="getOHItems:
> CamelLoopIndex=exchange.properties.CamelLoopIndex"/ -->
>                  <setHeader name="OHItem">
> <groovy>request.headers.OHItems[exchange.properties.CamelLoopIndex]</groovy>
>                  </setHeader>
>                  <log message="header OHItem is ${header.OHItem}"/>
>                  <!-- Result is in body -->
>                  <setHeader name="dummy">
> <groovy>request.headers.OHItemsResult[exchange.properties.CamelLoopIndex]=request.body</groovy>
>                  </setHeader>
>              </loop>
>              <setBody>
> <groovy>request.headers.OHItemsResult</groovy>
>              </setBody>
>          </route>
>
>         <route id="start1" autoStartup="true">
>              <from uri="timer:inittimer?repeatCount=1"/>
>              <setHeader name="OHItems">
>                  <groovy>new
> String[]{"f1_nw_display_backlight_min","f1_nw_display_backlight_max",
> "f1_nw_display_backlight_bias","f1_nw_display_backlight_multiplier"}
>                  </groovy>
>              </setHeader>
>              <to uri="direct:getOHItems"/>
>        </route>
>
>      </camelContext>
> </blueprint>
>
>
> Operating system Debian
>
> Java -version
>
> openjdk version "11.0.9.1" 2020-11-04
> OpenJDK Runtime Environment (build 11.0.9.1+1-post-Debian-1deb10u2)
> OpenJDK 64-Bit Server VM (build 11.0.9.1+1-post-Debian-1deb10u2, mixed
> mode, sharing)
>


-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2