我收到需要解码的base64流。 我正在做一些研究,但是我被卡住了,这是我的代码:
<outSequence>
<property name="cadena" value="Hola mundo" scope="default" type="STRING"/>
<property name="cadena64"
expression="base64Encode(get-property('cadena'))"
scope="default"
type="STRING"/>
<property
name="cadenaASCII"
expression="syn:base64Decode(syn:get-property('cadena64'))"
scope="default"
type="STRING"/>
<payloadFactory media-type="json">
<format>
{"cadena":"$1",
"cadena64":"$2",
"cadenaASCII":"$3",
}
</format>
<args>
<arg evaluator="xml" expression="get-property('cadena')"/>
<arg evaluator="xml" expression="get-property('cadena64')"/>
<arg evaluator="xml" expression="get-property('cadenaASCII')"/>
</args>
</payloadFactory>
<send/>
</outSequence>
我通过取消注释该行来启用Xpath 2.0
synapse.xpath.dom.failover.enabled=true
位于$ ESB_HOME / repository / conf目录中(并重新启动服务)。
这是我得到的错误:
Evaluation of the XPath expression syn:base64Decode(syn:get-property('cadena64')) resulted in an error More TID[-1234] [ESB] [2019-03-04 19:27:23,359] ERROR {org.apache.synapse.util.xpath.SynapseXPath} - Evaluation of the XPath expression syn:base64Decode(syn:get-property('cadena64')) resulted in an error net.sf.saxon.xpath.XPathEvaluator.compile(XPathEvaluator.java:378) org.apache.synapse.util.xpath.SynapseXPath.evaluateDOMXPath(SynapseXPath.java:529) org.apache.synapse.util.xpath.SynapseXPath.stringValueOf(SynapseXPath.java:364) org.apache.synapse.mediators.builtin.PropertyMediator.getResultValue(PropertyMediator.java:302) org.apache.synapse.mediators.builtin.PropertyMediator.mediate(PropertyMediator.java:96) org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77) org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47) org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131) org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:268) org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:488) org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:170) org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180) org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:225) org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) java.lang.Thread.run(Thread.java:745)
答案 0 :(得分:1)
您引用的错误包含格式不正确的堆栈跟踪:
Evaluation of the XPath expression syn:base64Decode(syn:get-property('cadena64')) resulted in an error
More TID[-1234] [ESB] [2019-03-04 19:27:23,359] ERROR {org.apache.synapse.util.xpath.SynapseXPath} -
Evaluation of the XPath expression syn:base64Decode(syn:get-property('cadena64')) resulted in an error
net.sf.saxon.xpath.XPathEvaluator.compile(XPathEvaluator.java:378)
org.apache.synapse.util.xpath.SynapseXPath.evaluateDOMXPath(SynapseXPath.java:529)
....
这给了我们一些信息,但没有我们想要的那么多。它告诉我们Saxon正在评估XPath表达式,并且告诉我们Saxon正在报告该表达式中的静态错误。它还告诉我们这是Saxon的较旧版本,因为至少在Saxon 9.6之后的版本中,类XPathEvaluator包含大约330行。它并没有告诉我们错误实际上是什么。
诊断错误似乎是Apache突触的原因。
恐怕这只是回答问题的一小步,但我希望这些信息对某人有用。
答案 1 :(得分:1)
我认为在4.8.1中仅支持/实现编码,否则如前所述,可以选择升级esb。以下内容在4.8.1中对我有用
<property name="contentBase64" expression="//t:Content" scope="default" type="STRING"/>
<script language="js"><![CDATA[importPackage(Packages.org.apache.commons.codec.binary); var log = mc.getServiceLog(); log.info("1");var c = mc.getProperty("contentBase64");log.info("2:"+c);var bc = Base64.decodeBase64(c);log.info("3:"+bc); var result = ""; for(var i = 0; i
< bc.length; ++i){ result+= (String.fromCharCode(bc[i])); } log.info("result:"+result); mc.setProperty("contentDecoded", result);]]></script>
可以在属性“ contentDecoded”中访问已解码的内容。
希望有帮助。
答案 2 :(得分:0)
您的代码在ESB 5.0.0中有效,因此那里没有帮助(但是升级将解决您的问题!)
我发现尽管Encode可以正常工作,但Decode却无法正常工作,我对此感到怀疑。如果没有base64Decode
,就没有syn:
可以尝试吗?