[jira] [Commented] (CAMEL-10349) javaScript setHeader conversion fault
[ https://issues.apache.org/jira/browse/CAMEL-10349?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16376876#comment-16376876 ] ASF GitHub Bot commented on CAMEL-10349: davsclaus closed pull request #1190: CAMEL-10349, javaScript setHeader conversion fault URL: https://github.com/apache/camel/pull/1190 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java b/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java index af2ba63f96a..96be8c68aca 100644 --- a/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java +++ b/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java @@ -32,6 +32,9 @@ import javax.script.ScriptEngineManager; import javax.script.ScriptException; +import jdk.nashorn.api.scripting.NashornScriptEngine; +import jdk.nashorn.api.scripting.ScriptObjectMirror; + import org.apache.camel.CamelContext; import org.apache.camel.Exchange; import org.apache.camel.Expression; @@ -481,6 +484,13 @@ protected Object runScript(ScriptEngine engine, Exchange exchange, ScriptContext if (result == null) { result = engine.get("result"); } + +// into jdk8 a list will be mapped to ScriptObjectMirror +if (engine instanceof NashornScriptEngine && result != null && result instanceof ScriptObjectMirror) { +if (((ScriptObjectMirror)result).isArray()) { +result = ((ScriptObjectMirror)result).values(); +} +} return result; } diff --git a/components/camel-script/src/test/java/org/apache/camel/builder/script/JavaScriptArrayExpressionTest.java b/components/camel-script/src/test/java/org/apache/camel/builder/script/JavaScriptArrayExpressionTest.java new file mode 100644 index 000..2ee8e93c2e7 --- /dev/null +++ b/components/camel-script/src/test/java/org/apache/camel/builder/script/JavaScriptArrayExpressionTest.java @@ -0,0 +1,58 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.builder.script; + +import java.util.List; +import java.util.concurrent.TimeUnit; + +import org.apache.camel.EndpointInject; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +/** + * Tests cast routing expression using JavaScript + */ +public class JavaScriptArrayExpressionTest extends CamelTestSupport { + +@EndpointInject(uri = "mock:result") +MockEndpoint resultEndpoint; + +private static final String HEADER_NAME = "myHeader"; + +@Test +public void testSendMatchingMessage() throws Exception { +context.addRoutes(new RouteBuilder() { +public void configure() throws Exception { +from("direct:start").setHeader(HEADER_NAME).javaScript("new Array()").to(resultEndpoint); +} +}); + +template.sendBody("direct:start", "BODY"); + +assertNotEquals(resultEndpoint.getExchanges().size(), 0); + +Object header = resultEndpoint.getExchanges().get(0).getIn().getHeader(HEADER_NAME); + +log.info("Check header instance: {}", header.getClass().getCanonicalName()); + +assertTrue(header instanceof List); + +assertMockEndpointsSatisfied(10, TimeUnit.SECONDS); +} +} diff --git a/components/camel-script/src/test/java/org/apache/camel/builder/script/JavaScriptListWithMapExpressionTest.java b/components/camel-script/src/test/java/org/apache/camel/builder/script/JavaScriptListWithMapExpressionTest.java new file mode 100644 index 000..fba56e9904f --- /dev/null +++ b/components/camel-script/src/test/java/org/apache/camel/builder/script/JavaScriptListWithMapExpressionTest.java @@ -0,0 +1,61 @@
[jira] [Commented] (CAMEL-10349) javaScript setHeader conversion fault
[ https://issues.apache.org/jira/browse/CAMEL-10349?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16376875#comment-16376875 ] ASF GitHub Bot commented on CAMEL-10349: davsclaus commented on issue #1190: CAMEL-10349, javaScript setHeader conversion fault URL: https://github.com/apache/camel/pull/1190#issuecomment-368507934 The Karaf guys keeps making this wrong, so lets just give up. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > javaScript setHeader conversion fault > - > > Key: CAMEL-10349 > URL: https://issues.apache.org/jira/browse/CAMEL-10349 > Project: Camel > Issue Type: Bug > Components: camel-script, karaf >Affects Versions: 2.18.0 >Reporter: Fabrizio Spataro >Assignee: Fabrizio Spataro >Priority: Minor > > I may have found a bug derived from 2.18 > Before 2.18, i can specified an header like: > {code} > > [ {"firstField": "firstValue", "secondField":"secondValue"} > ] > > {code} > I pass it into a method inside my bean. It was cast to > ArrayList> > After 2.18 upgrade i had an error > 'java.lang.ClassCastException: jdk.nashorn.api.scripting.ScriptObjectMirror > cannot be cast to java.util.List' > Can you help me? Is it a camel bug or an jdk8 issue? -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (CAMEL-10349) javaScript setHeader conversion fault
[ https://issues.apache.org/jira/browse/CAMEL-10349?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16376877#comment-16376877 ] ASF GitHub Bot commented on CAMEL-10349: Github user davsclaus closed the pull request at: https://github.com/apache/camel/pull/1190 > javaScript setHeader conversion fault > - > > Key: CAMEL-10349 > URL: https://issues.apache.org/jira/browse/CAMEL-10349 > Project: Camel > Issue Type: Bug > Components: camel-script, karaf >Affects Versions: 2.18.0 >Reporter: Fabrizio Spataro >Assignee: Fabrizio Spataro >Priority: Minor > > I may have found a bug derived from 2.18 > Before 2.18, i can specified an header like: > {code} > > [ {"firstField": "firstValue", "secondField":"secondValue"} > ] > > {code} > I pass it into a method inside my bean. It was cast to > ArrayList> > After 2.18 upgrade i had an error > 'java.lang.ClassCastException: jdk.nashorn.api.scripting.ScriptObjectMirror > cannot be cast to java.util.List' > Can you help me? Is it a camel bug or an jdk8 issue? -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (CAMEL-10349) javaScript setHeader conversion fault
[ https://issues.apache.org/jira/browse/CAMEL-10349?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16303308#comment-16303308 ] ASF GitHub Bot commented on CAMEL-10349: davsclaus commented on issue #1190: CAMEL-10349, javaScript setHeader conversion fault URL: https://github.com/apache/camel/pull/1190#issuecomment-353875989 Its still a problem in Karaf and KARAF-4603 did not fix this. You have to add the osgi import in the etc/jre.properties file to make it work. @gnodet wonder if you could take a 2nd look at your fix and possible amend it to include the osgi package in the etc/jre.properties file as well. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > javaScript setHeader conversion fault > - > > Key: CAMEL-10349 > URL: https://issues.apache.org/jira/browse/CAMEL-10349 > Project: Camel > Issue Type: Bug > Components: camel-script, karaf >Affects Versions: 2.18.0 >Reporter: Fabrizio Spataro >Assignee: Fabrizio Spataro >Priority: Minor > > I may have found a bug derived from 2.18 > Before 2.18, i can specified an header like: > {code} > > [ {"firstField": "firstValue", "secondField":"secondValue"} > ] > > {code} > I pass it into a method inside my bean. It was cast to > ArrayList> > After 2.18 upgrade i had an error > 'java.lang.ClassCastException: jdk.nashorn.api.scripting.ScriptObjectMirror > cannot be cast to java.util.List' > Can you help me? Is it a camel bug or an jdk8 issue? -- This message was sent by Atlassian JIRA (v6.4.14#64029)
[jira] [Commented] (CAMEL-10349) javaScript setHeader conversion fault
[ https://issues.apache.org/jira/browse/CAMEL-10349?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16303304#comment-16303304 ] ASF GitHub Bot commented on CAMEL-10349: davsclaus commented on issue #1190: CAMEL-10349, javaScript setHeader conversion fault URL: https://github.com/apache/camel/pull/1190#issuecomment-353875553 The Karaf team have not yet fixed this properly, installing camel-script now fails with ``` karaf@root()> feature:install camel-script-javascript Error executing command: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=camel-script-javascript; type=karaf.feature; version="[2.21.0.SNAPSHOT,2.21.0.SNAPSHOT]"; filter:="(&(osgi.identity=camel-script-javascript)(type=karaf.feature)(version>=2.21.0.SNAPSHOT)(version<=2.21.0.SNAPSHOT))" [caused by: Unable to resolve camel-script-javascript/2.21.0.SNAPSHOT: missing requirement [camel-script-javascript/2.21.0.SNAPSHOT] osgi.identity; osgi.identity=camel-script; type=karaf.feature; version="[2.21.0.SNAPSHOT,2.21.0.SNAPSHOT]" [caused by: Unable to resolve camel-script/2.21.0.SNAPSHOT: missing requirement [camel-script/2.21.0.SNAPSHOT] osgi.identity; osgi.identity=org.apache.camel.camel-script; type=osgi.bundle; version="[2.21.0.SNAPSHOT,2.21.0.SNAPSHOT]"; resolution:=mandatory [caused by: Unable to resolve org.apache.camel.camel-script/2.21.0.SNAPSHOT: missing requirement [org.apache.camel.camel-script/2.21.0.SNAPSHOT] osgi.wiring.package; filter:="(osgi.wiring.package=jdk.nashorn.api.scripting)"]]] ``` This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > javaScript setHeader conversion fault > - > > Key: CAMEL-10349 > URL: https://issues.apache.org/jira/browse/CAMEL-10349 > Project: Camel > Issue Type: Bug > Components: camel-core >Affects Versions: 2.18.0 >Reporter: Fabrizio Spataro >Assignee: Fabrizio Spataro > > I may have found a bug derived from 2.18 > Before 2.18, i can specified an header like: > {code} > > [ {"firstField": "firstValue", "secondField":"secondValue"} > ] > > {code} > I pass it into a method inside my bean. It was cast to > ArrayList> > After 2.18 upgrade i had an error > 'java.lang.ClassCastException: jdk.nashorn.api.scripting.ScriptObjectMirror > cannot be cast to java.util.List' > Can you help me? Is it a camel bug or an jdk8 issue? -- This message was sent by Atlassian JIRA (v6.4.14#64029)
[jira] [Commented] (CAMEL-10349) javaScript setHeader conversion fault
[ https://issues.apache.org/jira/browse/CAMEL-10349?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15529792#comment-15529792 ] Fabrizio Spataro commented on CAMEL-10349: -- fixed. Can you approve my PR? > javaScript setHeader conversion fault > - > > Key: CAMEL-10349 > URL: https://issues.apache.org/jira/browse/CAMEL-10349 > Project: Camel > Issue Type: Bug > Components: camel-core >Affects Versions: 2.18.0 >Reporter: Fabrizio Spataro >Assignee: Fabrizio Spataro > > I may have found a bug derived from 2.18 > Before 2.18, i can specified an header like: > {code} > > [ {"firstField": "firstValue", "secondField":"secondValue"} > ] > > {code} > I pass it into a method inside my bean. It was cast to > ArrayList> > After 2.18 upgrade i had an error > 'java.lang.ClassCastException: jdk.nashorn.api.scripting.ScriptObjectMirror > cannot be cast to java.util.List' > Can you help me? Is it a camel bug or an jdk8 issue? -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (CAMEL-10349) javaScript setHeader conversion fault
[ https://issues.apache.org/jira/browse/CAMEL-10349?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15529566#comment-15529566 ] Fabrizio Spataro commented on CAMEL-10349: -- [~davsclaus] read this: https://wiki.openjdk.java.net/display/Nashorn/Nashorn+jsr223+engine+notes > javaScript setHeader conversion fault > - > > Key: CAMEL-10349 > URL: https://issues.apache.org/jira/browse/CAMEL-10349 > Project: Camel > Issue Type: Bug > Components: camel-core >Affects Versions: 2.18.0 >Reporter: Fabrizio Spataro >Assignee: Fabrizio Spataro > > I may have found a bug derived from 2.18 > Before 2.18, i can specified an header like: > {code} > > [ {"firstField": "firstValue", "secondField":"secondValue"} > ] > > {code} > I pass it into a method inside my bean. It was cast to > ArrayList> > After 2.18 upgrade i had an error > 'java.lang.ClassCastException: jdk.nashorn.api.scripting.ScriptObjectMirror > cannot be cast to java.util.List' > Can you help me? Is it a camel bug or an jdk8 issue? -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (CAMEL-10349) javaScript setHeader conversion fault
[ https://issues.apache.org/jira/browse/CAMEL-10349?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15529540#comment-15529540 ] ASF GitHub Bot commented on CAMEL-10349: GitHub user Fabryprog opened a pull request: https://github.com/apache/camel/pull/1190 javaScript setHeader conversion fault https://issues.apache.org/jira/browse/CAMEL-10349 You can merge this pull request into a Git repository by running: $ git pull https://github.com/Fabryprog/camel CAMEL-10349 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/camel/pull/1190.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #1190 commit 58b028c3c0572795e92ec17aaae7da75179e183e Author: Fabrizio SpataroDate: 2016-09-28T13:02:39Z CAMEL-10349, insert new test file > javaScript setHeader conversion fault > - > > Key: CAMEL-10349 > URL: https://issues.apache.org/jira/browse/CAMEL-10349 > Project: Camel > Issue Type: Bug > Components: camel-core >Affects Versions: 2.18.0 >Reporter: Fabrizio Spataro >Assignee: Fabrizio Spataro > > I may have found a bug derived from 2.18 > Before 2.18, i can specified an header like: > {code} > > [ {"firstField": "firstValue", "secondField":"secondValue"} > ] > > {code} > I pass it into a method inside my bean. It was cast to > ArrayList > > After 2.18 upgrade i had an error > 'java.lang.ClassCastException: jdk.nashorn.api.scripting.ScriptObjectMirror > cannot be cast to java.util.List' > Can you help me? Is it a camel bug or an jdk8 issue? -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (CAMEL-10349) javaScript setHeader conversion fault
[ https://issues.apache.org/jira/browse/CAMEL-10349?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15528743#comment-15528743 ] Fabrizio Spataro commented on CAMEL-10349: -- ok, I start to work immediately to reproduce it. > javaScript setHeader conversion fault > - > > Key: CAMEL-10349 > URL: https://issues.apache.org/jira/browse/CAMEL-10349 > Project: Camel > Issue Type: Bug > Components: camel-core >Affects Versions: 2.18.0 >Reporter: Fabrizio Spataro > > I may have found a bug derived from 2.18 > Before 2.18, i can specified an header like: > {code} > > [ {"firstField": "firstValue", "secondField":"secondValue"} > ] > > {code} > I pass it into a method inside my bean. It was cast to > ArrayList> > After 2.18 upgrade i had an error > 'java.lang.ClassCastException: jdk.nashorn.api.scripting.ScriptObjectMirror > cannot be cast to java.util.List' > Can you help me? Is it a camel bug or an jdk8 issue? -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (CAMEL-10349) javaScript setHeader conversion fault
[ https://issues.apache.org/jira/browse/CAMEL-10349?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15528711#comment-15528711 ] Claus Ibsen commented on CAMEL-10349: - You need to research this yourself some more. There is plenty of moving things when upgrading. Did you upgrade JDK also? And from what older Camel version. Do you touch any other code changes and so on. Try to build a produceable unit test in camel-script that uses . > javaScript setHeader conversion fault > - > > Key: CAMEL-10349 > URL: https://issues.apache.org/jira/browse/CAMEL-10349 > Project: Camel > Issue Type: Bug > Components: camel-core >Affects Versions: 2.18.0 >Reporter: Fabrizio Spataro > > I may have found a bug derived from 2.18 > Before 2.18, i can specified an header like: > {code} > > [ {"firstField": "firstValue", "secondField":"secondValue"} > ] > > {code} > I pass it into a method inside my bean. It was cast to > ArrayList> > After 2.18 upgrade i had an error > 'java.lang.ClassCastException: jdk.nashorn.api.scripting.ScriptObjectMirror > cannot be cast to java.util.List' > Can you help me? Is it a camel bug or an jdk8 issue? -- This message was sent by Atlassian JIRA (v6.3.4#6332)