blob: 8df019a0998ca421cd4f24ce56de7debfc511972 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<link type="text/css" rel="stylesheet" href="/resources/site.css">
<script src='/resources/space.js'></script>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<meta name="keywords" content="business integration, EAI, SOA, Service Oriented Architecture, web services, SOAP, JBI, JMS, WSDL, XML, EDI, Electronic Data Interchange, standards support, integration standards, application integration, middleware, software, solutions, services, CXF, open source">
<meta name="description" content="Apache CXF, Services Framework - JAXB">
<link type="text/css" rel="stylesheet" href="/resources/highlighter/styles/shCoreCXF.css">
<link type="text/css" rel="stylesheet" href="/resources/highlighter/styles/shThemeCXF.css">
<script src='/resources/highlighter/scripts/shCore.js'></script>
<script src='/resources/highlighter/scripts/shBrushXml.js'></script>
<script>
SyntaxHighlighter.defaults['toolbar'] = false;
SyntaxHighlighter.all();
</script>
<title>
Apache CXF -- JAXB
</title>
</head>
<body onload="init()">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td id="cell-0-0" colspan="2">&nbsp;</td>
<td id="cell-0-1">&nbsp;</td>
<td id="cell-0-2" colspan="2">&nbsp;</td>
</tr>
<tr>
<td id="cell-1-0">&nbsp;</td>
<td id="cell-1-1">&nbsp;</td>
<td id="cell-1-2">
<!-- Banner -->
<div class="banner" id="banner"><div><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td align="left" colspan="1" nowrap>
<a shape="rect" href="http://cxf.apache.org/" title="Apache CXF"><span style="font-weight: bold; font-size: 170%; color: white">Apache CXF</span></a>
</td><td align="right" colspan="1" nowrap>
<a shape="rect" href="http://www.apache.org/" title="The Apache Sofware Foundation"><img border="0" alt="ASF Logo" src="http://cxf.apache.org/images/asf-logo.png"></a>
</td></tr></table></div></div>
<!-- Banner -->
<div id="top-menu">
<table border="0" cellpadding="1" cellspacing="0" width="100%">
<tr>
<td>
<div align="left">
<!-- Breadcrumbs -->
<a href="index.html">Index</a>&nbsp;&gt;&nbsp;<a href="databindings.html">DataBindings</a>&nbsp;&gt;&nbsp;<a href="jaxb.html">JAXB</a>
<!-- Breadcrumbs -->
</div>
</td>
<td>
<div align="right">
<!-- Quicklinks -->
<div id="quicklinks"><p><a shape="rect" href="http://cxf.apache.org/download.html">Download</a> | <a shape="rect" href="http://cxf.apache.org/docs/index.html">Documentation</a></p></div>
<!-- Quicklinks -->
</div>
</td>
</tr>
</table>
</div>
</td>
<td id="cell-1-3">&nbsp;</td>
<td id="cell-1-4">&nbsp;</td>
</tr>
<tr>
<td id="cell-2-0" colspan="2">&nbsp;</td>
<td id="cell-2-1">
<table>
<tr valign="top">
<td height="100%">
<div id="wrapper-menu-page-right">
<div id="wrapper-menu-page-top">
<div id="wrapper-menu-page-bottom">
<div id="menu-page">
<!-- NavigationBar -->
<div id="navigation"><ul class="alternate"><li><a shape="rect" href="overview.html">Overview</a></li><li><a shape="rect" href="how-tos.html">How-Tos</a></li><li><a shape="rect" href="frontends.html">Frontends</a></li><li><a shape="rect" href="databindings.html">DataBindings</a></li><li><a shape="rect" href="transports.html">Transports</a></li><li><a shape="rect" href="configuration.html">Configuration</a></li><li><a shape="rect" href="debugging-and-logging.html">Debugging and Logging</a></li><li><a shape="rect" href="tools.html">Tools</a></li><li><a shape="rect" href="restful-services.html">RESTful Services</a></li><li><a shape="rect" href="wsdl-bindings.html">WSDL Bindings</a></li><li><a shape="rect" href="service-routing.html">Service Routing</a></li><li><a shape="rect" href="dynamic-languages.html">Dynamic Languages</a></li><li><a shape="rect" href="ws-support.html">WS-* Support</a></li><li><a shape="rect" href="advanced-integration.html">Advanced Integration</a></li><li><a shape="rect" href="deployment.html">Deployment</a></li><li><a shape="rect" href="schemas-and-namespaces.html">Use of Schemas and Namespaces</a></li></ul><hr><ul class="alternate"><li><p>Search</p></li></ul><form enctype="application/x-www-form-urlencoded" method="get" id="cse-search-box" action="http://www.google.com/cse">
<div>
<input type="hidden" name="cx" value="002890367768291051730:o99qiwa09y4">
<input type="hidden" name="ie" value="UTF-8">
<input type="text" name="q" size="21">
<input type="submit" name="sa" value="Search">
</div>
</form>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&amp;lang=en"></script><hr><ul class="alternate"><li><a shape="rect" href="http://cxf.apache.org/javadoc/latest/">API 3.2.x (Javadoc)</a></li><li><a shape="rect" href="http://cxf.apache.org/javadoc/latest-3.1.x/">API 3.1.x (Javadoc)</a></li><li><a shape="rect" href="http://cxf.apache.org/">CXF Website</a></li></ul><p>&#160;</p><p><a shape="rect" class="external-link" href="http://www.apache.org/events/current-event.html"><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-external-resource" src="http://www.apache.org/events/current-event-125x125.png" data-image-src="http://www.apache.org/events/current-event-125x125.png"></span></a></p></div>
<!-- NavigationBar -->
</div>
</div>
</div>
</div>
</td>
<td height="100%">
<!-- Content -->
<div class="wiki-content">
<div id="ConfluenceContent"><h1 id="JAXB-Introduction">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 shape="rect" class="external-link" href="http://docs.oracle.com/javase/6/docs/technotes/guides/standards/" 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 shape="rect" class="external-link" href="https://javaee.github.io/jaxb-v2/doc/user-guide/" rel="nofollow">JAXB user's guide</a>.</p><h1 id="JAXB-JAXBversusJAX-WS(orotherfront-ends)">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 id="JAXB-ConfiguringJAXB">Configuring JAXB</h1><p>CXF allows you to configure JAXB in two ways.</p><h2 id="JAXB-JAXBProperties">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. <strong>Take care.</strong> 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 pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Example of Configuring a Context Property</b></div><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default">&lt;jaxws:server id="bookServer"
serviceClass="org.myorg.mytypes.AnonymousComplexTypeImpl"
address="http://localhost:8080/act"
bus="cxf"&gt;
&lt;jaxws:invoker&gt;
&lt;bean class="org.apache.cxf.service.invoker.BeanInvoker"&gt;
&lt;constructor-arg&gt;
&lt;bean class="org.myorg.mytypes.AnonymousComplexTypeImpl"/&gt;
&lt;/constructor-arg&gt;
&lt;/bean&gt;
&lt;/jaxws:invoker&gt;
&lt;jaxws:dataBinding&gt;
&lt;bean class="org.apache.cxf.jaxb.JAXBDataBinding"&gt;
&lt;property name="contextProperties"&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 id="JAXB-ActivatingJAXBValidationofSOAPrequestsandresponses">Activating JAXB Validation of SOAP requests and responses</h2><p>Please see the <a shape="rect" href="http://cxf.apache.org/faq.html#FAQ-HowcanIturnonschemavalidationforjaxwsendpoint?">FAQ</a>.</p><h2 id="JAXB-NamespacePrefixManagement">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 pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Example of Configuring a Namespace Mapping</b></div><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default">&lt;jaxws:server id="bookServer"
serviceClass="org.myorg.mytypes.AnonymousComplexTypeImpl"
address="http://localhost:8080/act"
bus="cxf"&gt;
&lt;jaxws:invoker&gt;
&lt;bean class="org.apache.cxf.service.invoker.BeanInvoker"&gt;
&lt;constructor-arg&gt;
&lt;bean class="org.myorg.mytypes.AnonymousComplexTypeImpl"/&gt;
&lt;/constructor-arg&gt;
&lt;/bean&gt;
&lt;/jaxws:invoker&gt;
&lt;jaxws:dataBinding&gt;
&lt;bean class="org.apache.cxf.jaxb.JAXBDataBinding"&gt;
&lt;property name="namespaceMap"&gt;
&lt;map&gt;
&lt;entry&gt;
&lt;key&gt;&lt;value&gt;http://cxf.apache.org/anonymous_complex_type/&lt;/value&gt;&lt;/key&gt;
&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>
<!-- Content -->
</td>
</tr>
</table>
</td>
<td id="cell-2-2" colspan="2">&nbsp;</td>
</tr>
<tr>
<td id="cell-3-0">&nbsp;</td>
<td id="cell-3-1">&nbsp;</td>
<td id="cell-3-2">
<div id="footer">
<!-- Footer -->
<div id="site-footer">
<a href="http://cxf.apache.org/privacy-policy.html">Privacy Policy</a> -
(<a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=49906">edit page</a>)
(<a href="https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=49906&amp;showComments=true&amp;showCommentArea=true#addcomment">add comment</a>)<br>
Apache CXF, CXF, Apache, the Apache feather logo are trademarks of The Apache Software Foundation.<br>
All other marks mentioned may be trademarks or registered trademarks of their respective owners.
</div>
<!-- Footer -->
</div>
</td>
<td id="cell-3-3">&nbsp;</td>
<td id="cell-3-4">&nbsp;</td>
</tr>
<tr>
<td id="cell-4-0" colspan="2">&nbsp;</td>
<td id="cell-4-1">&nbsp;</td>
<td id="cell-4-2" colspan="2">&nbsp;</td>
</tr>
</table>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-4458903-1");
pageTracker._trackPageview();
} catch(err) {}</script>
</body>
</html>