簡體   English   中英

CXF Web服務:攔截器未觸發

[英]CXF webservice : interceptor not triggered

當前,我們在Jboss EAP 6.2上遇到CXF 2.7.3的問題,並帶有一個自定義的SoapFault異常。

當我們發送自定義的SoapFault時,不會顯示子代碼及其值:

這是我們想要的cxf:

<?xml version="1.0" encoding="UTF-8"?>
<tns:Fault 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:tns="http://www.w3.org/2003/05/soap-envelope">
   <tns:Code>
       <tns:Value>tns:Sender</tns:Value>
       <tns:Subcode>
          <tns:Value>value</tns:Value>
       </tns:Subcode>
   </tns:Code>
   <tns:Reason>
       <tns:Text xml:lang="fr">
****
       </tns:Text>
   </tns:Reason>
   <tns:Detail>
**Custom fault***
   </tns:Detail>
</tns:Fault>

到目前為止,這里是:

<?xml version="1.0" encoding="UTF-8"?>
<tns:Fault 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:tns="http://www.w3.org/2003/05/soap-envelope">
   <tns:Code>
       <tns:Value>tns:Sender</tns:Value>
   </tns:Code>
   <tns:Reason>
       <tns:Text xml:lang="fr">
****
       </tns:Text>
   </tns:Reason>
   <tns:Detail>
**Custom fault***
   </tns:Detail>
</tns:Fault>

子代碼完全丟失。

我們嘗試使用來自CXF的自定義攔截器(從LoggingOutInterceptor或AbstractInterceptor擴展)來攔截自定義錯誤:

public class SoapRequestInterceptor extends LoggingOutInterceptor  {

        private static Logger log = Logger.getLogger(SoapRequestInterceptor.class);

    public SoapRequestInterceptor() {
        super(Phase.MARSHAL);

    }

        public void handleMessage(SoapMessage message) throws Fault{
                 SoapMessage soapMessage =  message.getContent(SoapMessage.class);

                 if (soapMessage != null) {
                     log.info( "request intercepted:" + soapMessage.toString());
                 }

        }

}

當我們將他添加到CXF總線或jaxws攔截器時,甚至都不會調用該攔截器(它是在應用程序開始時添加的,盡管它是通過構造函數獲得的)。 我們如何截獲自定義的Soap Fault消息並在CXF中對其進行編輯?

非常感謝!

正如所問的那樣,這是我們在spring applicationContext.xml中聲明攔截器的方式:

<cxf:bus>
        <cxf:outFaultInterceptors>
            <ref bean="soapRequestInterceptor" />
        </cxf:outFaultInterceptors>
    </cxf:bus>

    <bean id="soapRequestInterceptor" class="fr.test.SoapRequestInterceptor" />

    <jaxws:server serviceClass="fr.test.PriseEnChargeB2ServiceSP"
        address="" serviceBean="#service">
        <jaxws:binding>
            <soap:soapBinding version="1.2" mtomEnabled="true" />
        </jaxws:binding>
    </jaxws:server>

注意:攔截器的實例很好,但是從我們的WS拋出肥皂故障后沒有調用

在我們的WS末尾拋出的異常是這個:

public class PecSoapFaultException extends SoapFault {

    private static final long serialVersionUID = 1L;

    public TypeErreur erreur;

    public PecSoapFaultException(String message, TypeErreur structure) {
        super(message, new QName(""));
        this.erreur = structure;
    }

    public PecSoapFaultException(String message, TypeErreur structure, QName faultcode) {
        super(message, faultcode);
        this.erreur = structure;
    }

    public PecSoapFaultException(String message, TypeErreur structure, QName faultcode,
            QName subcode) {
        super(message, faultcode);

        this.setSubCode(subcode);
        this.erreur = structure;
    }

    public TypeErreur getFaultInfo() {
        return erreur;
    }

沒有調用攔截器的問題是您沒有覆蓋正確的方法。 您應該具有如下代碼:

    @Override
    public void handleMessage(Message message) throws Fault {
        SoapMessage soapMessage =  message.getContent(SoapMessage.class);

        if (soapMessage != null) {
            log.info( "request intercepted:" + soapMessage.toString());
        }

    }

然后您的攔截器將被調用。 但是正如我在評論中所說:如果發生故障,soapmessage為空。 因此,您將不會在日志中獲得任何輸出。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM