blob: bb2e484dc0e989cdceef90c7807343197cf046d5 [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 - XSLT Feature">
<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 src='/resources/highlighter/scripts/shBrushJava.js'></script>
<script>
SyntaxHighlighter.defaults['toolbar'] = false;
SyntaxHighlighter.all();
</script>
<title>
Apache CXF -- XSLT Feature
</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="configuration.html">Configuration</a>&nbsp;&gt;&nbsp;<a href="featureslist.html">FeaturesList</a>&nbsp;&gt;&nbsp;<a href="xslt-feature.html">XSLT Feature</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="XSLTFeature-XSLTFeature">XSLT Feature</h1><p><style type="text/css">/*<![CDATA[*/
div.rbtoc1636141671312 {padding: 0px;}
div.rbtoc1636141671312 ul {list-style: disc;margin-left: 0px;}
div.rbtoc1636141671312 li {margin-left: 0px;padding-left: 0px;}
/*]]>*/</style></p><div class="toc-macro rbtoc1636141671312">
<ul class="toc-indentation"><li><a shape="rect" href="#XSLTFeature-XSLTFeature">XSLT Feature</a></li><li><a shape="rect" href="#XSLTFeature-WhenshouldIusetheTransformationFeatureandwhentheXSLTFeature?">When should I use the Transformation Feature and when the XSLT Feature?</a></li><li><a shape="rect" href="#XSLTFeature-Springconfiguration">Spring configuration</a></li><li><a shape="rect" href="#XSLTFeature-ConfiguringtheXSLTFeaturefromSpring/Blueprint">Configuring the XSLT Feature from Spring/Blueprint</a></li><li><a shape="rect" href="#XSLTFeature-ConfiguringtheXSLTinterceptorsincode">Configuring the XSLT interceptors in code</a></li><li><a shape="rect" href="#XSLTFeature-XSLTinterceptorsandphases">XSLT interceptors and phases</a></li><li><a shape="rect" href="#XSLTFeature-Supportedmessagecontents">Supported message contents</a></li></ul>
</div><p>The CXF XSLT Feature is an alternative to the <a shape="rect" href="http://cxf.apache.org/docs/transformationfeature.html">CXF Transformation Feature</a>, providing a flexible way to dynamically transform XML messages. <br clear="none"> The XSLT Feature applies custom XSL transformations to inbound and/or outbound messages.</p><h1 id="XSLTFeature-WhenshouldIusetheTransformationFeatureandwhentheXSLTFeature?">When should I use the Transformation Feature and when the XSLT Feature?</h1><p>If only trivial transformations must be done, it is recommended to use the lightweight and fast Transformation Feature. It covers most use cases such as:</p><ul><li>dropping the namespace of the outbound messages;</li><li>qualifying the incoming message;</li><li>changing namespaces;</li><li>appending or dropping elements;</li><li>converting attributes to elements.</li></ul><p>The Transformation Feature is completely stream oriented and works fast especially for large messages.</p><p>If you should apply non-trivial transformations, not supported by Transformation Feature - it is a use case for the XSLT Feature. Here you can write any custom XSL Transformation and apply it to inbound and/or outbound messages. As the Xalan XSLT engine is actually not completely stream oriented, the XSLT Feature breaks streaming. However it uses the high-performance DTM (Document Table Model) instead of the complete DOM model. Performance can be improved in the future by using further versions of Xalan or other XSLT engines (like Saxon or STX oriented Joost).</p><h1 id="XSLTFeature-Springconfiguration">Spring configuration</h1><p>It is necessary to configure the location of the XSLT script for inbound or/and outbound transformation. Example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default">&lt;bean id="xsltFeature" class="org.apache.cxf.feature.transform.XSLTFeature"&gt;
&lt;property name="inXSLTPath" value="requestTransformation.xsl" /&gt;
&lt;property name="outXSLTPath" value="responseTransformation.xsl" /&gt;
&lt;/bean&gt;
</pre>
</div></div><p>The XSLT scripts should be available from the classpath. If the XSLT path is not specified, no transformation will be done.</p><h1 id="XSLTFeature-ConfiguringtheXSLTFeaturefromSpring/Blueprint">Configuring the XSLT Feature from Spring/Blueprint</h1><p>The feature can be configured in spring or blueprint for JAX-WS or JAX-RS clients and endpoints. Example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default">&lt;jaxws:client id="customerService" serviceName="customer:CustomerServiceService"
endpointName="customer:CustomerServiceEndpoint" address="http://localhost:9091/CustomerServicePort"
serviceClass="com.example.customerservice.CustomerService"&gt;
&lt;jaxws:features&gt;
&lt;ref bean="xsltFeature" /&gt;
&lt;/jaxws:features&gt;
&lt;/jaxws:client&gt;
&lt;jaxws:endpoint xmlns:customer="http://customerservice.example.com/"
id="CustomerServiceHTTP" address="http://localhost:9090/CustomerServicePort"
serviceName="customer:CustomerServiceService" endpointName="customer:CustomerServiceEndpoint"
implementor="com.example.customerservice.server.CustomerServiceImpl"&gt;
&lt;jaxws:features&gt;
&lt;ref bean="xsltFeature" /&gt;
&lt;/jaxws:features&gt;
&lt;/jaxws:endpoint&gt;
</pre>
</div></div><h1 id="XSLTFeature-ConfiguringtheXSLTinterceptorsincode">Configuring the XSLT interceptors in code</h1><p>Here is how a JAX-WS client can be configured:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default"> CustomerServiceService service = new CustomerServiceService();
CustomerService customerService = service.getCustomerServicePort();
Client client = ClientProxy.getClient(customerService);
XSLTOutInterceptor outInterceptor = new XSLTOutInterceptor(Phase.PRE_STREAM, StaxOutInterceptor.class, null,
XSLT_REQUEST_PATH);
client.getOutInterceptors().add(outInterceptor);
</pre>
</div></div><h1 id="XSLTFeature-XSLTinterceptorsandphases">XSLT interceptors and phases</h1><p>By default XSLT interceptors run on POST_STREAM and PRE_STREAM phases. In some cases it may be needed to change the phase, for example, the in transformation has to be applied after the encrypted payload has been decrypted and its signature checked. For such transformations to succeed XSLTInInterceptor/XSLTOutInterceptor will need to be created with a constructor accepting a 'phase' String parameter. Additionally you can specify before and after interceptors for this phase as further constructor parameters.</p><h1 id="XSLTFeature-Supportedmessagecontents">Supported message contents</h1><p>The XSLT interceptors support the following message contents:</p><ul><li>InputStream/OutputStream;</li><li>Reader/Writer;</li><li>XMLStreamReader/XMLStreamWriter.</li></ul><p>Therefore the interceptors can be used on different phases. XSLT Interceptors were tested with JMS Transport uses JMS Text messages (produces Reader/Writer message contents).</p></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=30741563">edit page</a>)
(<a href="https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=30741563&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>