You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Curious Mind <yo...@yahoo.com> on 2008/12/13 14:56:59 UTC
XML Response modification
Hi,
I am new to Apache CXF and I have one requirement wherein I have to modify
response XML generated by CXF webservice.
After going through documentation it seems interceptors could be useful fo
this, but I m not sure how to do it. Can someone help me with detailed
sample code for achieving this.
Any help really appreciated.
(I should be able to modify message before any encryption or signing of
message will be done.)
--
View this message in context: http://www.nabble.com/XML-Response-modification-tp20990405p20990405.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: XML Response modification
Posted by bschuette <bj...@schuetteonline.de>.
Thanks for your help!
Before i read your reply, i did a workaround and wrote a handler.
But to prove your solution, I just rewrote my interceptors.
It was enough to use
super( Phase.POST_PROTOCOL );
addBefore( WSS4JOutInterceptor.class.getName() );
in the constructor of my out-interceptor.
My corresponding in-interceptor is constructed using
super(Phase.PRE_PROTOCOL);
getAfter().add(WSS4JInInterceptor.class.getName());
This gives me the decrypted message ready for logging (or whatever).
Now as I got them working, I will stick to the interceptors and drop the
handler.
Greetings
Björn
dkulp wrote:
>
>
> This would be a bit tricky. If you are using the WSS4JOutInterceptor,
> the
> non-encrypted stuff would NEVER be in "stream" form.
>
> Most likely, what you need to do is write an interceptor that goes in the:
> Phase.POST_PROTOCOL;
> phase, but is before the
> WSS4JOutInterceptorInternal.class.getName()
> interceptor. (could probably do "setBefore("*");"
>
> In that interceptor, you should be able to do:
> SOAPMessage saaj = mc.getContent(SOAPMessage.class);
> to get it in SAAJ form, but prior to encryption. You could then log that
> anyway you want.
>
> Dan
>
>
>
> On Tuesday 16 December 2008 5:48:02 am bschuette wrote:
>> I have a similar problem, I need to log all outgoing messages before they
>> are encrypted and signed.
>> I tried to modify the shipped LoggingOutInterceptor within its
>> constructor:
>>
>> super( Phase.PRE_STREAM );
>> addBefore( StaxOutInterceptor.class.getName() );
>> addBefore( WSS4JOutInterceptor.class.getName() );
>>
>>
>> This does not seem to help. I have tried to use earlier phases with no
>> luck. I guess it has something to do with the callback mechanism and the
>> caching used by this interceptor?
>>
>> Any hints how I could solve my problem?
>>
>> Thanks!
>>
>> Björn
>>
>> dkulp wrote:
>> > On Monday 15 December 2008 1:41:03 pm Curious Mind wrote:
>> >> I have gone through that example and didnt found of much use. Anyways
>> I
>> >> have achieved my target using handler but I still think Interceptor
>> >> would have be better option. I really need example which can show how
>> to
>> >> play with XML Body Message.
>> >
>> > It kind of depends on what type of modifications you need to make.
>> >
>> > If you really need to make large structural modifications (kind of like
>> > ws-security that is encrypting things, adding headers, etc...), you
>> would
>> > probably use the SAAJOutInterceptor+YouInterceptor to work on the saaj
>> > model.
>> > Fairly similar to the JAX-WS handlers.
>> >
>> > If the modification can be done in a streaming manner (like namespace
>> > mapping
>> > or adding an element/attribute or similar), you would normally use an
>> > interceptor that would wrapper/replace the XMLStreamWriter or even the
>> > OutputStream with a new one that does the behavior you need.
>> >
>> > --
>> > Daniel Kulp
>> > dkulp@apache.org
>> > http://dankulp.com/blog
>
>
>
> --
> Daniel Kulp
> dkulp@apache.org
> http://dankulp.com/blog
>
>
--
View this message in context: http://www.nabble.com/XML-Response-modification-tp20990405p21051562.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: XML Response modification
Posted by Daniel Kulp <dk...@apache.org>.
This would be a bit tricky. If you are using the WSS4JOutInterceptor, the
non-encrypted stuff would NEVER be in "stream" form.
Most likely, what you need to do is write an interceptor that goes in the:
Phase.POST_PROTOCOL;
phase, but is before the
WSS4JOutInterceptorInternal.class.getName()
interceptor. (could probably do "setBefore("*");"
In that interceptor, you should be able to do:
SOAPMessage saaj = mc.getContent(SOAPMessage.class);
to get it in SAAJ form, but prior to encryption. You could then log that
anyway you want.
Dan
On Tuesday 16 December 2008 5:48:02 am bschuette wrote:
> I have a similar problem, I need to log all outgoing messages before they
> are encrypted and signed.
> I tried to modify the shipped LoggingOutInterceptor within its constructor:
>
> super( Phase.PRE_STREAM );
> addBefore( StaxOutInterceptor.class.getName() );
> addBefore( WSS4JOutInterceptor.class.getName() );
>
>
> This does not seem to help. I have tried to use earlier phases with no
> luck. I guess it has something to do with the callback mechanism and the
> caching used by this interceptor?
>
> Any hints how I could solve my problem?
>
> Thanks!
>
> Björn
>
> dkulp wrote:
> > On Monday 15 December 2008 1:41:03 pm Curious Mind wrote:
> >> I have gone through that example and didnt found of much use. Anyways I
> >> have achieved my target using handler but I still think Interceptor
> >> would have be better option. I really need example which can show how to
> >> play with XML Body Message.
> >
> > It kind of depends on what type of modifications you need to make.
> >
> > If you really need to make large structural modifications (kind of like
> > ws-security that is encrypting things, adding headers, etc...), you would
> > probably use the SAAJOutInterceptor+YouInterceptor to work on the saaj
> > model.
> > Fairly similar to the JAX-WS handlers.
> >
> > If the modification can be done in a streaming manner (like namespace
> > mapping
> > or adding an element/attribute or similar), you would normally use an
> > interceptor that would wrapper/replace the XMLStreamWriter or even the
> > OutputStream with a new one that does the behavior you need.
> >
> > --
> > Daniel Kulp
> > dkulp@apache.org
> > http://dankulp.com/blog
--
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog
Re: XML Response modification
Posted by bschuette <bj...@schuetteonline.de>.
Hi!
I have a similar problem, I need to log all outgoing messages before they
are encrypted and signed.
I tried to modify the shipped LoggingOutInterceptor within its constructor:
super( Phase.PRE_STREAM );
addBefore( StaxOutInterceptor.class.getName() );
addBefore( WSS4JOutInterceptor.class.getName() );
This does not seem to help. I have tried to use earlier phases with no luck.
I guess it has something to do with the callback mechanism and the caching
used by this interceptor?
Any hints how I could solve my problem?
Thanks!
Björn
dkulp wrote:
>
> On Monday 15 December 2008 1:41:03 pm Curious Mind wrote:
>> I have gone through that example and didnt found of much use. Anyways I
>> have achieved my target using handler but I still think Interceptor would
>> have be better option. I really need example which can show how to play
>> with XML Body Message.
>
> It kind of depends on what type of modifications you need to make.
>
> If you really need to make large structural modifications (kind of like
> ws-security that is encrypting things, adding headers, etc...), you would
> probably use the SAAJOutInterceptor+YouInterceptor to work on the saaj
> model.
> Fairly similar to the JAX-WS handlers.
>
> If the modification can be done in a streaming manner (like namespace
> mapping
> or adding an element/attribute or similar), you would normally use an
> interceptor that would wrapper/replace the XMLStreamWriter or even the
> OutputStream with a new one that does the behavior you need.
>
> --
> Daniel Kulp
> dkulp@apache.org
> http://dankulp.com/blog
>
>
--
View this message in context: http://www.nabble.com/XML-Response-modification-tp20990405p21030868.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: XML Response modification
Posted by Daniel Kulp <dk...@apache.org>.
On Monday 15 December 2008 1:41:03 pm Curious Mind wrote:
> I have gone through that example and didnt found of much use. Anyways I
> have achieved my target using handler but I still think Interceptor would
> have be better option. I really need example which can show how to play
> with XML Body Message.
It kind of depends on what type of modifications you need to make.
If you really need to make large structural modifications (kind of like
ws-security that is encrypting things, adding headers, etc...), you would
probably use the SAAJOutInterceptor+YouInterceptor to work on the saaj model.
Fairly similar to the JAX-WS handlers.
If the modification can be done in a streaming manner (like namespace mapping
or adding an element/attribute or similar), you would normally use an
interceptor that would wrapper/replace the XMLStreamWriter or even the
OutputStream with a new one that does the behavior you need.
--
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog
RE: XML Response modification
Posted by Curious Mind <yo...@yahoo.com>.
I have gone through that example and didnt found of much use. Anyways I have
achieved my target using handler but I still think Interceptor would have be
better option. I really need example which can show how to play with XML
Body Message.
--
View this message in context: http://www.nabble.com/XML-Response-modification-tp20990405p21019353.html
Sent from the cxf-user mailing list archive at Nabble.com.
RE: XML Response modification
Posted by Sean O'Callaghan <SE...@progress.com>.
Hi,
There is a configuration_interceptor sample in the samples directory of a CXF installation which may be of help to you. It shows a user interceptor and how to configure it.
Regards,
Seán.
-----Original Message-----
From: Curious Mind [mailto:yogeshcjadhav@yahoo.com]
Sent: 13 December 2008 13:57
To: users@cxf.apache.org
Subject: XML Response modification
Hi,
I am new to Apache CXF and I have one requirement wherein I have to modify
response XML generated by CXF webservice.
After going through documentation it seems interceptors could be useful fo
this, but I m not sure how to do it. Can someone help me with detailed
sample code for achieving this.
Any help really appreciated.
(I should be able to modify message before any encryption or signing of
message will be done.)
--
View this message in context: http://www.nabble.com/XML-Response-modification-tp20990405p20990405.html
Sent from the cxf-user mailing list archive at Nabble.com.