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 Tue, 24 Jan 2012 14:14: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 (14)</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" >&quot;inTransformElements&quot;
map property can be used to change the input element names and change or drop namespaces.
See the &quot;outTransfromElements&quot; property description for an example. <br>
<br></td></tr>
            <tr><td class="diff-changed-lines" >h2. Appending new <span class="diff-added-words"style="background-color:
#dfd;">input and</span> output elements <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-changed-lines" >&quot;outAppendElements&quot;
<span class="diff-added-words"style="background-color: #dfd;">and &quot;inAppendElements&quot;</span>
map <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">property</span>
<span class="diff-added-words"style="background-color: #dfd;">properties</span>
can be used to append new simple or qualified elements to the <span class="diff-changed-words">output<span
class="diff-added-chars"style="background-color: #dfd;">/input in a number of ways</span>.</span>
Keys are the elements the new elements will be appended before, values are the new elements.
Examples: <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h3.
Append-Pre-Wrap <br> <br>Using inAppendsElements: <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-changed-lines" >&lt;property <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">name=&quot;outAppendElements&quot;&gt;</span>
<span class="diff-added-words"style="background-color: #dfd;">name=&quot;inAppendElements&quot;&gt;</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >    &lt;map&gt; <br>
     &lt;!-- get &quot;book&quot; wrapped with the new &quot;thebook&quot;
element--&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;">Only
this so-called Append-Wrap is currently supported for out elements. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">Using
outAppendsElements: <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;">h2.
Appending new input elements <br> <br>&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-changed-lines" >&lt;property <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">name=&quot;inAppendElements&quot;&gt;</span>
<span class="diff-added-words"style="background-color: #dfd;">name=&quot;outAppendElements&quot;&gt;</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >    &lt;map&gt; <br>
     &lt;!-- get &quot;book&quot; wrapped with the new &quot;thebook&quot;
element--&gt; <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >h2. Replacing text content <br>
<br></td></tr>
            <tr><td class="diff-changed-lines" >It&#39;s possible to replace
the text content of a given simple element only on the <span class="diff-changed-words">input<span
class="diff-added-chars"style="background-color: #dfd;"> and output</span>,</span>
for example: <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" > <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >h2. Dropping output <span class="diff-added-words"style="background-color:
#dfd;">and input</span> 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 output elements. 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;">&quot;outDropElements&quot;
and &quot;inDropElements&quot; list properties can be used to drop output and 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. It&#39;s
a so-called &quot;shallow&quot; drop. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">Additionally,
outTransformElements and inTransformElements property can be used to deep-drop an element
and all of its children if any, for example: <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-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">
 &lt;property name=&quot;outDropElements&quot;&gt; <br>    &lt;list&gt;
<br>      &lt;!-- shallow drop &#39;index&#39; and &#39;{http://numbers}number&#39;
elements --&gt; <br>      &lt;value&gt;{http://numbers}number&lt;/value&gt;
<br>      &lt;value&gt;index&lt;/value&gt; <br>    &lt;/list&gt;
<br>  &lt;/property&gt; <br>&lt;/bean&gt;  <br>{code} <br>
<br>h2. Dropping input elements <br> <br>&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> <br>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></td></tr>
            <tr><td class="diff-unchanged" >  &lt;property name=&quot;outTransformElements&quot;&gt;
<br>    &lt;map&gt; <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-Appendingnewinputandoutputelements'>Appending
new input and output 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-Droppingoutputandinputelements'>Dropping
output and 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-Appendingnewinputandoutputelements"></a>Appending
new input and output elements</h2>

<p>"outAppendElements" and "inAppendElements" map properties can be used to append new
simple or qualified elements to the output/input in a number of ways. Keys are the elements
the new elements will be appended before, values are the new elements. Examples: </p>

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

<p>Using inAppendsElements:</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;!-- 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>Using outAppendsElements:</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>


<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
and output, 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-Droppingoutputandinputelements"></a>Dropping
output and input elements</h2>

<p>"outDropElements" and "inDropElements" list properties can be used to drop output
and 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. It's a so-called
"shallow" drop.</p>

<p>Additionally, outTransformElements and 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=8&originalVersion=7">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