On Tue May 5 2009 5:43:38 am Martin Renner wrote:
> Hi,
>
> just in case someone has to solve the same problem, here is how I did:
>
> Inbound:
>
> Added an interceptor to the phase POST_STREAM, after StaxInInterceptor.
> This interceptor takes the XMLStreamReader created by StaxInInterceptor and
> puts a wrapper around it. The wrapper translates the namespaces and sets a
> threadlocal flag.

Yep.   Perfect.

> Outbound:
> Added in interceptor to the phase PRE_MARSHAL. This interceptor takes the
> XMLStreamWriter created by StaxOutInterceptor and puts another wrapper
> around it. This outbound wrapper evaluates the threadlocal of the inbound
> wrapper and wraps the output accordingly.
>
> However, by default, CXF will write the outgoing SOAP message directly to
> the ServletOutputStream (see BareOutInterceptor.writeParts()). So I had to
> set the flag DISABLE_OUTPUTSTREAM_OPTIMIZATION in the outbound interceptor
> to force CXF to use the (wrapped) XMLStreamWriter instead of the output
> stream.
>
> This works quite nice. However, I am not quite sure about this output
> optimization. I could not find any documentation about the drawbacks when
> writing to a XMLStreamWriter instead of the OutputStream. Does someone have
> any hints about "DISABLE_OUTPUTSTREAM_OPTIMIZATION"?

Yea.  That's what is needed.  

Basically, JAXB is about 15% faster at writing directly to an output stream as 
compared to an XMLStreamWriter.   It does a bunch of optimizations to pre-
encode various UTF-8 things (like the namespaces, element names, etc...) that 
are not doable when outputting to the stax streams.   Thus, by default, we try 
to take advantage of that optimization if at all possible.    That flag allows 
it to be bypassed to go through stax.     That's needed for things like 
fastinfoset and json as well where it has to go through the stax writers.

Dan


>
> Regards,
> Martin
>
> > Hi,
> >
> > I have a web service (Soap 1.1, Document wrapped, JAXB) which uses the
> > namespace "http://something.old";. I would like to migrate this namespace
> > to "http://something.new";.
> >
> > Unfortunately, there are quite some clients out there which use my
> > service. So I cannot just switch the namespace with a new release of my
> > web service. Instead I would like to have a "smooth" transition.
> >
> > Some code would detect that a client is sending a document with the old
> > namespace. This code would rewrite the old namespace to the new namespace
> > before/while the document is being unmarshaled. Furthermore it would set
> > a thread local flag that namespace translation was used. Another piece of
> > code in the output chain would evaluate this flag and would rewrite the
> > new namespace to the old namespace, if the flag is set.
> >
> > This way, old clients would be able to send documents with the old
> > namespace and they would receive a response from the server with the old
> > namespace.
> >
> > Is this possible? Where do I have to start?
> >
> > I already looked into StaxInInterceptor and StaxOutInterceptor. I think
> > that it would be possible to put a wrapper around XMLStreamReader and
> > XMLStreamWriter, but this would be rather cumbersome (and slow?). Is
> > there an elegant solution to this problem?
> >
> > Regards,
> > Martin

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

Reply via email to