2

我正在使用 CXf 的故障输出拦截器来拦截来自 Web 服务方法的异常。这在 handleMessage 方法中运行良好。
现在我有两个问题,

  1. 除了设置故障代码外,我如何获得故障对象的额外信息?

假设在handleMessage 方法中有任何错误,控制转到handleFault 方法,但在handle fault 方法中它只是展开并记录类似的内容——GetMth 抛出异常,现在展开:java.lang.Exception。但是错误消息(xml格式)没有作为输出消息发送到客户端,

    2. 如何确保故障消息作为 SOAPfault 发送到客户端?(在下面的hanldeMessage中,我有地方`f=null`来介绍故障)请指教!!!

我设法使用以下代码将 xml 内容写入编写器类,但无法将此消息传递给客户端。我的意思是即使在将消息写入 xmlwriter 类并且内容被很好地写入控制台日志之后,它也没有被发送到客户端。即,当我打开监视器和拦截器出站日志时,我看不到出站消息正在发送或打印。谁能帮我解决这个问题?

            MessageFactory factory = getFactory(message); 
            SOAPMessage soapMessage = factory.createMessage(); 
            SOAPPart soapPart = soapMessage.getSOAPPart(); 
            SOAPBody soapBody = soapPart.getEnvelope().getBody();   
            SOAPFault soapFault = soapBody.addFault();   
            soapFault.setFaultString("Strange"); 
            W3CDOMStreamWriter writer1 = new SAAJStreamWriter(soapPart); 
            message.setContent(XMLStreamWriter.class, writer1); 
            message.setContent(SOAPMessage.class, soapMessage); 
            message.setContent(Node.class, soapMessage.getSOAPPart()); 
            message.getInterceptorChain().add(SAAJOutEndingInterceptor.INSTANCE);

日志:

saaj the factory com.sun.xml.messaging.saaj.soap.ver1_2.SOAPMessageFactory1_2Impl@146ee9c 
saaj the soapMessage  com.sun.xml.messaging.saaj.soap.ver1_2.Message1_2Impl@1db52c8 
saaj the soapPart  com.sun.xml.messaging.saaj.soap.ver1_2.SOAPPart1_2Impl@17d6c1 
saaj the soapsoapBodyPart  [env:Body: null] 
saaj the soapFault  [env:Fault: null] 
saaj the setFaultString  Strange 
saaj the messg  {org.apache.cxf.message.Message.RESPONSE_CODE=200, HTTP.RESPONSE=org.apache.catalina.connector.ResponseFacade@2982bf, org.apache.cxf.headers.Header.list=[], wrote.envelope.start=true, org.apache.cxf.message.Message.ENCODING=UTF-8, org.apache.cxf.message.FaultMode=CHECKED_APPLICATION_FAULT, org.apache.cxf.binding.soap.SoapVersion=org.apache.cxf.binding.soap.Soap12@b16f5f, Content-Type=application/soap+xml, org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor.original.xml.writer=[StreamWriter: class com.ctc.wstx.sw.SimpleNsStreamWriter, underlying outputter: com.ctc.wstx.sw.BufferingXmlWriter@1144823], org.apache.cxf.interceptor.LoggingOutInterceptor.log-setup=true, org.apache.cxf.service.model.BindingFaultInfo=org.apache.cxf.service.model.BindingFaultInfo@106def2} 
saaj the writer1 :   
><pre><env:Header/><env:Body><env:Fault><env:Code><env:Value>env:Receiver</env:Value></env:Code><env:Reason><env:Text xml:lang="en-US">Strange</env:Text></env:Reason></env:Fault></env:Body>  </pre>

请指教。

4

0 回答 0