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 > TransformationFeature
Date Mon, 02 May 2011 15:40: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/TransformationFeature">TransformationFeature</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~sergey_beryozkin">Sergey
Beryozkin</a>
    </h4>
        <br/>
                         <h4>Changes (2)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >h2. JAX-WS <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >Here is <span class="diff-added-words"style="background-color:
#dfd;">how</span> a JAX-WS client can be configured: <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{code:java} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >h2. JAX-RS  <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >Here is <span class="diff-added-words"style="background-color:
#dfd;">how</span> a JAX-RS client can be configured: <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{code:java} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p><span style="font-size:2em;font-weight:bold"> Transformation Feature
</span></p>

<div>
<ul>
    <li><a href='#TransformationFeature-Springconfiguration'>Spring configuration</a></li>
    <li><a href='#TransformationFeature-Configuringthefeaturefromthecode'>Configuring
the feature from the code</a></li>
<ul>
    <li><a href='#TransformationFeature-JAXWS'>JAX-WS</a></li>
    <li><a href='#TransformationFeature-JAXRS'>JAX-RS</a></li>
</ul>
</ul></div>

<p>The CXF Transformation feature provides for a flexible and fast way to do the dynamic
transformations of the inbound and/or outbound XML messages. </p>

<p>This feature can be used in a number of cases: dropping the namespace of the outbound
messages, qualifying the incoming message, changing namespaces, appending or dropping elements
and converting attributes to elements.</p>

<p>The "outTransformElements", "inTransformElements", "outDropElements", "inDropElements",
"outAppendElements", "inAppendElements" and "attributesAsElements" properties can be used.</p>

<h1><a name="TransformationFeature-Springconfiguration"></a>Spring configuration</h1>

<p>The following properties can be set from Spring:</p>

<ul class="alternate" type="square">
	<li>"outTransformElements" map property: can be used to change the output element names
and change or drop namespaces; keys are the elements to be changed, values are the new element
names. Examples:</li>
</ul>


<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;bean id=<span class="code-quote">"transformFeature"</span>
class=<span class="code-quote">"org.apache.cxf.feature.StaxTransfromFeature"</span>&gt;</span>
  <span class="code-tag">&lt;property name=<span class="code-quote">"outTransformElements"</span>&gt;</span>
    <span class="code-tag">&lt;map&gt;</span>
      <span class="code-tag"><span class="code-comment">&lt;!-- change <span
class="code-quote">"book"</span> to <span class="code-quote">"thebook"</span>
--&gt;</span></span>
      <span class="code-tag">&lt;entry key=<span class="code-quote">"book"</span>
value=<span class="code-quote">"thebook"</span>/&gt;</span>
      
      <span class="code-tag"><span class="code-comment">&lt;!-- drop the namespace
from <span class="code-quote">"book"</span> --&gt;</span></span>
      <span class="code-tag">&lt;entry key=<span class="code-quote">"{http://books}book"</span>
value=<span class="code-quote">"book"</span>/&gt;</span> 
      
      <span class="code-tag"><span class="code-comment">&lt;!-- qualify <span
class="code-quote">"book"</span> with <span class="code-quote">"http://books"</span>
--&gt;</span></span>
      <span class="code-tag">&lt;entry key=<span class="code-quote">"book"</span>
value=<span class="code-quote">"{http://books}thebook"</span>/&gt;</span>

      
      <span class="code-tag"><span class="code-comment">&lt;!--  change namespace
to <span class="code-quote">"http://books"</span> for all the elements with the
<span class="code-quote">"http://book"</span> namespace --&gt;</span></span>
      <span class="code-tag">&lt;entry key=<span class="code-quote">"{http://book}*"</span>
value=<span class="code-quote">"{http://books}*"</span>/&gt;</span>

    <span class="code-tag">&lt;/map&gt;</span>
  <span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span> 
</pre>
</div></div>

<ul class="alternate" type="square">
	<li>"inTransformElements" map property: can be used to change the input element names
and change or drop namespaces; see the "outTransfromElements" property description for an
example.</li>
</ul>


<ul class="alternate" type="square">
	<li>"outAppendElements" map property: can be used to append new simple or qualified
elements to the output; keys are the new elements, values are the elements the new ones will
be appended before. Examples:</li>
</ul>


<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;bean id=<span class="code-quote">"transformFeature"</span>
class=<span class="code-quote">"org.apache.cxf.feature.StaxTransfromFeature"</span>&gt;</span>
  <span class="code-tag">&lt;property name=<span class="code-quote">"outAppendElements"</span>&gt;</span>
    <span class="code-tag">&lt;map&gt;</span>
      <span class="code-tag"><span class="code-comment">&lt;!-- append <span
class="code-quote">"book"</span> before <span class="code-quote">"thebook"</span>
--&gt;</span></span>
      <span class="code-tag">&lt;entry key=<span class="code-quote">"book"</span>
value=<span class="code-quote">"thebook"</span>/&gt;</span>
      
      <span class="code-tag"><span class="code-comment">&lt;!-- qualify <span
class="code-quote">"book"</span> with <span class="code-quote">"http://books"</span>
--&gt;</span></span>
      <span class="code-tag">&lt;entry key=<span class="code-quote">"{http://books}book"</span>
value=<span class="code-quote">"book"</span>/&gt;</span> 
      
      <span class="code-tag"><span class="code-comment">&lt;!-- drop the namespace
from the <span class="code-quote">"book"</span> --&gt;</span></span>
      <span class="code-tag">&lt;entry key=<span class="code-quote">"book"</span>
value=<span class="code-quote">"{http://books}thebook"</span>/&gt;</span>

      
      <span class="code-tag"><span class="code-comment">&lt;!--  change namespace
to <span class="code-quote">"http://book"</span> for all the elements with the
<span class="code-quote">"http://books"</span> namespace --&gt;</span></span>
      <span class="code-tag">&lt;entry key=<span class="code-quote">"{http://book}*"</span>
value=<span class="code-quote">"{http://books}*"</span>/&gt;</span>

    <span class="code-tag">&lt;/map&gt;</span>
  <span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span> 
</pre>
</div></div>

<ul class="alternate" type="square">
	<li>"inAppendElements" map property : can be used to append new simple or qualified
elements to the input; see the "outAppendElements" property description for an example.</li>
</ul>


<ul class="alternate" type="square">
	<li>"outDropElements" list property : can be used to drop elements2.  during the serialization;
note that children elements if any of a given dropped element are not affected. Examples:</li>
</ul>


<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;bean id=<span class="code-quote">"transformFeature"</span>
class=<span class="code-quote">"org.apache.cxf.feature.StaxTransfromFeature"</span>&gt;</span>
  <span class="code-tag">&lt;property name=<span class="code-quote">"outDropElements"</span>&gt;</span>
    <span class="code-tag">&lt;list&gt;</span>
      <span class="code-tag"><span class="code-comment">&lt;!-- ignore drop
and {http://numbers}number elements --&gt;</span></span>
      <span class="code-tag">&lt;value&gt;</span>{http://numbers}number<span
class="code-tag">&lt;/value&gt;</span>
      <span class="code-tag">&lt;value&gt;</span>index<span class="code-tag">&lt;/value&gt;</span>
    <span class="code-tag">&lt;/list&gt;</span>
  <span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span> 
</pre>
</div></div>

<ul class="alternate" type="square">
	<li>"inDropElements" list property : can be used to drop elements during the deserialization;
note that children elements if any of a given dropped element are not affected. Please see
the "outDropElements" property description for an example.</li>
</ul>


<ul class="alternate" type="square">
	<li>"attributesAsElements" boolean property : can be used to have attributes serialized
as elements.</li>
</ul>


<p>The combination of "attributesAsElements" and "outDropElements" properties can be
used to have certain attributes ignored in the output by turning then into elements first
and then blocking them.</p>

<h1><a name="TransformationFeature-Configuringthefeaturefromthecode"></a>Configuring
the feature from the code</h1>

<p>The feature can be configured from the code for JAX-WS or JAX-RS clients and endpoints.</p>

<h2><a name="TransformationFeature-JAXWS"></a>JAX-WS</h2>

<p>Here is how a JAX-WS client can be configured:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
CustomerServiceService service = <span class="code-keyword">new</span> CustomerServiceService();
CustomerService customerService = service.getCustomerServicePort();
Client client = ClientProxy.getClient(customerService);

<span class="code-comment">// drop namespace from all elements qualified by 'http://customers'
</span>Map&lt;<span class="code-object">String</span>, <span class="code-object">String</span>&gt;
outTransformMap = Collections.singletonMap(<span class="code-quote">"{http:<span
class="code-comment">//customers}*"</span>, <span class="code-quote">"*"</span>);
</span>org.apache.cxf.interceptor.transform.TransformOutInterceptor transformOutInterceptor
=
    org.apache.cxf.interceptor.transform.TransformOutInterceptor();
client.getOutInterceptors().add(transformOutInterceptor);

<span class="code-comment">// qualify the incoming 'customer' element with 'http://customers'

</span>Map&lt;<span class="code-object">String</span>, <span class="code-object">String</span>&gt;
inTransformMap =  Collections.singletonMap(<span class="code-quote">"customer"</span>,
<span class="code-quote">"{http:<span class="code-comment">//customers}customer"</span>);
</span>org.apache.cxf.interceptor.transform.TransformInInterceptor transformInInterceptor
=
    org.apache.cxf.interceptor.transform.TransformInInterceptor();
client.getInInterceptors().add(transformInInterceptor);

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


<h2><a name="TransformationFeature-JAXRS"></a>JAX-RS </h2>

<p>Here is how a JAX-RS client can be configured:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
CustomerService customerServiceProxy = JAXRSClientFactory.create(endpointAddress, CustomerService.class);

ClientConfiguration config = WebClient.getConfig(customerServiceProxy);

<span class="code-comment">// or
</span><span class="code-comment">//WebClient client = WebClient.create(endpointAddress);
</span><span class="code-comment">//ClientConfiguration config = WebClient.getConfig(client);
</span>

<span class="code-comment">// drop namespace from all elements qualified by 'http://customers'
</span>Map&lt;<span class="code-object">String</span>, <span class="code-object">String</span>&gt;
outTransformMap = Collections.singletonMap(<span class="code-quote">"{http:<span
class="code-comment">//customers}*"</span>, <span class="code-quote">"*"</span>);
</span>org.apache.cxf.interceptor.transform.TransformOutInterceptor transformOutInterceptor
=
    org.apache.cxf.interceptor.transform.TransformOutInterceptor();
config.getOutInterceptors().add(transformOutInterceptor);

<span class="code-comment">// qualify the incoming 'customer' element with 'http://customers'

</span>Map&lt;<span class="code-object">String</span>, <span class="code-object">String</span>&gt;
inTransformMap =  Collections.singletonMap(<span class="code-quote">"customer"</span>,
<span class="code-quote">"{http:<span class="code-comment">//customers}customer"</span>);
</span>org.apache.cxf.interceptor.transform.TransformInInterceptor transformInInterceptor
=
    org.apache.cxf.interceptor.transform.TransformInInterceptor();
config.getInInterceptors().add(transformInInterceptor);
</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/TransformationFeature">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=25202779&revisedVersion=3&originalVersion=2">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CXF20DOC/TransformationFeature?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message