You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Todd Orr <to...@gmail.com> on 2008/03/01 20:01:58 UTC

REST CDATA Marshalling

I'm attempting to get String data wrapped in CDATA before being
returned to the client. I do not want special characters to be
escaped. First I tried simply wrapping the properties in my getters
with the CDATA block. Unfortunately, JAXB continued to escape all the
special characters.

I found this post:
http://forum.java.sun.com/thread.jspa?threadID=607524&messageID=3531931.
Although promising, I could not find out how to setup JAXB in my
applicationContext in such a way to set this as the XMLSerializer.

Has anyone accomplished this? It seems as though it would be a fairly
common need.

Thanks,
T

Re: REST CDATA Marshalling

Posted by Sergey Beryozkin <se...@iona.com>.
Hi,

One way would be to use a CXF JAX-RS implementation. I'm presuming no SOAP is involved as Todd is
asking about CDATA in a context of the REST application, right ?
If so, then with JAX-RS one can just return a String which uses CData to encapsulate XML..., with no JAXB involved.
JAXB might be used to create the actual XML, but the String will be written directly to the output stream or read as is from the input stream...

Cheers, Sergey

> 
> Yea, there really is NOT a way to do this with JAXB.   Jaxb doesn't call 
> the writeCData method on the XmlStreamWriter at all, ever.  (I just 
> grepped the source).   The ONLY way I can see to do this would be write 
> a XmlStreamWriter wrapper that wraps the "real" writer and keeps track 
> of the element it's in and if in the appropriate element, foward the 
> writeCharacters calls to writeCData calls instead.  Not sure how worth 
> it that would be.
> 
> Dan
> 
> On Saturday 01 March 2008, Todd Orr wrote:
>> I'm attempting to get String data wrapped in CDATA before being
>> returned to the client. I do not want special characters to be
>> escaped. First I tried simply wrapping the properties in my getters
>> with the CDATA block. Unfortunately, JAXB continued to escape all the
>> special characters.
>>
>> I found this post:
>> http://forum.java.sun.com/thread.jspa?threadID=607524&messageID=353193
>>1. Although promising, I could not find out how to setup JAXB in my
>> applicationContext in such a way to set this as the XMLSerializer.
>>
>> Has anyone accomplished this? It seems as though it would be a fairly
>> common need.
>>
>> Thanks,
>> T
> 
> 
> 
> -- 
> J. Daniel Kulp
> Principal Engineer, IONA
> dkulp@apache.org
> http://www.dankulp.com/blog

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

Re: REST CDATA Marshalling

Posted by Daniel Kulp <dk...@apache.org>.
Yea, there really is NOT a way to do this with JAXB.   Jaxb doesn't call 
the writeCData method on the XmlStreamWriter at all, ever.  (I just 
grepped the source).   The ONLY way I can see to do this would be write 
a XmlStreamWriter wrapper that wraps the "real" writer and keeps track 
of the element it's in and if in the appropriate element, foward the 
writeCharacters calls to writeCData calls instead.  Not sure how worth 
it that would be.

Dan

On Saturday 01 March 2008, Todd Orr wrote:
> I'm attempting to get String data wrapped in CDATA before being
> returned to the client. I do not want special characters to be
> escaped. First I tried simply wrapping the properties in my getters
> with the CDATA block. Unfortunately, JAXB continued to escape all the
> special characters.
>
> I found this post:
> http://forum.java.sun.com/thread.jspa?threadID=607524&messageID=353193
>1. Although promising, I could not find out how to setup JAXB in my
> applicationContext in such a way to set this as the XMLSerializer.
>
> Has anyone accomplished this? It seems as though it would be a fairly
> common need.
>
> Thanks,
> T



-- 
J. Daniel Kulp
Principal Engineer, IONA
dkulp@apache.org
http://www.dankulp.com/blog

Re: REST CDATA Marshalling

Posted by Benson Margulies <bi...@gmail.com>.
Indeed, the CXF JAXB data binding does not provide any simple way around
this.

In the example at hand, the code knows the target byte stream for the
output, and is concocting a specialized XML writer that has the desired
behavior. CXF uses StaX to write out XML. You'd need a StaX implementation.

I wonder if you could create an interceptor that rewrote the XML the way you
like it? I'm not much of an interceptor expert.

On Sat, Mar 1, 2008 at 4:32 PM, Benson Margulies <bi...@gmail.com>
wrote:

> Why do you want to do this? The distinction between CDATA and various
> &-entities is way below the level of web service semantics. Any conformant
> XML parser is going to treat them identically.
>
>
> On Sat, Mar 1, 2008 at 2:01 PM, Todd Orr <to...@gmail.com> wrote:
>
> > I'm attempting to get String data wrapped in CDATA before being
> > returned to the client. I do not want special characters to be
> > escaped. First I tried simply wrapping the properties in my getters
> > with the CDATA block. Unfortunately, JAXB continued to escape all the
> > special characters.
> >
> > I found this post:
> > http://forum.java.sun.com/thread.jspa?threadID=607524&messageID=3531931.
> > Although promising, I could not find out how to setup JAXB in my
> > applicationContext in such a way to set this as the XMLSerializer.
> >
> > Has anyone accomplished this? It seems as though it would be a fairly
> > common need.
> >
> > Thanks,
> > T
> >
>
>

Re: REST CDATA Marshalling

Posted by Benson Margulies <bi...@gmail.com>.
Why do you want to do this? The distinction between CDATA and various
&-entities is way below the level of web service semantics. Any conformant
XML parser is going to treat them identically.

On Sat, Mar 1, 2008 at 2:01 PM, Todd Orr <to...@gmail.com> wrote:

> I'm attempting to get String data wrapped in CDATA before being
> returned to the client. I do not want special characters to be
> escaped. First I tried simply wrapping the properties in my getters
> with the CDATA block. Unfortunately, JAXB continued to escape all the
> special characters.
>
> I found this post:
> http://forum.java.sun.com/thread.jspa?threadID=607524&messageID=3531931.
> Although promising, I could not find out how to setup JAXB in my
> applicationContext in such a way to set this as the XMLSerializer.
>
> Has anyone accomplished this? It seems as though it would be a fairly
> common need.
>
> Thanks,
> T
>