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 Thu, 20 Oct 2011 22:31: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 (24)</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" >h1. Spring configuration <br>
<br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">The
following properties can be set from Spring: <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h2.
Changing input and output element names and namespaces <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">-</span>
&quot;outTransformElements&quot; map <span class="diff-changed-words">property<span
class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">:</span></span>
can be used to change the output element names and change or drop <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">namespaces;
keys</span> <span class="diff-added-words"style="background-color: #dfd;">namespaces.
Keys</span> are the elements to be changed, values are the new element names. <span
class="diff-changed-words">Example<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">s</span>:</span>
<br></td></tr>
            <tr><td class="diff-unchanged" > <br>{code:xml} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">-</span>
&quot;inTransformElements&quot; map <span class="diff-changed-words">property<span
class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">:</span></span>
can be used to change the input element names and change or drop <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">namespaces;
see</span> <span class="diff-added-words"style="background-color: #dfd;">namespaces.
See</span> the &quot;outTransfromElements&quot; property description for an
example. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">-
&quot;outAppendElements&quot; map property: can be used to append new simple or qualified
elements to the output; keys are the elements the new elements will be appended before, values
are the new elements. Examples:  <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h2.
Appending new output elements <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">&quot;outAppendElements&quot;
map property can be used to append new simple or qualified elements to the output. Keys are
the elements the new elements will be appended before, values are the new elements. Examples:
 <br> <br></td></tr>
            <tr><td class="diff-unchanged" >{code:xml} <br>&lt;bean
id=&quot;transformFeature&quot; class=&quot;org.apache.cxf.feature.StaxTransformFeature&quot;&gt;
<br>  &lt;property name=&quot;outAppendElements&quot;&gt; <br>
   &lt;map&gt; <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">
     &lt;!-- append &quot;thebook&quot; before &quot;book&quot; --&gt;
<br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
     &lt;!-- get &quot;book&quot; wrapped with the new &quot;thebook&quot;
element--&gt; <br></td></tr>
            <tr><td class="diff-unchanged" >      &lt;entry key=&quot;book&quot;
value=&quot;thebook&quot;/&gt; <br></td></tr>
            <tr><td class="diff-unchanged" >    &lt;/map&gt; <br>
 &lt;/property&gt; <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">-
&quot;inAppendElements&quot; map property : can be used to append new simple or qualified
elements to the input; see the &quot;outAppendElements&quot; property description
for an example. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">Only
this so-called Append-Wrap is currently supported for out elements. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">-
&quot;outDropElements&quot; 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:  <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h2.
Appending new input elements <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">&quot;inAppendElements&quot;
map property can be used to append new simple or qualified elements to the input in a number
of ways. <br> <br>h3. Append-Pre-Wrap <br> <br></td></tr>
            <tr><td class="diff-unchanged" >{code:xml} <br>&lt;bean
id=&quot;transformFeature&quot; class=&quot;org.apache.cxf.feature.StaxTransformFeature&quot;&gt;
<br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
 &lt;property name=&quot;inAppendElements&quot;&gt; <br>    &lt;map&gt;
<br>      &lt;!-- get &quot;book&quot; wrapped with the new &quot;thebook&quot;
element--&gt; <br>      &lt;entry key=&quot;book&quot; value=&quot;thebook&quot;/&gt;
<br>    &lt;/map&gt; <br>  &lt;/property&gt; <br>&lt;/bean&gt;
 <br>{code} <br> <br>h3. Append-Post-Wrap <br> <br>{code:xml}
<br>&lt;bean id=&quot;transformFeature&quot; class=&quot;org.apache.cxf.feature.StaxTransformFeature&quot;&gt;
<br>  &lt;property name=&quot;inAppendElements&quot;&gt; <br>
   &lt;map&gt; <br>      &lt;!--  <br>         get all &quot;book&quot;
children elements wrapped with the new &quot;thebook&quot; element <br>    
    using the &quot;/&quot; convention. <br>      --&gt; <br>    
 &lt;entry key=&quot;book/&quot; value=&quot;thebook&quot;/&gt; <br>
   &lt;/map&gt; <br>  &lt;/property&gt; <br>&lt;/bean&gt;
 <br>{code} <br> <br> <br>h3. Append-Pre-Include <br> <br>{code:xml}
<br>&lt;bean id=&quot;transformFeature&quot; class=&quot;org.apache.cxf.feature.StaxTransformFeature&quot;&gt;
<br>  &lt;property name=&quot;inAppendElements&quot;&gt; <br>
   &lt;map&gt; <br>      &lt;!-- append new simple &quot;thebook&quot;
element with a text value &#39;2&#39; before &quot;the book&quot; --&gt;
<br>      &lt;entry key=&quot;book&quot; value=&quot;thebook=2&quot;/&gt;
<br>    &lt;/map&gt; <br>  &lt;/property&gt; <br>&lt;/bean&gt;
 <br>{code} <br> <br>h3. Append-Post-Include <br> <br>{code:xml}
<br>&lt;bean id=&quot;transformFeature&quot; class=&quot;org.apache.cxf.feature.StaxTransformFeature&quot;&gt;
<br>  &lt;property name=&quot;inAppendElements&quot;&gt; <br>
   &lt;map&gt; <br>      &lt;!-- append new simple &quot;thebook&quot;
element with a text value &#39;2&#39; after &quot;the book&quot;, using a
&#39;/&#39; convention --&gt; <br>      &lt;entry key=&quot;book/&quot;
value=&quot;thebook=2&quot;/&gt; <br>    &lt;/map&gt; <br>
 &lt;/property&gt; <br>&lt;/bean&gt;  <br>{code} <br> <br>h2.
Replacing text content <br> <br>It&#39;s possible to replace the text content
of a given simple element only on the input, for example:  <br> <br>{code:xml}
<br>&lt;bean id=&quot;transformFeature&quot; class=&quot;org.apache.cxf.feature.StaxTransformFeature&quot;&gt;
<br>  &lt;property name=&quot;inAppendElements&quot;&gt; <br>
   &lt;map&gt; <br>      &lt;!-- replace the text content of {ns}a element
with the &#39;new Text&#39; value --&gt; <br>      &lt;entry key=&quot;{ns}a&quot;
value=&quot;{ns}a=new Text&quot;/&gt; <br>    &lt;/map <br>  &lt;/property&gt;
<br>&lt;/bean&gt;  <br>{code} <br> <br> <br>h2. Dropping
output elements <br> <br>&quot;outDropElements&quot; list property can
be used to drop output elements. Note that children elements if any of a given dropped element
are not affected. Examples:  <br> <br>{code:xml} <br>&lt;bean id=&quot;transformFeature&quot;
class=&quot;org.apache.cxf.feature.StaxTransformFeature&quot;&gt; <br></td></tr>
            <tr><td class="diff-unchanged" >  &lt;property name=&quot;outDropElements&quot;&gt;
<br>    &lt;list&gt; <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">
     &lt;!-- ignore drop and {http://numbers}number elements --&gt; <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
     &lt;!-- shallow drop &#39;index&#39; and &#39;{http://numbers}number&#39;
elements --&gt; <br></td></tr>
            <tr><td class="diff-unchanged" >      &lt;value&gt;{http://numbers}number&lt;/value&gt;
<br>      &lt;value&gt;index&lt;/value&gt; <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">-
&quot;inDropElements&quot; 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 &quot;outDropElements&quot; property description for an example. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h2.
Dropping input elements <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">-
&quot;attributesAsElements&quot; boolean property : can be used to have attributes
serialized as elements. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">&quot;inDropElements&quot;
list property can be used to drop input elements. Note that children elements if any of a
given dropped element are not affected. Please see the &quot;outDropElements&quot;
property description for an example. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">The
combination of &quot;attributesAsElements&quot; and &quot;outDropElements&quot;
properties can be used to have certain attributes ignored in the output by turning then into
elements first and then blocking them. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">Additionally,
inTransformElements property can be used to deep-drop an element and all of its children if
any, for example: <br>{code:xml} <br>&lt;bean id=&quot;transformFeature&quot;
class=&quot;org.apache.cxf.feature.StaxTransformFeature&quot;&gt; <br> 
&lt;property name=&quot;outTransformElements&quot;&gt; <br>    &lt;map&gt;
<br>      &lt;!-- drop &quot;book&quot; and all of its children, using an
empty value convention --&gt; <br>      &lt;entry key=&quot;book&quot;
value=&quot;&quot;/&gt; <br> <br>    &lt;/map&gt; <br>
 &lt;/property&gt; <br>&lt;/bean&gt;  <br>{code} <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h2.
Converting attributes to elements <br>&quot;attributesAsElements&quot; boolean
property can be used to have attributes serialized as elements on the output only. <br>
<br>The combination of &quot;attributesAsElements&quot; and &quot;outDropElements&quot;
properties can be used to have certain attributes ignored in the output by turning them into
elements and then blocking them. <br> <br>h1. Input Transformation and Redirection
<br> <br>Consider the case where a new endpoint has been introduced but some of
the existing clients have not been updated yet to work with the new endpoint, they are still
unaware of it. <br> <br>In this case  you may want to keep the CXFServlet serving
the old clients but make it redirect them to a new CXFServlet serving a new endpoint only.
<br>Now, in order to serve the old clients one needs to apply a transform feature, however
the new clients should not be affected. Thus the feature can be configured such that it&#39;s
only triggered if a certain contextual property has been set on a current Message. In this
case the feature should only apply to the old redirected clients: <br> <br>{code:xml}
<br>&lt;bean id=&quot;transformFeatureRest&quot; class=&quot;org.apache.cxf.feature.StaxTransformFeature&quot;&gt;
<br>      &lt;!--  <br>         apply the transformation only if the boolean
property with the given name <br>         is set to true on the message <br> 
    --&gt;    <br>      &lt;property name=&quot;contextPropertyName&quot;
value=&quot;http.service.redirection&quot;/&gt; <br>      &lt;!-- the
transform configuration --&gt; <br>&lt;/bean&gt; <br>{code} <br>
<br></td></tr>
            <tr><td class="diff-unchanged" >h1. Configuring the feature from the
code <br> <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>
<ul>
    <li><a href='#TransformationFeature-Changinginputandoutputelementnamesandnamespaces'>Changing
input and output element names and namespaces</a></li>
    <li><a href='#TransformationFeature-Appendingnewoutputelements'>Appending
new output elements</a></li>
    <li><a href='#TransformationFeature-Appendingnewinputelements'>Appending new
input elements</a></li>
<ul>
    <li><a href='#TransformationFeature-AppendPreWrap'>Append-Pre-Wrap</a></li>
    <li><a href='#TransformationFeature-AppendPostWrap'>Append-Post-Wrap</a></li>
    <li><a href='#TransformationFeature-AppendPreInclude'>Append-Pre-Include</a></li>
    <li><a href='#TransformationFeature-AppendPostInclude'>Append-Post-Include</a></li>
</ul>
    <li><a href='#TransformationFeature-Replacingtextcontent'>Replacing text content</a></li>
    <li><a href='#TransformationFeature-Droppingoutputelements'>Dropping output
elements</a></li>
    <li><a href='#TransformationFeature-Droppinginputelements'>Dropping input
elements</a></li>
    <li><a href='#TransformationFeature-Convertingattributestoelements'>Converting
attributes to elements</a></li>
</ul>
    <li><a href='#TransformationFeature-InputTransformationandRedirection'>Input
Transformation and Redirection</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>

<h2><a name="TransformationFeature-Changinginputandoutputelementnamesandnamespaces"></a>Changing
input and output element names and namespaces</h2>

<p>"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. Example: </p>

<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.StaxTransformFeature"</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>

<p>"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.</p>

<h2><a name="TransformationFeature-Appendingnewoutputelements"></a>Appending
new output elements</h2>

<p>"outAppendElements" map property can be used to append new simple or qualified elements
to the output. Keys are the elements the new elements will be appended before, values are
the new elements. Examples: </p>

<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.StaxTransformFeature"</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;!-- get <span
class="code-quote">"book"</span> wrapped with the new <span class="code-quote">"thebook"</span>
element--&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">&lt;/map&gt;</span>
  <span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span> 
</pre>
</div></div>

<p>Only this so-called Append-Wrap is currently supported for out elements.</p>

<h2><a name="TransformationFeature-Appendingnewinputelements"></a>Appending
new input elements</h2>

<p>"inAppendElements" map property can be used to append new simple or qualified elements
to the input in a number of ways.</p>

<h3><a name="TransformationFeature-AppendPreWrap"></a>Append-Pre-Wrap</h3>

<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.StaxTransformFeature"</span>&gt;</span>
  <span class="code-tag">&lt;property name=<span class="code-quote">"inAppendElements"</span>&gt;</span>
    <span class="code-tag">&lt;map&gt;</span>
      <span class="code-tag"><span class="code-comment">&lt;!-- get <span
class="code-quote">"book"</span> wrapped with the new <span class="code-quote">"thebook"</span>
element--&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">&lt;/map&gt;</span>
  <span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span> 
</pre>
</div></div>

<h3><a name="TransformationFeature-AppendPostWrap"></a>Append-Post-Wrap</h3>

<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.StaxTransformFeature"</span>&gt;</span>
  <span class="code-tag">&lt;property name=<span class="code-quote">"inAppendElements"</span>&gt;</span>
    <span class="code-tag">&lt;map&gt;</span>
      &lt;!-- 
         get all <span class="code-quote">"book"</span> children elements wrapped
with the new <span class="code-quote">"thebook"</span> element
         using the <span class="code-quote">"/"</span> convention.
      --&gt;
      <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">&lt;/map&gt;</span>
  <span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span> 
</pre>
</div></div>


<h3><a name="TransformationFeature-AppendPreInclude"></a>Append-Pre-Include</h3>

<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.StaxTransformFeature"</span>&gt;</span>
  <span class="code-tag">&lt;property name=<span class="code-quote">"inAppendElements"</span>&gt;</span>
    <span class="code-tag">&lt;map&gt;</span>
      <span class="code-tag"><span class="code-comment">&lt;!-- append new
simple <span class="code-quote">"thebook"</span> element with a text value '2'
before <span class="code-quote">"the book"</span> --&gt;</span></span>
      <span class="code-tag">&lt;entry key=<span class="code-quote">"book"</span>
value=<span class="code-quote">"thebook=2"</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>

<h3><a name="TransformationFeature-AppendPostInclude"></a>Append-Post-Include</h3>

<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.StaxTransformFeature"</span>&gt;</span>
  <span class="code-tag">&lt;property name=<span class="code-quote">"inAppendElements"</span>&gt;</span>
    <span class="code-tag">&lt;map&gt;</span>
      <span class="code-tag"><span class="code-comment">&lt;!-- append new
simple <span class="code-quote">"thebook"</span> element with a text value '2'
after <span class="code-quote">"the book"</span>, using a '/' convention --&gt;</span></span>
      <span class="code-tag">&lt;entry key=<span class="code-quote">"book/"</span>
value=<span class="code-quote">"thebook=2"</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>

<h2><a name="TransformationFeature-Replacingtextcontent"></a>Replacing text
content</h2>

<p>It's possible to replace the text content of a given simple element only on the input,
for example: </p>

<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.StaxTransformFeature"</span>&gt;</span>
  <span class="code-tag">&lt;property name=<span class="code-quote">"inAppendElements"</span>&gt;</span>
    <span class="code-tag">&lt;map&gt;</span>
      <span class="code-tag"><span class="code-comment">&lt;!-- replace the
text content of {ns}a element with the 'new Text' value --&gt;</span></span>
      <span class="code-tag">&lt;entry key=<span class="code-quote">"{ns}a"</span>
value=<span class="code-quote">"{ns}a=new Text"</span>/&gt;</span>
    &lt;/map
  <span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span> 
</pre>
</div></div>


<h2><a name="TransformationFeature-Droppingoutputelements"></a>Dropping
output elements</h2>

<p>"outDropElements" list property can be used to drop output elements. Note that children
elements if any of a given dropped element are not affected. Examples: </p>

<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.StaxTransformFeature"</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;!-- shallow drop
'index' 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>

<h2><a name="TransformationFeature-Droppinginputelements"></a>Dropping input
elements</h2>

<p>"inDropElements" list property can be used to drop input elements. Note that children
elements if any of a given dropped element are not affected. Please see the "outDropElements"
property description for an example.</p>

<p>Additionally, inTransformElements property can be used to deep-drop an element and
all of its children if any, for example:</p>
<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.StaxTransformFeature"</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;!-- drop <span
class="code-quote">"book"</span> and all of its children, using an empty value convention
--&gt;</span></span>
      <span class="code-tag">&lt;entry key=<span class="code-quote">"book"</span>
value=""/&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>

<h2><a name="TransformationFeature-Convertingattributestoelements"></a>Converting
attributes to elements</h2>
<p>"attributesAsElements" boolean property can be used to have attributes serialized
as elements on the output only.</p>

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

<h1><a name="TransformationFeature-InputTransformationandRedirection"></a>Input
Transformation and Redirection</h1>

<p>Consider the case where a new endpoint has been introduced but some of the existing
clients have not been updated yet to work with the new endpoint, they are still unaware of
it.</p>

<p>In this case  you may want to keep the CXFServlet serving the old clients but make
it redirect them to a new CXFServlet serving a new endpoint only.<br/>
Now, in order to serve the old clients one needs to apply a transform feature, however the
new clients should not be affected. Thus the feature can be configured such that it's only
triggered if a certain contextual property has been set on a current Message. In this case
the feature should only apply to the old redirected clients:</p>

<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">"transformFeatureRest"</span>
class=<span class="code-quote">"org.apache.cxf.feature.StaxTransformFeature"</span>&gt;</span>
      &lt;!-- 
         apply the transformation only if the boolean property with the given name
         is set to true on the message
      --&gt;   
      <span class="code-tag">&lt;property name=<span class="code-quote">"contextPropertyName"</span>
value=<span class="code-quote">"http.service.redirection"</span>/&gt;</span>
      <span class="code-tag"><span class="code-comment">&lt;!-- the transform
configuration --&gt;</span></span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<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
=
    <span class="code-keyword">new</span> org.apache.cxf.interceptor.transform.TransformOutInterceptor();
transformOutInterceptor.setOutTransformElements(outTransformMap);
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
=
    <span class="code-keyword">new</span> org.apache.cxf.interceptor.transform.TransformInInterceptor();
transformInInterceptor.setInTransformElements(inTransformMap);
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
=
    <span class="code-keyword">new</span> org.apache.cxf.interceptor.transform.TransformOutInterceptor();
transformOutInterceptor.setOutTransformElements(outTransformMap);
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
=
    <span class="code-keyword">new</span> org.apache.cxf.interceptor.transform.TransformInInterceptor();
transformInInterceptor.setInTransformElements(inTransformMap);
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=7&originalVersion=6">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