Under "normal" operation, the messages are streamed out on the wire as they 
are produced.  Thus, you cannot really "rewrite" them that way.   There are 
options, however, depending on how complex of a re-writing you need to do:

Options:
1) Usually highest performing, but usually harder to write and "transforms" 
usually have to be pretty simple:   Write your own XMLStreamWriter that 
wrappers the original writers and kind of filters the events.   This is 
generally useful for simple things like element renaming, string munging, 
namespace re-mapping, etc.... that can be done in a streaming manner.

2) Next best option:   configure in the SAAJOutInterceptor and in POST-
MARSHALL, grab the SoapMessage out of the message and manipulate it as a DOM.   
This allows more complex things like XSLT transforms, etc...., but does keep 
the message in memory instead of streaming.   

3) If you need to operate at the stream level, you would need to register an 
interceptor (that runs before StaxOutInterceptor) that replaces the 
OutputStream with something that would buffer the output (like a 
ByteArrayOutputStream, but our CachedOutputStream is probably better) and then 
stick an interceptor at the end that would take the buffer, do whatever 
transform is needed, and write it to the original output stream.

Hope that helps.


Dan


On Wed August 19 2009 7:09:44 am Hartmut Lang wrote:
> Hi,
>
> We have the need to modify some of the soap messages that are generated
> by CXF.
> The idea is to use an OutInterceptor.
> Is there an example how such an interceptor should work, if it has to
> change the soap-message in the POST_MARSHALL phase.
>
> Our approach was to rewrite the outputstream of the message. But the
> problem here is the "HTTPConduit.WrappedOutputStream" that is used.
> We found no way to overwrite the content that is already in that stream.
>
> Is rewriting the stream the right approach?
> Any ideas, examples on that?
>
> Thanks,
> Hartmut

-- 
Daniel Kulp
[email protected]
http://www.dankulp.com/blog

Reply via email to