在WSO2 ESB中使用xquery脚本时,我收到以下错误。
[2015-06-05 14:28:55,983] WARN {TRACE_LOGGER} - ERROR_DETAIL :` org.apache.synapse.SynapseException: Unable to execute the query
at org.apache.synapse.mediators.xquery.XQueryMediator.handleException(XQueryMediator.java:649)
at org.apache.synapse.mediators.xquery.XQueryMediator.mediate(XQueryMediator.java:130)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:268)
at org.apache.synapse.mediators.builtin.LoopBackMediator.mediate(LoopBackMediator.java:42)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:166)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:411)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:183)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.synapse.SynapseException: Error during the querying Unexpected token "<eof>" in path expression
at org.apache.synapse.mediators.xquery.XQueryMediator.handleException(XQueryMediator.java:649)
at org.apache.synapse.mediators.xquery.XQueryMediator.performQuery(XQueryMediator.java:414)
at org.apache.synapse.mediators.xquery.XQueryMediator.mediate(XQueryMediator.java:123)
... 16 more
Caused by: javax.xml.xquery.XQException: Unexpected token "<eof>" in path expression
at net.sf.saxon.xqj.SaxonXQConnection.newXQException(SaxonXQConnection.java:195)
at net.sf.saxon.xqj.SaxonXQConnection.prepareExpression(SaxonXQConnection.java:143)
at net.sf.saxon.xqj.SaxonXQConnection.prepareExpression(SaxonXQConnection.java:128)
at org.apache.synapse.mediators.xquery.XQueryMediator.performQuery(XQueryMediator.java:284)
... 17 more
Caused by: net.sf.saxon.trans.XPathException: Unexpected token "<eof>" in path expression
at net.sf.saxon.query.QueryParser.grumble(QueryParser.java:417)
at net.sf.saxon.expr.parser.ExpressionParser.grumble(ExpressionParser.java:212)
at net.sf.saxon.expr.parser.ExpressionParser.grumble(ExpressionParser.java:199)
at net.sf.saxon.expr.parser.ExpressionParser.parseBasicStep(ExpressionParser.java:1839)
at net.sf.saxon.expr.parser.ExpressionParser.parseStepExpression(ExpressionParser.java:1654)
at net.sf.saxon.expr.parser.ExpressionParser.parseRelativePath(ExpressionParser.java:1573)
at net.sf.saxon.expr.parser.ExpressionParser.parsePathExpression(ExpressionParser.java:1557)
at net.sf.saxon.expr.parser.ExpressionParser.parseUnaryExpression(ExpressionParser.java:1447)
at net.sf.saxon.expr.parser.ExpressionParser.parseExprSingle(ExpressionParser.java:517)
at net.sf.saxon.expr.parser.ExpressionParser.parseExpression(ExpressionParser.java:455)
at net.sf.saxon.query.QueryParser.parseQuery(QueryParser.java:329)
at net.sf.saxon.query.QueryParser.makeXQueryExpression(QueryParser.java:140)
at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:536)
at net.sf.saxon.xqj.SaxonXQConnection.prepareExpression(SaxonXQConnection.java:138)
... 19 more
[2015-06-05 14:28:56,120] WARN {TRACE_LOGGER} - ERROR_EXCEPTION : org.apache.synapse.SynapseException: Unable to execute the query
[2015-06-05 14:28:56,120] WARN {SERVICE_LOGGER.PX_FungusTransform} - ERROR_CODE : 0 ERROR_MESSAGE : Unable to execute the query
[2015-06-05 14:28:56,120] WARN {TRACE_LOGGER} - FaultHandler : org.apache.synapse.mediators.MediatorFaultHandler@7803a7ad
[2015-06-05 14:28:56,124] WARN {TRACE_LOGGER} - Executing fault handler mediator : fault
[2015-06-05 14:28:56,125] WARN {SERVICE_LOGGER.PX_FungusTransform} - Executing fault sequence mediator : fault
[2015-06-05 14:28:56,126] INFO {TRACE_LOGGER} - Start : Sequence <fault>
[2015-06-05 14:28:56,166] INFO {TRACE_LOGGER} - Sequence <SequenceMediator> :: mediate()
[2015-06-05 14:28:56,166] INFO {TRACE_LOGGER} - Mediation started from mediator position : 0
[2015-06-05 14:28:56,166] INFO {TRACE_LOGGER} - Start : Log mediator
[2015-06-05 14:28:56,166] INFO {SERVICE_LOGGER.PX_FungusTransform} - To: , WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:
uuid:ce9a630d-7b46-4433-bc7a-65408c980461, Direction: response, MESSAGE = Executing default 'fault' sequence, ERROR_CODE = 0, ERROR_MESSAGE
= Unable to execute the query , Envelope: <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/s
oap-envelope"><soapenv:Body><fungi><fungus><name>Goldcap</name><cap>Yellow, White and Pearlescent</cap><stem>None</stem><gill>Smooth</gill><
toxin>Mercury comparable to Tuna/lb</toxin></fungus><fungus><name>Silvercap</name><cap>Blue, White and Pearlescent</cap><stem>Long and thin<
/stem><gill>Rough</gill><toxin>None</toxin></fungus></fungi></soapenv:Body></soapenv:Envelope>
[2015-06-05 14:28:56,180] INFO {TRACE_LOGGER} - To: , WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:ce9a630d-7b46-44
33-bc7a-65408c980461, Direction: response, MESSAGE = Executing default 'fault' sequence, ERROR_CODE = 0, ERROR_MESSAGE = Unable to execute t
he query , Envelope: <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapen
v:Body><fungi><fungus><name>Goldcap</name><cap>Yellow, White and Pearlescent</cap><stem>None</stem><gill>Smooth</gill><toxin>Mercury compara
ble to Tuna/lb</toxin></fungus><fungus><name>Silvercap</name><cap>Blue, White and Pearlescent</cap><stem>Long and thin</stem><gill>Rough</gi
ll><toxin>None</toxin></fungus></fungi></soapenv:Body></soapenv:Envelope>
[2015-06-05 14:28:56,202] INFO {TRACE_LOGGER} - End : Log mediator
[2015-06-05 14:28:56,202] INFO {TRACE_LOGGER} - Start : Drop mediator
[2015-06-05 14:28:56,202] INFO {TRACE_LOGGER} - End : Drop mediator
[2015-06-05 14:28:56,202] INFO {TRACE_LOGGER} - End : Sequence <fault>
xquery文件(也尝试作为第一行。)
<x><![CDATA[
declare namespace soapenv = "http://schemas.xmlsoap.org/soap/envelope";
declare variable $payload as element() external;
for $fungus in $payload/fungus
return {$fungus/name};
]]></x>
和代理
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="PX_FungusTransform"
transports="https,http"
statistics="disable"
trace="enable"
startOnLoad="true">
<target>
<inSequence>
<log level="full"/>
<loopback/>
</inSequence>
<outSequence>
<log level="full" category="TRACE"/>
<xquery key="xquery_fungusTransform">
<variable name="payload" type="ELEMENT"/>
</xquery>
<send/>
</outSequence>
</target>
<description/>
</proxy>
在研究这个问题时,我发现了这一点 https://wso2.org/jira/browse/CARBON-3081
我能够复制我系统上列出的问题,其中尝试添加包含上面列出的XQuery文件的本地条目导致“<![CData[
”和“]]>
”被任意删除。我假设我遇到的问题和这个问题是连接的(或者xml解析器有变化。)
有解决方法吗?还是补丁?
答案 0 :(得分:0)
你的XQuery无效,你不需要尾随的分号,你也不需要CDATA部分。你的序言也必须在你的查询之前来。尝试将其重写为:
declare namespace soapenv = "http://schemas.xmlsoap.org/soap/envelope";
declare variable $payload as element() external;
<x>
{
for $fungus in $payload/fungus
return
$fungus/name
}
</x>
此外,如果您的XML位于命名空间中,则需要将命名空间前缀添加到XPath中的元素名称。