Hi,

The code above works without any problems:

public class SAAJCustomInterceptor extends 
AbstractPhaseInterceptor<SoapMessage> {

  public SAAJCustomInterceptor() {
                super(Phase.PRE_PROTOCOL);
        addAfter(SAAJInInterceptor.class.getName());
        }
        
        @Override
        public void handleMessage(SoapMessage message) throws Fault {
                System.out.println(message.getInterceptorChain());
                SOAPMessage soapMessage = message.getContent(SOAPMessage.class);
                try {
                        Node rootNode = 
soapMessage.getSOAPBody().getFirstChild();
                        DOMUtils.writeXml(rootNode, System.out);
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }

}

Perhaps your method removeNil() somehow breaks SOAPMessage.
Would recommend to test without this call.

Btw: for such transformations you can try CXF transformation feature 
(http://cxf.apache.org/docs/transformationfeature.html) or XSLT feature 
(http://cxf.apache.org/docs/xslt-feature.html). In this case you don't need 
your own interceptor at all and it will perform better.

Regards,
Andrei.


> -----Original Message-----
> From: kwu [mailto:[email protected]]
> Sent: Dienstag, 16. April 2013 02:32
> To: [email protected]
> Subject: Response data equals to null after SAAJInInterceptor handle
> message
> 
> Hi All,
> 
> I am writing an SAAJInInteceptor to manipulate the incoming response
> message. I want to trim all the empty elements specifically Calendar Objects
> because CXF is trying to parse an null object during unmarshalling.
> 
> I've added the interceptor to my factoryBean before creating the port
> 
> factoryBean.inInterceptors.add(new
> SAAJTrimEmptyElementsInInterceptor(cxfRequestData,
> excludeFromTrimOperationNames))
> factoryBean.create()
> 
> and returns the port created by factoryBean
> 
> in my interceptor class
> 
> public SAAJTrimEmptyElementsInInterceptor(CxfRequestData
> cxfRequestData, List<String> excludeOutboundRequests) {
>         super(Phase.PRE_PROTOCOL)
>         addAfter(SAAJInInterceptor.class.getName())
>         this.cxfRequestData = cxfRequestData
>         excludeFromTrimOperationNames = excludeOutboundRequests
>     }
> 
> @Override
>     void handleMessage(SoapMessage soapMessage) {
>         if(shouldTrimMessage(soapMessage)){
>             if (soapMessage.getContent(SOAPMessage.class) == null) {
>                 getSaajInInterceptor().handleMessage(soapMessage)
>             }
>             SOAPMessage msg = soapMessage?.getContent(SOAPMessage.class)
> 
>             SOAPBody body = msg?.SOAPBody
> 
>             body?.childElements?.each {
>                 if (it instanceof SOAPElement) {
>                     removeNil(it)
>                 }
>             }
>         }
>     }
> 
> where removeNil is a recursive method which trims the xsi:nil child nodes.
> 
> I println() the soap body at the beginning the method to make sure it's
> created and at the end of method to make ensure the method has worked.
> However, after this interceptor, my response data is all null.
> 
> Interceptor happens on this line of code.
> 
> def response = port.getData(some arguments)
> 
> If I remove the interceptor or the content my handleMessage, the response
> data comes back just fine. But, with println(), I can see the body message
> pass through the handleMessage method. I've tried a lot of things, including
> changing the Phase of the interceptor and none has worked.
> 
> Why is my soap message/response data disappearing? Please let me know
> what else I can provide to clarify my issue. Thanks!!
> 
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Response-
> data-equals-to-null-after-SAAJInInterceptor-handle-message-
> tp5726342.html
> Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to