WSO2 - 代理输入中的错误解码 json 消息:无法调用未定义的方法 "info"
WSO2 - error decoding json message in input to proxy: Cannot call method "info" of undefined
我正在尝试在 wso2 中编写一个代理,给定一个 jason 格式的输入,调用一个签名略有不同的网络服务。我写了一个 Javascript 函数来执行转换,但我收到以下错误消息:
[2021-10-23 14:21:14,520] ERROR {ScriptMediator} - {proxy:cambioStatoPratica} The script engine returned an error executing the inlined js script function mediate com.sun.phobos.script.util.ExtendedScriptException: org.mozilla.javascript.EcmaError: TypeError: Cannot call method "info" of undefined (#3) in at line number 3
at com.sun.phobos.script.javascript.RhinoCompiledScript.eval(RhinoCompiledScript.java:68)
at javax.script.CompiledScript.eval(CompiledScript.java:92)
at org.apache.synapse.mediators.bsf.ScriptMediator.mediateForInlineScript(ScriptMediator.java:395)
at org.apache.synapse.mediators.bsf.ScriptMediator.invokeScript(ScriptMediator.java:290)
at org.apache.synapse.mediators.bsf.ScriptMediator.mediate(ScriptMediator.java:258)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:109)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:71)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:228)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:375)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:434)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:182)
at org.apache.axis2.transport.base.threads.NativeWorkerPool.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.mozilla.javascript.EcmaError: TypeError: Cannot call method "info" of undefined (#3)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3687)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3665)
at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3693)
at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3712)
at org.mozilla.javascript.ScriptRuntime.undefCallError(ScriptRuntime.java:3731)
at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2258)
at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2251)
at org.mozilla.javascript.gen._Unknown_Source__19._c_script_0(:3)
at org.mozilla.javascript.gen._Unknown_Source__19.call()
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:394)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3091)
at org.mozilla.javascript.gen._Unknown_Source__19.call()
at org.mozilla.javascript.gen._Unknown_Source__19.exec()
at com.sun.phobos.script.javascript.RhinoCompiledScript.eval(RhinoCompiledScript.java:55)
... 16 more
这是我写的小eg简单代理:
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="changeStatus" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<endpoint name="endpoint_urn_uuid_97b72a79-6507-4b7b-9d46-1d3e6e07931c">
<address uri="[MY HTTP REST SERVICE]">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</address>
</endpoint>
<inSequence>
<script language="js"><![CDATA[var plInput = mc.getPayloadJSON();
log.info("Log messaggio ricevuto: "+ JSON.stringify(plInput));
var localRespinta = true;
var localConclusa = true;
if (plInput.stato == 1)
{
localRespinta = false;
localConclusa = false;
}
if (plInput.stato == 2)
{
localRespinta = false;
localConclusa = true;
}
if (plInput.stato == 3)
{
localRespinta = false;
localConclusa = true;
}
var log = mc.getServiceLog();
var keys = Object.keys(plInput);
var response =
{
"key": plInput.key,
"id": plInput.id,
"motivo": plInput.motivo,
"respinta": localRespinta,
"conclusa": localConclusa
};
log.info("Logging inside Script Mediator"+JSON.stringify(response));
mc.setPayloadJSON(response);]]></script>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</target>
</proxy>
有人可以帮我吗?
好吧,我自己从未使用过 WSO2,但让我们看一下您收到的错误消息。是这样的:
TypeError: Cannot call method "info" of undefined (#3) in at line number 3
错误似乎很清楚。您正试图在 undefined
上调用 info
方法,但您不能在 undefined
.
上调用方法
让我们看一下脚本的第 3 行,错误告诉我们问题所在:
log.info("Log messaggio ricevuto: "+ JSON.stringify(plInput));
这里肯定调用了info
方法。因此 log
必须未定义。
在你的脚本的第 1 行有一个名为 mc
的变量,我看不到它的定义,但是由于你的脚本超过了那一行,mc
必须是 WSO2 定义的变量你。但是,查看脚本的其余部分,我看到底部有以下行:
var log = mc.getServiceLog();
所以看起来 log
不是 WSO2 为你定义的东西。这是您在脚本中定义的东西,问题是您试图在定义之前使用它。
因此,解决方法是将声明 log
的行移动到第 3 行上方,以便您的代码部分如下所示:
var log = mc.getServiceLog();
log.info("Log messaggio ricevuto: "+ JSON.stringify(plInput));
我正在尝试在 wso2 中编写一个代理,给定一个 jason 格式的输入,调用一个签名略有不同的网络服务。我写了一个 Javascript 函数来执行转换,但我收到以下错误消息:
[2021-10-23 14:21:14,520] ERROR {ScriptMediator} - {proxy:cambioStatoPratica} The script engine returned an error executing the inlined js script function mediate com.sun.phobos.script.util.ExtendedScriptException: org.mozilla.javascript.EcmaError: TypeError: Cannot call method "info" of undefined (#3) in at line number 3 at com.sun.phobos.script.javascript.RhinoCompiledScript.eval(RhinoCompiledScript.java:68) at javax.script.CompiledScript.eval(CompiledScript.java:92) at org.apache.synapse.mediators.bsf.ScriptMediator.mediateForInlineScript(ScriptMediator.java:395) at org.apache.synapse.mediators.bsf.ScriptMediator.invokeScript(ScriptMediator.java:290) at org.apache.synapse.mediators.bsf.ScriptMediator.mediate(ScriptMediator.java:258) at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:109) at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:71) at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158) at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:228) at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180) at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:375) at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:434) at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:182) at org.apache.axis2.transport.base.threads.NativeWorkerPool.run(NativeWorkerPool.java:172) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: org.mozilla.javascript.EcmaError: TypeError: Cannot call method "info" of undefined (#3) at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3687) at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3665) at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3693) at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3712) at org.mozilla.javascript.ScriptRuntime.undefCallError(ScriptRuntime.java:3731) at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2258) at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2251) at org.mozilla.javascript.gen._Unknown_Source__19._c_script_0(:3) at org.mozilla.javascript.gen._Unknown_Source__19.call() at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:394) at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3091) at org.mozilla.javascript.gen._Unknown_Source__19.call() at org.mozilla.javascript.gen._Unknown_Source__19.exec() at com.sun.phobos.script.javascript.RhinoCompiledScript.eval(RhinoCompiledScript.java:55) ... 16 more
这是我写的小eg简单代理:
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="changeStatus" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<endpoint name="endpoint_urn_uuid_97b72a79-6507-4b7b-9d46-1d3e6e07931c">
<address uri="[MY HTTP REST SERVICE]">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</address>
</endpoint>
<inSequence>
<script language="js"><![CDATA[var plInput = mc.getPayloadJSON();
log.info("Log messaggio ricevuto: "+ JSON.stringify(plInput));
var localRespinta = true;
var localConclusa = true;
if (plInput.stato == 1)
{
localRespinta = false;
localConclusa = false;
}
if (plInput.stato == 2)
{
localRespinta = false;
localConclusa = true;
}
if (plInput.stato == 3)
{
localRespinta = false;
localConclusa = true;
}
var log = mc.getServiceLog();
var keys = Object.keys(plInput);
var response =
{
"key": plInput.key,
"id": plInput.id,
"motivo": plInput.motivo,
"respinta": localRespinta,
"conclusa": localConclusa
};
log.info("Logging inside Script Mediator"+JSON.stringify(response));
mc.setPayloadJSON(response);]]></script>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</target>
</proxy>
有人可以帮我吗?
好吧,我自己从未使用过 WSO2,但让我们看一下您收到的错误消息。是这样的:
TypeError: Cannot call method "info" of undefined (#3) in at line number 3
错误似乎很清楚。您正试图在 undefined
上调用 info
方法,但您不能在 undefined
.
让我们看一下脚本的第 3 行,错误告诉我们问题所在:
log.info("Log messaggio ricevuto: "+ JSON.stringify(plInput));
这里肯定调用了info
方法。因此 log
必须未定义。
在你的脚本的第 1 行有一个名为 mc
的变量,我看不到它的定义,但是由于你的脚本超过了那一行,mc
必须是 WSO2 定义的变量你。但是,查看脚本的其余部分,我看到底部有以下行:
var log = mc.getServiceLog();
所以看起来 log
不是 WSO2 为你定义的东西。这是您在脚本中定义的东西,问题是您试图在定义之前使用它。
因此,解决方法是将声明 log
的行移动到第 3 行上方,以便您的代码部分如下所示:
var log = mc.getServiceLog();
log.info("Log messaggio ricevuto: "+ JSON.stringify(plInput));