简体   繁体   中英

CXF webservice : interceptor not triggered

We currently have a problem with CXF 2.7.3 on Jboss EAP 6.2 with a custom SoapFault exception.

The Subcode and its value is not displayed when we send a custom SoapFault:

Here is what we want from 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>

Here is what we have so far:

<?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>

The subcode is completely missing.

We tried to use a custom interceptor (extending from LoggingOutInterceptor or AbstractInterceptor) from CXF like this to intercept the custom fault:

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());
                 }

        }

}

The interceptor is not even called when we add him either to CXF bus or to jaxws interceptor (it's added at the start of the application though since it gets through the constructor). How can we intercept a custom soap Fault message and edit it in CXF?

Thanks a lot!

As asked here's the way we declare the interceptor in 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>

Note : the interceptor is well instancied, but not called after a soap fault throw from our WS

The exception thrown at the end of our WS is this one :

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;
    }

The problem that your interceptor is not called is that you do not override the correct method. You should have your code like this:

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

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

    }

Then your interceptor will be called. But as I said in my comment: in case of a fault the soapmessage is null. So you won't get any output in your log.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM