源码:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext id="_camelContext1" xmlns="http://camel.apache.org/schema/spring">
<route id="_fortest1">
<from id="_from1" uri="file:D:\Tmp\File\jsonfiles\test?noop=true"/>
<log id="_log1" message="file name is:${file:name},file contents is:${body}"/>
<convertBodyTo id="_convertBodyTo1-1" type="java.lang.String"/>
<setHeader headerName="js-msg" id="_setHeader1-2-2">
<javaScript>
var obj = JSON.parse(request.getBody());
var msgObj = obj.msg;
JSON.stringify(msgObj);
</javaScript>
</setHeader>
<log id="_log2" message="json contents name is:${header.js-name}, msg is:${header.js-msg}"/>
<transform id="_transform1">
<simple>${body}</simple>
</transform>
</route>
</camelContext>
var msgObj = obj.msg;
JSON.stringify(msgObj);. Cause: org.mozilla.javascript.EcmaError: ReferenceError: "JSON" is not defined. (<Unknown source>#1)
at org.apache.camel.builder.script.ScriptBuilder.createScriptEvaluationException(ScriptBuilder.java:547)[266:org.apache.camel.camel-script:2.17.0.redhat-630187]
at org.apache.camel.builder.script.ScriptBuilder.evaluateScript(ScriptBuilder.java:416)[266:org.apache.camel.camel-script:2.17.0.redhat-630187]
at org.apache.camel.builder.script.ScriptBuilder.evaluate(ScriptBuilder.java:160)[266:org.apache.camel.camel-script:2.17.0.redhat-630187]
请大神们帮忙分析分析,应如何解决该问题?
JAVA 的 js 引擎中没有引入浏览器中原生的JSON 库,您可以找一个json库,在java脚本引擎中添加.
已经回到
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。