Hi Kathy,

If you are working with DOM messages, you can use the similar technic as in CXF 
security interceptors (WSS4JOutInterceptor):

public class AuditOutInterceptor extends AbstractPhaseInterceptor<SoapMessage> {

        private final SAAJOutInterceptor saajOut = new SAAJOutInterceptor();
        private final AuditOutInterceptorEnding ending;

        public AuditOutInterceptor() {
                super(Phase.PRE_PROTOCOL);
                addAfter(SAAJOutInterceptor.class.getName());
                ending = new AuditOutInterceptorEnding();
        }

        @Override
        public void handleMessage(SoapMessage message) {
                if (null == message.getContent(SOAPMessage.class)) {
                        saajOut.handleMessage(message);
                }
                message.getInterceptorChain().add(ending);
        }

        public final static class AuditOutInterceptorEnding extends 
AbstractPhaseInterceptor<SoapMessage> {

                public AuditOutInterceptorEnding() {
                        super(Phase.POST_PROTOCOL);
                }

                @Override
                public void handleMessage(SoapMessage message) throws Fault {
                        // Access SOAP header and SOAP body here
                        }
           }
}


Regards,
Andrei.

-----Original Message-----
From: kstone [mailto:[email protected]] 
Sent: Mittwoch, 3. Oktober 2012 23:40
To: [email protected]
Subject: Need XML when intercepting an outbound SOAP message

All,
I am having the same issue as outlined in  this past post 
<http://www.mail-archive.com/[email protected]/msg13642.html>
I tried all of the suggestions there to no avail.

Our goal is to grab the outgoing xml from the SoapMessage and log to database 
for auditing purposes.
When I call getContent on the message, it is null. I have tried all phases 
listed below.
We have this working okay on the server side just not outgoing client 
Interceptor.

We are using JDK 1.6 under Grails/Groovy and grails cxf-client plugin

Could you please advise?
Thanks in advance!
Kathy

class ClientOutputMessageInterceptor extends AbstractSoapInterceptor {

    private SAAJOutInterceptor saajOut = new SAAJOutInterceptor()

    ClientOutputMessageInterceptor()
    {
        //http://www.mail-archive.com/[email protected]/msg13642.html,
should be after SAAJOutEndingInterceptor but before BareOutInterceptor
        // super(Phase.PRE_STREAM)//this phase had empty soap-env:header and 
soap-env:body elements

        super(Phase.PRE_PROTOCOL)//this phase had empty soap-env:header and 
soap-env:body elements

        //super(Phase.WRITE);//this phase had empty soap-env:header and 
soap-env:body elements
        //super(Phase.POST_PROTOCOL)//this phase had empty soap-env:header and 
soap-env:body elements
        //super(Phase.POST_STREAM)//this phase had empty soap-env:header and 
soap-env:body elements
        //super(Phase.SEND)//this phase had empty soap-env:header and 
soap-env:body elements
        //super(Phase.SETUP_ENDING)//this phase had empty soap-env:header and 
soap-env:body elements

        //addAfter(BareOutInterceptor.class.getName());
        addAfter().add(new SAAJOutInterceptor());
    }

    @Override
    public void handleMessage(SoapMessage message) throws Fault {
        System.out.println(message.getInterceptorChain())
        SOAPMessage soapMessage = message.getContent(SOAPMessage.class);

        if (soapMessage == null) {
            saajOut.handleMessage(message);
            soapMessage = message.getContent(SOAPMessage.class);
        }

        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            soapMessage.writeTo(baos);
            //baos has empty body

        } catch (Exception e) {
            e.printStackTrace();
        }
    }



    private SOAPMessage getSOAPMessage(SoapMessage smsg){

        SOAPMessage soapMessage =  smsg.getContent(SOAPMessage.class);
        if (soapMessage == null) {

             saajOut.handleMessage(smsg);
             soapMessage =  smsg.getContent(SOAPMessage.class);
        }

         return soapMessage;
       }
}


More info:
This is the PhaseInterceptorChain I see output. I do not see the 
SAAJOutInterceptor here at all.
I have also implemented a CustomLoggingOutInterceptor similar to the one 
here <https://github.com/ctoestreich/cxf-client#Out>   and this also is null
when calling getContent on the message. However, the CustomOutLogging 
Interceptor falls after [BareOutInterceptor] but before 
SAAJOutEndingInterceptor and still not able to grab XML.

  setup [PolicyOutInterceptor]
  pre-logical [HolderOutInterceptor, SwAOutInterceptor, 
WrapperClassOutInterceptor, SoapHeaderOutFilterInterceptor]
  post-logical [SoapPreProtocolOutInterceptor]
  prepare-send [MessageSenderInterceptor]
  pre-stream [LoggingOutInterceptor, AttachmentOutInterceptor, 
StaxOutInterceptor]
  pre-protocol [LmmClientOutputMessageInterceptor]
  write [SoapOutInterceptor]
  marshal [BareOutInterceptor]
  send [CustomLoggingOutInterceptor]
  pre-stream-ending [StaxOutEndingInterceptor]
  prepare-send-ending [MessageSenderEndingInterceptor]



--
View this message in context: 
http://cxf.547215.n5.nabble.com/Need-XML-when-intercepting-an-outbound-SOAP-message-tp5715588.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to