cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From R1ch <rich.ku...@gmail.com>
Subject Re: Adding Elements to WS-Security Header .... WSS4JOutInterceptor, SAAJOutInterceptor
Date Mon, 10 Aug 2009 17:08:13 GMT
Hi Mayank and thanks for the respone. Resending I dont think i hit reply all
last time

I tried what you suggested but I am getting a null pointer exception after
the line following
SOAPMessage soapMessage = message.getContent(SOAPMessage.*class*);
that is, the soapMessage is null.

I think this is due to the fact that

WSS4JOutInterceptor.handleMessage(SoapMessage mc)
      if (mc.getContent(SOAPMessage.class) == null) {
            saajOut.handleMessage(mc);
}

if you look inside saajOut.handleMessage(mc) this is what creates the
soapMessage when the getContent returns null.
This is what i was referring to in my example 1) below. So I went with
example 2) the internal interceptor.
I guess i can try and explicitly add the SAAJOutInterceptor to the endpoint
but the documentation says
it is not needed in CXF 2.1+



On Mon, Aug 10, 2009 at 1:11 AM, Mayank Mishra <mayankm01@gmail.com> wrote:

> Hi,
>
> You can always extend WSS4JOutInterceptor and customize the behavior. But I
> would rather do something like below,
>
> class MyCustomInterceptor extends AbstractPhaseInterceptor{
>
> public MyCustomInterceptor(){
> super();
> setPhase(Phase.*PRE_PROTOCOL*);
> getAfter().add(SAAJOutInterceptor.*class*.getName());
> getBefore().add(WSS4JOutInterceptor.*class*.getName());
> }
> public void handleMessage(SoapMessage message) throws Fault{
>
> SOAPMessage soapMessage = message.getContent(SOAPMessage.*class*);
>
> soapMessage.getSOAPBody().addChildElement(myElement());
> }
>
>
> With Regards,
> Mayank
> On Fri, Aug 7, 2009 at 2:42 PM, R1ch <rich.kuali@gmail.com> wrote:
>
> > CXF 2.2 and WSS4J 1.5.8
> >
> > Hello all,
> > I have a working webservice configured with WSS4JOutInterceptor to insert
> a
> > signed SAML token.
> > Now I'm trying to insert an Element before the signature occurs so that
> my
> > Element is also signed.
> >
> > I tried two different ways and both are not resulting in what I need.
> >
> ==========================================================================
> > 1) did something similar to
> >
> > public class myInterceptor extends WSS4JOutInterceptor {
> >          handleMessage(SoapMessage mc) {
> >                    SOAPMessage soapMsg = myElement();
> >                    mc.setContent(SOAPMessage.class, soapMsg);
> >                    super.handleMessage(mc);
> >           }
> > }
> > this throws an exception, dont have it right now but can reproduce if
> some
> > needs to see it.
> > If I place the super.handleMessage(mc); before my code, (before the
> > myElement()) there is no error
> > but my element is not in the final soap message.
> >
> > Then I noticed that WSS4JOutInterceptor.handleMessage(SoapMessage mc) has
> > if (mc.getContent(SOAPMessage.class) == null) {
> >            saajOut.handleMessage(mc);
> > }
> > So I thought that I can't add SOAPMessage content. so I came up with the
> > next try
> >
> >
> ==========================================================================
> > 2) I did something almost exactly to what WSS4JOutInterceptor has, i.e
> use
> > an internal interceptor
> > with phase.USER_PROTOCOL. The WSS4JOutInterceptorInternal is
> > Phase.POST_PROTOCOL so i figured
> > if mine was before the post it would work.
> >
> > public class myInterceptor extends WSS4JOutInterceptor {
> >
> >          final class myInternal implements PhaseInterceptor<SoapMessage>
> {
> >                    handleMessage(SoapMessage mc) {
> >                             SOAPMessage soapMsg = myElement();
> >                             mc.setContent(SOAPMessage.class, soapMsg);
> >                             super.handleMessage(mc);
> >                     }
> >           }
> > }
> >
> > Well, my element is in the final SOAP message but it is not signed and my
> > <BODY> was actually empty
> > not what the webservice returns.
> >
> ==========================================================================
> >
> > So I was going to try and my Element to the message as XMLStreamWriter
> > content but I noticed that
> > SAAJOutInterceptor.handleMessage(SoapMessage message) replaces that with
> > W3CDOMStreamWriter
> >
> > 1. My first question is how do I get my element signed?
> > 2. What is the correct way to add content, is it mc.setContent() or do I
> > mc.getContent and add to that?
> > 3. What is the pupose of the Message Content Formats?
> > 4. When should I use SOAPMessage or XMLStreamWriter or any other format?
> > 5. If I put my content in the message for example as java.io.OutputStream
> > does it still get added to the final message?
> >
> > Thanks for your time.
> >
>

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