cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrei Shakirin <ashaki...@talend.com>
Subject RE: Logging clear-text message
Date Wed, 14 May 2014 16:24:46 GMT
Hi Giriraj,

As far as you use CXF 2.7.8, I would recommend to get and log SOAPMessage in your logging
interceptors.
WSS4J interceptors in CXF 2.7.8 activate SAAJ interceptors, preparing SOAPMessage.
As Dan said, it will be a bit complicated in CXF 3.0.0.

Following interceptors code logs clear text message by me in case of using WSS4J for encryption
in CXF 2.7.8:

public class LogClearTextOutInterceptor extends AbstractPhaseInterceptor<Message> {

    public LogClearTextOutInterceptor() {
        super(Phase.POST_PROTOCOL);
        getBefore().add(WSS4JOutInterceptor.class.getName());
    }

    @Override
    public void handleMessage(Message message) {
    	SOAPMessage soapMessage = message.getContent(SOAPMessage.class);
    	try {
    		System.out.println("out message: ");
			DOMUtils.writeXml(soapMessage.getSOAPBody(), System.out);
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
}


public class LogClearTextInInterceptor extends AbstractPhaseInterceptor<Message> {

    public LogClearTextInInterceptor() {
        super(Phase.POST_PROTOCOL);
        getAfter().add(WSS4JInInterceptor.class.getName());
    }

    @Override
    public void handleMessage(Message message) {
    	SOAPMessage soapMessage = message.getContent(SOAPMessage.class);
    	try {
    		System.out.println("In message: ");
			DOMUtils.writeXml(soapMessage.getSOAPBody(), System.out);
		} catch (Exception e) {
			e.printStackTrace();
		}
    }

}
...
        client.getOutInterceptors().add(new LogClearTextOutInterceptor());
        client.getInInterceptors().add(new LogClearTextInInterceptor());
...
        endpoint.getInInterceptors().add(new LogClearTextInInterceptor());
        endpoint.getInInterceptors().add(new LogClearTextOutInterceptor());

Regards,
Andrei.

> -----Original Message-----
> From: Giriraj Bhojak [mailto:giriraj2k@gmail.com]
> Sent: Dienstag, 13. Mai 2014 18:08
> To: Daniel Kulp
> Cc: users@cxf.apache.org
> Subject: Re: Logging clear-text message
> 
> Thank you Daniel and Andrei.
> Here is new interceptor I just wrote for outgoing messages:
> 
> import org.apache.cxf.interceptor.Fault; import
> org.apache.cxf.message.Message; import
> org.apache.cxf.phase.AbstractPhaseInterceptor;
> import org.apache.cxf.phase.Phase;
> import org.w3c.dom.Document;
> 
> public class LoggingOutInterceptor extends
> AbstractPhaseInterceptor<Message>  {
> 
>     public LoggingOutInterceptor() {
>         super(Phase.PRE_PROTOCOL);
>     }
> 
>     public void handleMessage(Message message) throws Fault {
> 
>         Document document = message.getContent(Document.class);
>     }
> 
> }
> 
> The document is null. While debugging I see that the actual object I am trying
> to send is in contents[] array of org.apache.cxf.message.MessageImpl.
> But I haven't been able to retrieve it yet. Any idea what I am doing wrong?
> 
> Thanks,
> Giriraj.
> 
> 
> 
> 
> On Tue, May 13, 2014 at 11:00 AM, Daniel Kulp <dkulp@apache.org> wrote:
> 
> >
> > The Logging interceptors run at a byte stream level and only would see the
> > “secured” message.   To log the unsecured message, you would need to write
> > a different interceptor to handle that.  Unfortunately, its also going
> > to be different for CXF 2.7.x and CXF 3.x due to changes in the
> > security handling.
> >
> > For 2.7.x, you can write an interceptor that would run after the
> > WSS4JInInterceptors that would do a:
> >
> > message.getContent(Document.class)
> >
> > and prints the DOM.    For 3.x with the new streaming security
> > interceptors, it would be way more complex.   You’d have to grab the
> > XMLStreamReader from the message, wrapper it with a new stream reader
> that
> > would then record the read events.   (the wrapped stream reader method
> > would also work for 2.7.x, but like I said, a bit more complex to
> > write)
> >
> > Dan
> >
> >
> >
> > On May 12, 2014, at 6:05 PM, Giriraj Bhojak <giriraj2k@gmail.com> wrote:
> >
> > > Hi,
> > >
> > > I am using cxf (2.7.8 )with wss4j(1.6.13).
> > > For the sake of debugging I need to see the outgoing messages.
> > > I have added cxf:inInterceptors and cxf:outInterceptors in the
> > > spring config.
> > > This helps me see the signed and encrypted message.
> > > Is there a way to see the clear-text version of the message?
> > > I have used JAXB marshaller to print the message but I am trying to
> > > avoid writing any code to see the message.
> > >
> > > Thanks,
> > > Giriraj.
> >
> > --
> > Daniel Kulp
> > dkulp@apache.org - http://dankulp.com/blog Talend Community Coder -
> > http://coders.talend.com
> >
> >
Mime
View raw message