cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eoghan Glynn <eogl...@gmail.com>
Subject Re: Problems when intercepting an outbound SOAP message
Date Thu, 11 Mar 2010 11:08:39 GMT
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/java/org/apache/cxf/jaxws/handler/soap/SOAPHandlerInterceptor.java
[2]
http://svn.apache.org/repos/asf/cxf/trunk/rt/bindings/soap/src/main/java/org/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.
> >
> >
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message