cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache CXF Documentation > JAXB
Date Fri, 10 Aug 2012 17:10:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CXF20DOC&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CXF20DOC/JAXB">JAXB</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~mazzag">Glen
Mazza</a>
    </h4>
        <div id="versionComment">
        <b>Comment:</b>
        (Hopefully) clarified JAXB 2.1/2.2 usage<br />
    </div>
        <br/>
                         <h4>Changes (2)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-unchanged" >h1. Introduction <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">JAXB
is the default data binding for CXF. If you don&#39;t specify one of the other data bindings
in your Spring configuration or through the API, you will get JAXB. CXF 2.0.x branch supplies
JAXB 2.0, CXF 2.1.x and CXF 2.2.x use JAXB 2.1. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">JAXB
is the default data binding for CXF. If you don&#39;t specify one of the other data bindings
in your Spring configuration or through the API, you will get JAXB. Releases of CXF since
2.3.x have used the JDK7 default of JAXB 2.2, however Maven users running on JDK 6 will need
to use the [Java endorsed override mechanism|http://docs.oracle.com/javase/6/docs/technotes/guides/standards/]
to use JAXB 2.2 instead of JAXB 2.1. <br></td></tr>
            <tr><td class="diff-unchanged" > <br>JAXB uses Java annotation
combined with files found on the classpath to build the mapping between XML and Java. JAXB
supports both code-first and schema-first programming. The schema-first support the ability
to create a client proxy, dynamically, at runtime. See the CXF DynamicClientFactory class.
<br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h1><a name="JAXB-Introduction"></a>Introduction</h1>

<p>JAXB is the default data binding for CXF. If you don't specify one of the other data
bindings in your Spring configuration or through the API, you will get JAXB. Releases of CXF
since 2.3.x have used the JDK7 default of JAXB 2.2, however Maven users running on JDK 6 will
need to use the <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/standards/"
class="external-link" rel="nofollow">Java endorsed override mechanism</a> to use
JAXB 2.2 instead of JAXB 2.1.</p>

<p>JAXB uses Java annotation combined with files found on the classpath to build the
mapping between XML and Java. JAXB supports both code-first and schema-first programming.
The schema-first support the ability to create a client proxy, dynamically, at runtime. See
the CXF DynamicClientFactory class.</p>

<p>CXF uses the JAXB reference implementation. To learn more about annotating your classes
or how to generate beans from a schema, please read the <a href="https://jaxb.dev.java.net/guide/"
class="external-link" rel="nofollow">JAXB user's guide</a>.</p>

<h1><a name="JAXB-JAXBversusJAXWS%28orotherfrontends%29"></a>JAXB versus
JAX-WS (or other front-ends)</h1>

<p>There are some pitfalls in the interaction between the front end and the data binding.
If you need detailed control over the XML that travels on the wire, you may want to avoid
the 'wrapped' alternative, and stick with 'bare'. When you use the wrapped parameter style
or the RPC binding, the front ends construct more or less elaborate XML representations for
your operations. You have less control over those constructs than you do over JAXB's mappings.
In particular, developers with detailed requirements to control the XML Schema 'elementFormDefault'
or the use or non-use of XML namespace prefixes often become frustrated because the JAXB annotations
for these options don't effect mappings that are purely the work of the front-end. The safest
course is to use Document/Literal/Bare.</p>

<h1><a name="JAXB-ConfiguringJAXB"></a>Configuring JAXB</h1>

<p>CXF allows you to configure JAXB in two ways.</p>

<h2><a name="JAXB-JAXBProperties"></a>JAXB Properties</h2>

<p>JAXB allows the application to specify two sets of properties that modify its behavior:
<em>context</em> properties and <em>marshaller</em> properties. CXF
allows applications to add to these properties. <b>Take care.</b> In some cases,
CXF sets these properties for its own use. </p>

<p>You can add items to both of these property sets via the JAXBDataBinding class. The
'contextProperties' and 'marshallerProperties' <em>properties</em> (in the Spring
sense) of JAXBDataBinding each store a Map&lt;String, Object&gt;. Whatever you put
in the map, CXF will pass along to JAXB. See the JAXB documentation for details.</p>


<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;jaxws:server id=<span class="code-quote">"bookServer"</span>
  	serviceClass=<span class="code-quote">"org.myorg.mytypes.AnonymousComplexTypeImpl"</span>
    address=<span class="code-quote">"http:<span class="code-comment">//localhost:8080/act"</span>

</span>    bus=<span class="code-quote">"cxf"</span>&gt;
    &lt;jaxws:invoker&gt;
      &lt;bean class=<span class="code-quote">"org.apache.cxf.service.invoker.BeanInvoker"</span>&gt;
        &lt;constructor-arg&gt;
          &lt;bean class=<span class="code-quote">"org.myorg.mytypes.AnonymousComplexTypeImpl"</span>/&gt;
        &lt;/constructor-arg&gt;
      &lt;/bean&gt;
    &lt;/jaxws:invoker&gt;
     &lt;jaxws:dataBinding&gt;
      &lt;bean class=<span class="code-quote">"org.apache.cxf.jaxb.JAXBDataBinding"</span>&gt;
        &lt;property name=<span class="code-quote">"contextProperties"</span>&gt;
    		&lt;map&gt;
   			&lt;entry&gt;
      			&lt;key&gt;&lt;value&gt;com.sun.xml.bind.defaultNamespaceRemap&lt;/value&gt;&lt;/key&gt;
      			&lt;value&gt;uri:ultima:thule&lt;/value&gt;
   			&lt;/entry&gt;
      		&lt;/map&gt;
        &lt;/property&gt;
      &lt;/bean&gt;
      &lt;/jaxws:dataBinding&gt;
  &lt;/jaxws:server&gt;

</pre>
</div></div>

<h2><a name="JAXB-ActivatingJAXBValidationofSOAPrequestsandresponses"></a>Activating
JAXB Validation of SOAP requests and responses</h2>

<p>Please see the <a href="http://cxf.apache.org/faq.html#FAQ-HowcanIturnonschemavalidationforjaxwsendpoint?"
class="external-link" rel="nofollow">FAQ</a>.</p>

<h2><a name="JAXB-NamespacePrefixManagement"></a>Namespace Prefix Management</h2>

<p>The JAXB reference implementation allows the application to provide an object that
in turn maps namespace URI's to prefixes. You can create such an object and supply it via
the marshaller properties. However, CXF provides an easier process. The namespaceMap property
of the JAXBDataBinding accepts a Map&lt;String, String&gt;. Think of it as a map from
namespace URI to namespace prefix. If you load up this map, CXF will set up the necessary
marshaller property for you.</p>


<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;jaxws:server id=<span class="code-quote">"bookServer"</span>
  	serviceClass=<span class="code-quote">"org.myorg.mytypes.AnonymousComplexTypeImpl"</span>
    address=<span class="code-quote">"http:<span class="code-comment">//localhost:8080/act"</span>

</span>    bus=<span class="code-quote">"cxf"</span>&gt;
    &lt;jaxws:invoker&gt;
      &lt;bean class=<span class="code-quote">"org.apache.cxf.service.invoker.BeanInvoker"</span>&gt;
        &lt;constructor-arg&gt;
          &lt;bean class=<span class="code-quote">"org.myorg.mytypes.AnonymousComplexTypeImpl"</span>/&gt;
        &lt;/constructor-arg&gt;
      &lt;/bean&gt;
    &lt;/jaxws:invoker&gt;
     &lt;jaxws:dataBinding&gt;
      &lt;bean class=<span class="code-quote">"org.apache.cxf.jaxb.JAXBDataBinding"</span>&gt;
        &lt;property name=<span class="code-quote">"namespaceMap"</span>&gt;
    		&lt;map&gt;
   			&lt;entry&gt;
      			&lt;key&gt;&lt;value&gt;http:<span class="code-comment">//cxf.apache.org/anonymous_complex_type/&lt;/value&gt;&lt;/key&gt;
</span>      			&lt;value&gt;BeepBeep&lt;/value&gt;
   			&lt;/entry&gt;
      		&lt;/map&gt;
        &lt;/property&gt;
      &lt;/bean&gt;
      &lt;/jaxws:dataBinding&gt;
  &lt;/jaxws:server&gt;

</pre>
</div></div>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CXF20DOC/JAXB">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=49906&revisedVersion=7&originalVersion=6">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CXF20DOC/JAXB?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message