我在调用中介上面临“blocking = true”的问题。 当被调用的后端端点返回404时(因为在REST获取时无法找到数据),将返回堆栈跟踪并且序列因此堆栈跟踪而失败:
[2016-04-18 12:49:20,303] INFO - HTTPSender Unable to sendViaGet to url[http://api.vidal.fr:80/rest/imd/package/412849-1862-2/lppr?app_id=0c117950&app_key=f6657d21b96e5e86ff1758be84618459]
org.apache.axis2.AxisFault: Transport error: 404 Error: Introuvable
at org.apache.axis2.transport.http.HTTPSender.handleResponse(HTTPSender.java:331)
at org.apache.axis2.transport.http.HTTPSender.sendViaGet(HTTPSender.java:105)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:63)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:451)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:278)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:430)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:225)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:149)
at org.apache.synapse.message.senders.blocking.BlockingMsgSender.sendReceive(BlockingMsgSender.java:254)
at org.apache.synapse.message.senders.blocking.BlockingMsgSender.send(BlockingMsgSender.java:175)
at org.apache.synapse.mediators.builtin.CallMediator.handleBlockingCall(CallMediator.java:113)
at org.apache.synapse.mediators.builtin.CallMediator.mediate(CallMediator.java:85)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:81)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:48)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:149)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:214)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:81)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:48)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:149)
at org.apache.synapse.mediators.eip.Target.mediate(Target.java:106)
at org.apache.synapse.mediators.eip.splitter.IterateMediator.mediate(IterateMediator.java:163)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:81)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:261)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.mediateFromContinuationStateStack(Axis2SynapseEnvironment.java:679)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:244)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:529)
at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:172)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:247)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
即使我尝试传递该参数: 因为它在HttpSender中从String转换为Set(!!)失败了:
Set<Integer>nonErrorCodes = (Set<Integer>) msgContext.getProperty(HTTPConstants.NON_ERROR_HTTP_STATUS_CODES);
这是我的调用中介,当端点响应404时抛出异常:
<property value="404" name="non.error.http.status.codes" scope="axis2" type="STRING" />
<call blocking="true">
<endpoint key="xxxx" />
</call>
那么,如何才能在阻止通话中正确处理404响应代码?
由于
答案 0 :(得分:0)
您可以使用faultsequence来处理wso2 ESB中提到的错误。 falut序列也与其他序列相同。如果在调解过程中出现一些错误或 转发消息,将执行faultsequence。在您的方案中,您在ESB中使用REST api,并且可以在API配置中指定faultsequenc。 如果在调用该API时发生某些错误,则会将触发错误的消息委派给指定的故障序列。首先,您需要创建一个faultsequnce,然后您可以指定它 您的API配置出现故障。请参阅以下示例配置。
FaultSequence
<sequence name="sampleFaultSequence">
<makefault version="pox">
<reason expression="get-property('ERROR_MESSAGE')"/>
</makefault>
<send/>
</sequence>
API配置
<api xmlns="http://ws.apache.org/ns/synapse" name="testapi" context="/abcd">
<resource methods="POST GET" uri-template="/*" faultSequence="sampleFaultSequence">
<inSequence>
<call blocking="true">
<endpoint key="conf:/ep1"/>
</call>
<respond/>
</inSequence>
</resource>
</api>
您可以参考文档[1],[2]以获取有关Wso2 ESB中的错误处理的更多信息。 [1] - https://docs.wso2.com/display/ESB490/Error+Handling [2] - https://docs.wso2.com/display/ESB490/Sample+4%3A+Specifying+a+Fault+Sequence+with+a+Regular+Mediation+Sequence
感谢。