Hi,

Just tested, this implementation works fine by me:

public class SAAJCustomInterceptor extends 
AbstractPhaseInterceptor<SoapMessage> {
        public SAAJCustomInterceptor() {
                super(Phase.POST_PROTOCOL);
        }
        
        @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);

                        SOAPEnvelope env = 
soapMessage.getSOAPPart().getEnvelope();
                        DOMUtils.writeXml(env, System.out);
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }
}

Could you double check is SAAJInInterceptor in chain?

Regards,
Andrei.


> -----Original Message-----
> From: Jay Prakash [mailto:[email protected]]
> Sent: Mittwoch, 20. August 2014 00:00
> To: [email protected]
> Subject: Unable to get SOAPBody in interceptor
> 
> Hello,
>        I've reading about CXF interceptor and I'm writing one currently which 
> will
> read parts of incoming SOAP request and log them (for now).
> 
> public class SampleInterceptor extends AbstractSoapInterceptor {
> 
>        public SampleInterceptor () {
> super(Phase.POST_PROTOCOL);
> addAfter(SAAJInInterceptor.class.getName());
> }
> 
>         @Override
> public void handleMessage(final SoapMessage message) throws Fault {
>                 final SOAPMessage saaj = 
> message.getContent(SOAPMessage.class);
> final SOAPBody document;
> try {
> document = saaj.getSOAPPart().getEnvelope().getBody();
> //document = saaj.getSOAPBody();
> } catch (final SOAPException e) {
> logger.error("", "Unable to get SOAP body from request", e); throw new
> Fault(e); }
>                 // log some nodes in the document.
>          }
> }
> 
> Also I've added the SAAJ interceptor to the incoming interceptor chain at the
> endpoint like this.
> 
> <jaxws:inInterceptors>
>         <bean id="saajInInterceptor"
> class="org.apache.cxf.binding.soap.saaj.SAAJInInterceptor"/>
>         <ref bean="sampleInterceptor"/>
>     </jaxws:inInterceptors>
> 
> The problem is that the document is coming out as null/empty (in both forms).
> 
> (com.sun.xml.internal.messaging.saaj.soap.ver1_1.Body1_1Impl)
> [soapenv:Body: null]
> 
> In debug mode I see that SAAJInInterceptor was executed in PRE_PROTOCOL
> phase and thus I am expecting a SAAJ model (also
> message.getContentFormats() shows SOAPMessage in it).
> 
> I'm using CXF 2.7.1 and I'd appreciate any pointers on why this is showing up 
> as
> empty.

Reply via email to