The Source for Java Technology Collaboration
User: Password:



Kohsuke Kawaguchi

Kohsuke Kawaguchi's Blog

Canonicalization support in JAXB RI 2.0

Posted by kohsuke on March 07, 2006 at 10:14 AM | Comments (5)

JAXB 2.0 is sometimes used in an environment where its output needs to be canonicalized. This is particularly true in the context of web services, such as Tango.

Traditionally, this has been done by attaching a separate processor that receives the output from JAXB, then do c14n, then write it out to byte stream (and for a reason beyond me they chose to do this by building a DOM, instead of doing it in a streaming fashion, but that's a different story.)

Anyway, even if you do c14n in a streaming filter, it still has to pass through an infoset API, such as StAX or SAX. But since JAXB can write XML directly to UTF-8 byte stream very fast, we wanted to take advantage of this even when we are doing c14n. Besides, JAXB knows a lot about its output --- for example, it knows how it produces namespace declarations, it knows that it doesn't produce CDATA, etc. All these knowledge allows JAXB to do c14n faster than doing so as a general-purpose filter.

So, here's how to do it. Just insert the following code before you do the marshalling:

marshaller.setProperty("com.sun.xml.bind.c14n",true);

Note that this is still an experimental feature. There are different modes of c14n, such as inclusive vs exclusive, and I don't claim I understand all the details, so there could be some bugs, too. I appreciate any feedback.


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first)

  • See https://jaxb-architecture-document.dev.java.net/nonav/doc/index.html?com/sun/xml/bind/api/C14nSupport_ArchitectureDocument.html for more details about this.

    Posted by: kohsuke on March 07, 2006 at 10:30 AM

  • As canonicalization is supported in JAXB RI 2.0 and JAX-WS uses precisely JAXB for the SOAP messages marshaller, do you know how to enable the canonicalization in JAX-WS for the oubounds SOAP messages send by a client web service ?
    I figure out a little in several forums but unfortunately I have no answer.

    Thanks.

    Richard.

    Posted by: aillet on January 16, 2007 at 08:52 AM


  • Usually one would canonicalize only a portion of a message (like just a payload, a header, or a few subtrees, etc.) So depending on what you want to do, it would be different.


    Sounds like you just want to use XWSS. No?

    Posted by: kohsuke on January 16, 2007 at 10:57 AM

  • Fo my need I would like canonalize the entire message (..)
    What is the best way to do it ?

    Posted by: aillet on January 17, 2007 at 02:04 AM

  • I think my friendly colleagues at http://xwss.dev.java.net/ should be able to help you.

    Posted by: kohsuke on January 17, 2007 at 02:26 PM





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds