404 文件未找到异常的 WSO2 调解器处理程序

WSO2 Mediator Handler for 404 File not Found Exception

我正在使用 WSO2 4.8.1 wso2 ESB。

我开发了一个代理,我可以通过它向我的 tomcat 服务器转发请求。

我需要处理服务器发给我的"file not found exception"(状态码404),每次都要做一些操作。

这是代理的outSequence代码:

<sequence xmlns="http://ws.apache.org/ns/synapse" name="addBannedUrl">
   <property xmlns:ns="http://org.apache.synapse/xsd" name="responseStatus" expression="$axis2:HTTP_SC"></property>        
   <filter xmlns:ns="http://org.apache.synapse/xsd" source="get-property('responseStatus')" regex="404">
       <then>         
           <payloadFactory media-type="json">
               <format>         {         "codice":"403",         "message":"FORBIDDEN."         }      </format>
           </payloadFactory>   
           <class name="it.innovapuglia.diogene.integration.wso2.esb.GovernanceClient"></class>
       </then>
  </filter>
</sequence>

我很确定每次 tomcat 服务器返回的代码是 404 时 WSB 都会进入过滤器中介器,但是当它进入 payloadFactory 时会出现错误:

[2015-01-19 18:05:29,787] ERROR - FilterMediator Error while building message
org.apache.axiom.om.OMException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,956]
Message: Il tipo di elemento "HR" deve terminare con la corrispondente tag finale "</HR>".
    at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:296)
    at org.apache.axiom.om.impl.llom.OMSerializableImpl.build(OMSerializableImpl.java:78)
    at org.apache.axiom.om.impl.llom.OMElementImpl.build(OMElementImpl.java:722)
    at org.apache.axiom.om.impl.llom.OMElementImpl.detach(OMElementImpl.java:700)
    at org.apache.axiom.om.impl.llom.OMNodeImpl.setParent(OMNodeImpl.java:105)
    at org.apache.axiom.om.impl.llom.OMElementImpl.addChild(OMElementImpl.java:296)
    at org.apache.axiom.om.impl.llom.OMElementImpl.addChild(OMElementImpl.java:212)
    at org.apache.axiom.soap.impl.llom.SOAPBodyImpl.addChild(SOAPBodyImpl.java:231)
    at org.apache.axis2.transport.TransportUtils.createSOAPEnvelope(TransportUtils.java:161)
    at org.apache.synapse.transport.passthru.util.RelayUtils.builldMessage(RelayUtils.java:114)
    at org.apache.synapse.transport.passthru.util.RelayUtils.buildMessage(RelayUtils.java:82)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:68)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
    at org.apache.synapse.mediators.filters.FilterMediator.mediate(FilterMediator.java:160)
    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.mediators.base.SequenceMediator.mediate(SequenceMediator.java:196)
    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.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:488)
    at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:170)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
    at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:225)
    at org.apache.axis2.transport.base.threads.NativeWorkerPool.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:722)
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,956]
Message: Il tipo di elemento "HR" deve terminare con la corrispondente tag finale "</HR>".
    at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:598)
    at org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper.next(XMLStreamReaderWrapper.java:225)
    at org.apache.axiom.util.stax.dialect.DisallowDoctypeDeclStreamReaderWrapper.next(DisallowDoctypeDeclStreamReaderWrapper.java:34)
    at org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper.next(XMLStreamReaderWrapper.java:225)
    at org.apache.axiom.util.stax.dialect.SJSXPStreamReaderWrapper.next(SJSXPStreamReaderWrapper.java:138)
    at org.apache.axiom.om.impl.builder.StAXOMBuilder.parserNext(StAXOMBuilder.java:681)
    at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:214)
    ... 29 more

代码有什么问题?

难道是tomcat服务器的错误响应信息是这样的?

<html><head><title>Apache Tomcat/7.0.52 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 404 - Not Found</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>Not Found</u></p><p><b>description</b> <u>The requested resource is not available.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.52</h3></body></html>

...esb xml 解析器解析它有困难吗? 我怎样才能避免这个例外? 谢谢。

你应该能够理解这行提到的错误;

Message: Il tipo di elemento "HR" deve terminare con la corrispondente tag finale "</HR>".
    at c

BTW 你的后序逻辑对吗?我认为您需要将 class 冥想器放在 <then> 标签或 <else> 标签中。

编辑:您能否在 axis2.xml 中添加 text/html 消息生成器并检查。