cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Atul Shinde <shinde_a...@rediffmail.com>
Subject RE: Problems when intercepting an outbound SOAP message
Date Tue, 06 Apr 2010 09:06:47 GMT

Hi,

You may want to refer below link. It suggest the use of handlers for logging
inbound and outbound messages.

http://gaob.blogspot.com/2010/03/use-soap-handler-to-intercept.html

Thanks,
Atul


Inma Marín wrote:
> 
> Hello,
> 
> We have been able to get the body of a SOAP Message, but then we cannot
> add a header within that SOAP Message. The point is that we need to do the
> following:
> 
> - Get the body of a SOAP Message.
> - Sign that body.
> - Add a header into the SOAP Message. That header has to include the
> signature previously calculated (over the body of the SOAP Message).
> 
> It is an application requirement, and we do need to do that, not
> WS-Security (although it could be similar...)... It is any way of doing
> such a processing?
> 
> Thank you very much in advance.
> 
> Regards,
> Inma.
> 
> 
> 
>> -----Mensaje original-----
>> De: Daniel Kulp [mailto:dkulp@apache.org]
>> Enviado el: martes, 30 de marzo de 2010 3:34
>> Para: users@cxf.apache.org
>> CC: Inma Marín
>> Asunto: Re: Problems when intercepting an outbound SOAP message
>> 
>> On Monday 29 March 2010 10:40:21 am Inma Marín wrote:
>> > Hi again,
>> >
>> > We are using CXF version 2.2.4 ... is it posible that the problem of
>> > intercepting the whole outbound SOAP message is related to that
>> version?
>> >
>> > Thank you very much in advance.
>> 
>> Should be irrelevant.   It's mostly a matter of where in the chain your
>> interceptor is ending up.   What I would suggest is in your interceptor,
>> do a:
>> 
>> System.out.println(message.getInterceptorChain());
>> 
>> to printout the chain and see where it is in relation to the
>> SAAJOutEndingInterceptor and the BareOutInterceptor or
>> DocLitOutInterceptor.
>> 
>> It would need to be before the first (SAAJ ending), but after the other
>> two.
>> 
>> Dan
>> 
>> 
>> >
>> > > -----Mensaje original-----
>> > > De: Inma Marín [mailto:inmaml@um.es]
>> > > Enviado el: lunes, 15 de marzo de 2010 19:47
>> > > Para: users@cxf.apache.org
>> > > Asunto: RE: Problems when intercepting an outbound SOAP message
>> > >
>> > > Hi Daniel,
>> > >
>> > > I am afraid I am not be able to get the complete soap message. It
>> should
>> > > be possible to get it, but I don't know how....  Do you know another
>> way
>> > > of getting the whole outbound soap message?
>> > >
>> > > Thank you very much in advance.
>> > >
>> > > Regards,
>> > > Inma.
>> > >
>> > > > -----Mensaje original-----
>> > > > De: Daniel Kulp [mailto:dkulp@apache.org]
>> > > > Enviado el: jueves, 11 de marzo de 2010 16:39
>> > > > Para: users@cxf.apache.org; Inma Marín
>> > > > Asunto: Re: Problems when intercepting an outbound SOAP message
>> > > >
>> > > >
>> > > > The other important thing to note is that the SAAJOutInterceptor
>> is
>> > > > really two
>> > > > separate interceptors:
>> > > > 1) The "main" one that runs early to create the SAAJ object and
>> setup
>> > > > the
>> > > > XMLStreamWriter to write to it.
>> > > >
>> > > > 2) An "internal" one that runs late in the chain
>> (PRE_PROTOCOL_ENDING
>> > > > phase)
>> > > > to write the SAAJ model out to the stream.
>> > > >
>> > > > You're interceptor really needs to run immediately BEFORE the
>> second
>> > > > one.   At
>> > > > that point, the SAAJ model is completely constructed with the body
>> and
>> > > > everything.    Thus, you should be able to log that without
>> problem.
>> > > >
>> > > > If you  move your interceptor to the PRE_PROTOCOL_ENDING phase, it
>> > >
>> > > might
>> > >
>> > > > just
>> > > > work.
>> > > >
>> > > > Dan
>> > > >
>> > > > On Thursday 11 March 2010 6:08:39 am Eoghan Glynn wrote:
>> > > > > Hi Inma,
>> > > > >
>> > > > > I think what you're seeing on the outbound chain is a result
of
>> the
>> > > >
>> > > > lazy
>> > > >
>> > > > > creation of SAAJ message. Since creating the SOAPMessage is an
>> > > >
>> > > > expensive
>> > > >
>> > > > > operation, CXF is optimized so as not to create it unless we're
>> > > >
>> > > > certain
>> > > >
>> > > > > that this object is actually required.
>> > > > >
>> > > > > See for example the logic used by the JAX-WS
>> > >
>> > > SOAPHandlerInterceptor[1]
>> > >
>> > > > > which checks if the SAAJOutInterceptor has already been
>> traversed
>> > >
>> > > and
>> > >
>> > > > if
>> > > >
>> > > > > not, calls directly into SAAJOutInterceptor.handleMessage() to
>> > >
>> > > ensure
>> > >
>> > > > that
>> > > >
>> > > > > the SAAJ model is created.
>> > > > >
>> > > > > You could follow a similarly approach, or more simply just
>> ensure
>> > >
>> > > the
>> > >
>> > > > > SAAJOutInterceptor is in your outbound interceptor chain, and
be
>> > > >
>> > > > careful to
>> > > >
>> > > > > call:
>> > > > >     addAfter(SAAJOutInterceptor.class.getName());
>> > > > >
>> > > > > in your own interceptor's constructor so as to ensure its
>> traversed
>> > >
>> > > in
>> > >
>> > > > the
>> > > >
>> > > > > correct order.
>> > > > >
>> > > > > Cheers,
>> > > > > Eoghan
>> > > > >
>> > > > > [1]
>> > >
>> > >
>> http://svn.apache.org/repos/asf/cxf/trunk/rt/frontend/jaxws/src/main/jav
>> > >
>> > > > a/o
>> > > >
>> > > > > rg/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java
[2]
>> > >
>> > >
>> http://svn.apache.org/repos/asf/cxf/trunk/rt/bindings/soap/src/main/java
>> > >
>> > > > /or
>> > > >
>> > > > > g/apache/cxf/binding/soap/saaj/SAAJOutInterceptor.java
>> > > > >
>> > > > > On 11 March 2010 09:38, Inma Marín <inmaml@um.es> wrote:
>> > > > > > Hi all,
>> > > > > >
>> > > > > > I would like to know if somebody can help me in getting
a SOAP
>> > > >
>> > > > message
>> > > >
>> > > > > > using
>> > > > > > interceptors. I need to process the whole SOAP message...
>> > > > > >
>> > > > > > Thank you very much in advance.
>> > > > > >
>> > > > > > Regards,
>> > > > > > Inma.
>> > > > > >
>> > > > > > > -----Mensaje original-----
>> > > > > > > De: Inma Marín [mailto:inmaml@um.es]
>> > > > > > > Enviado el: martes, 09 de marzo de 2010 16:11
>> > > > > > > Para: users@cxf.apache.org
>> > > > > > > Asunto: Problems when intercepting an outbound SOAP
message
>> > > > > > >
>> > > > > > > Hello,
>> > > > > > >
>> > > > > > >
>> > > > > > >
>> > > > > > > I have a web service deployed and I need to deal with
SOAP
>> > > >
>> > > > messages
>> > > >
>> > > > > > > both inbound and outbound ones (I have to add some
headers,
>> but
>> > >
>> > > I
>> > >
>> > > > need
>> > > >
>> > > > > > > the whole
>> > > > > > > SOAP message (Envelope element) ). I have added two
>> > >
>> > > interceptors:
>> > > > one
>> > > >
>> > > > > > > for
>> > > > > > > inbound messages and other one for outbound messages
and, by
>> the
>> > > > > > > moment, they only print the SOAP message intercepted.
>> > > > > > >
>> > > > > > >
>> > > > > > >
>> > > > > > > As far as the inbound interceptor is concerned, it
extends
>> > > > > > > AbstractSoapInterceptor and is included in PRE_PROTOCOL
>> phase
>> > > >
>> > > > after
>> > > >
>> > > > > > > SAAJInInterceptor. Here, I managed to print the SOAP
>> Message,
>> > >
>> > > and
>> > >
>> > > > I get
>> > > >
>> > > > > > > the
>> > > > > > > whole message correctly.
>> > > > > > >
>> > > > > > >
>> > > > > > >
>> > > > > > > However, the outbound interceptor also extends
>> > > >
>> > > > AbstractSoapInterceptor
>> > > >
>> > > > > > > and
>> > > > > > > is included in Pre_protocol phase after SAAJOutInterceptor.
>> > >
>> > > Here,
>> > >
>> > > > I
>> > > >
>> > > > > > > managed
>> > > > > > > to print the SOAP Message, but I get the body element
>> empty!! ->
>> > > >
>> > > > The
>> > > >
>> > > > > > > client
>> > > > > > > receives a complete SOAP message, with element body
filled
>> in.
>> > > > > > >
>> > > > > > >
>> > > > > > >
>> > > > > > > I would like to know:
>> > > > > > >
>> > > > > > > 1)      If my interceptors extend correct class.
>> > > > > > >
>> > > > > > > 2)      If they are added in the correct phase (should
I add
>> an
>> > > >
>> > > > ending
>> > > >
>> > > > > > > interceptor to my outbound interceptor? Or is it better
to
>> > >
>> > > include
>> > >
>> > > > it
>> > > >
>> > > > > > > in POST_PROTOCOL phase?).
>> > > > > > >
>> > > > > > > 3)      Why I am not able to get a complete outbound
SOAP
>> > >
>> > > message
>> > >
>> > > > and
>> > > >
>> > > > > > > what
>> > > > > > > is the way of get it.
>> > > > > > >
>> > > > > > >
>> > > > > > >
>> > > > > > > I include my interceptors java code.
>> > > > > > >
>> > > > > > >
>> > > > > > >
>> > > > > > > ///////////////////////////////// INBOUND INTERCEPTOR
>> > > > > > > ///////////////////////////////////////
>> > > > > > >
>> > > > > > > public class InterceptorMensajeSOAPIn extends
>> > > >
>> > > > AbstractSoapInterceptor {
>> > > >
>> > > > > > >       private static Logger log =
>> > > > > > >
>> > > > > > > Logger.getLogger(InterceptorMensajeSOAPIn.class);
>> > > > > > >
>> > > > > > >       private SAAJInInterceptor saajIn = new
>> > >
>> > > SAAJInInterceptor();
>> > >
>> > > > > > >       public InterceptorMensajeSOAPIn(){
>> > > > > > >
>> > > > > > >             super(Phase.PRE_PROTOCOL);
>> > > > > > >
>> > > > > > >
>> getAfter().add(SAAJInInterceptor.class.getName());
>> > > > > > >
>> > > > > > >       }
>> > > > > > >
>> > > > > > >
>> > > > > > >
>> > > > > > >       public void handleMessage(SoapMessage message)
throws
>> > >
>> > > Fault
>> > >
>> > > > {
>> > > >
>> > > > > > >         SOAPMessage soapMessage = getSOAPMessage(message);
>> > > > > > >
>> > > > > > >         try {
>> > > > > > >
>> > > > > > >                   soapMessage.writeTo(System.out);
>> > > > > > >
>> > > > > > >             } catch (Exception e) {
>> > > > > > >
>> > > > > > >                   e.printStackTrace();
>> > > > > > >
>> > > > > > >             }
>> > > > > > >
>> > > > > > >       }
>> > > > > > >
>> > > > > > >
>> > > > > > >
>> > > > > > >       private SOAPMessage getSOAPMessage(SoapMessage
smsg){
>> > > > > > >
>> > > > > > >             SOAPMessage soapMessage =
>> > > > > > >
>> > > > > > > smsg.getContent(SOAPMessage.class);
>> > > > > > >
>> > > > > > >         if (soapMessage == null) {
>> > > > > > >
>> > > > > > >             saajIn.handleMessage(smsg);
>> > > > > > >
>> > > > > > >             soapMessage =
>> smsg.getContent(SOAPMessage.class);
>> > > > > > >
>> > > > > > >         }
>> > > > > > >
>> > > > > > >         return soapMessage;
>> > > > > > >
>> > > > > > >       }
>> > > > > > >
>> > > > > > > }
>> > > > > > >
>> > > > > > >
>> > > > > > >
>> > > > > > >
>> > > > > > >
>> > > > > > > ///////////////////////////////// OUTBOUND INTERCEPTOR
>> > > > > > > ///////////////////////////////////////
>> > > > > > >
>> > > > > > >
>> > > > > > >
>> > > > > > > public class InterceptorMensajeSOAPOut extends
>> > > >
>> > > > AbstractSoapInterceptor
>> > > >
>> > > > > > > {
>> > > > > > >
>> > > > > > >       private static Logger log =
>> > > > > > >
>> > > > > > > Logger.getLogger(InterceptorMensajeSOAPOut.class);
>> > > > > > >
>> > > > > > >       private SAAJOutInterceptor saajOut = new
>> > > >
>> > > > SAAJOutInterceptor();
>> > > >
>> > > > > > >       public InterceptorMensajeSOAPOut(){
>> > > > > > >
>> > > > > > >             super(Phase.PRE_PROTOCOL);
>> > > > > > >
>> > > > > > >
>> getAfter().add(SAAJOutInterceptor.class.getName());
>> > > > > > >
>> > > > > > >       }
>> > > > > > >
>> > > > > > >
>> > > > > > >
>> > > > > > >       public void handleMessage(SoapMessage message)
throws
>> > >
>> > > Fault
>> > >
>> > > > {
>> > > >
>> > > > > > >        SOAPMessage soapMessage = getSOAPMessage(message);
>> > > > > > >
>> > > > > > >         try {
>> > > > > > >
>> > > > > > >                   soapMessage.writeTo(System.out);
>> > > > > > >
>> > > > > > >             } 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;
>> > > > > > >
>> > > > > > >       }
>> > > > > > >
>> > > > > > > }
>> > > > > > >
>> > > > > > >
>> > > > > > >
>> > > > > > >
>> > > > > > >
>> > > > > > >
>> > > > > > >
>> > > > > > > Could you be so kind as to help me, please?
>> > > > > > >
>> > > > > > >
>> > > > > > >
>> > > > > > > Regards,
>> > > > > > >
>> > > > > > > Inma.
>> > > >
>> > > > --
>> > > > Daniel Kulp
>> > > > dkulp@apache.org
>> > > > http://dankulp.com/blog
>> 
>> --
>> Daniel Kulp
>> dkulp@apache.org
>> http://dankulp.com/blog
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Problems-when-intercepting-an-outbound-SOAP-message-tp27837050p28149123.html
Sent from the cxf-user mailing list archive at Nabble.com.


Mime
View raw message