blob: f4735385bb6a8e464d0a77fd97765d54a37e76fc [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 - Features">
<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 -- Features
</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="advanced-integration.html">Advanced Integration</a>&nbsp;&gt;&nbsp;<a href="features.html">Features</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="Features-FeaturesinCXF">Features in CXF</h1><p>A Feature in CXF is a way of adding capabilities to a Server, Client or Bus. For example, you could add the ability to log messages for each of these objects, by configuring them with a LoggingFeature. To implement a Feature, you must subclass <a shape="rect" class="external-link" href="https://github.com/apache/cxf/blob/master/core/src/main/java/org/apache/cxf/feature/AbstractFeature.java" rel="nofollow">AbstractFeature</a> below. By default the initialize methods all delegate to initializeProvider(InterceptorProvider), so if you're simply adding interceptors to a Server, Client, or Bus, this allows you to add them easily.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default">public abstract class AbstractFeature extends WebServiceFeature implements Feature {
public String getID() {
return getClass().getName();
}
public void initialize(Server server, Bus bus) {
initializeProvider(server.getEndpoint(), bus);
}
public void initialize(Client client, Bus bus) {
initializeProvider(client, bus);
}
public void initialize(InterceptorProvider interceptorProvider, Bus bus) {
initializeProvider(interceptorProvider, bus);
}
public void initialize(Bus bus) {
initializeProvider(bus, bus);
}
protected void initializeProvider(InterceptorProvider provider, Bus bus) {
// you could customize the interceptors in the provider here
}
/**
* Convenience method to extract a feature by type from an active list.
*
* @param features the given feature list
* @param type the feature type required
* @return the feature of the specified type if active
*/
public static &lt;T&gt; T getActive(List&lt;? extends Feature&gt; features,
Class&lt;T&gt; type) {
T active = null;
if (features != null) {
for (Feature feature : features) {
if (type.isInstance(feature)) {
active = type.cast(feature);
break;
}
}
}
return active;
}
}
</pre>
</div></div><h1 id="Features-WritingandconfiguringtheFeature">Writing and configuring the Feature</h1><p>CXF provides several features to configure commonly used capabilities, such as logging, failover, policies, addressing, and reliable messaging. You can go to the <a shape="rect" href="featureslist.html">FeaturesList</a> for more information.</p><h2 id="Features-WritingaFeature">Writing a Feature</h2><p>It is very easy to write a new feature; your feature just needs to extends the&#160;<a shape="rect" class="external-link" href="https://github.com/apache/cxf/blob/master/core/src/main/java/org/apache/cxf/feature/AbstractFeature.java" rel="nofollow">AbstractFeature</a> and implement initializeProvider or write customizing code for configuring client or server interceptors. Here is an example for implementing the logging feature.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default">public class LoggingFeature extends AbstractFeature {
private static final int DEFAULT_LIMIT = 100 * 1024;
private static final LoggingInInterceptor IN = new LoggingInInterceptor(DEFAULT_LIMIT);
private static final LoggingOutInterceptor OUT = new LoggingOutInterceptor(DEFAULT_LIMIT);
int limit = DEFAULT_LIMIT;
@Override
protected void initializeProvider(InterceptorProvider provider, Bus bus) {
if (limit == DEFAULT_LIMIT) {
provider.getInInterceptors().add(IN);
provider.getInFaultInterceptors().add(IN);
provider.getOutInterceptors().add(OUT);
provider.getOutFaultInterceptors().add(OUT);
} else {
LoggingInInterceptor in = new LoggingInInterceptor(limit);
LoggingOutInterceptor out = new LoggingOutInterceptor(limit);
provider.getInInterceptors().add(in);
provider.getInFaultInterceptors().add(in);
provider.getOutInterceptors().add(out);
provider.getOutFaultInterceptors().add(out);
}
}
/**
* This function has no effect at this time.
* @param lim
*/
public void setLimit(int lim) {
limit = lim;
}
/**
* Retrieve the value set with {@link #setLimit(int)}.
* @return
*/
public int getLimit() {
return limit;
}
}
</pre>
</div></div><h2 id="Features-AddingaFeatureprogrammatically">Adding a Feature programmatically</h2><p>To add the feature to both server and client, you can use the Feature annotation on the service class</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default">@org.apache.cxf.feature.Features (features = "org.apache.cxf.jaxws.service.AnnotationFeature")
public class HelloServiceImpl implements HelloService {
public String sayHi() {
return "HI";
}
}
</pre>
</div></div><p>You can also add the feature to the server by using ServerFactoryBean, or the client by using the ClientFactoryBean or the ClientProxyFactoryBean</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default">import org.apache.cxf.frontend.ServerFactoryBean;
import org.apache.cxf.frontend.ClientFactoryBean;
import org.apache.cxf.frontend.ClientProxyFactoryBean;
...
ServerFactoryBean serverFactoryBean = new ServerFactoryBean();
MyFeature myFeature = new MyFeature();
// added my feature to the serverFactoryBean
serverFactoryBean.setFeatures(Collections.singletonList(myFeature));
...
ClientFactoryBean clientFactoryBean = new ClientFactoryBean();
clientFactoryBean.setFeatures(Collections.singletonList(myFeature));
...
ClientProxyFactoryBean clientFactoryBean = new ClientProxyFactoryBean();
clientFactoryBean.setFeatures(Collections.singletonList(policyFeature));&#160;</pre>
</div></div><p>It is also possible to add a feature when publishing an Endpoint via Endpoint.publish. For example, the Logging feature can be added as follows:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Endpoint.publish</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default">import javax.xml.ws.Endpoint;
import org.apache.cxf.ext.logging.LoggingFeature;
...
CustomerService implementor = new CustomerServiceImpl();
Endpoint.publish("http://localhost:9090/CustomerServicePort",
implementor,
new LoggingFeature());</pre>
</div></div><p>&#160;</p><h2 id="Features-AddingaFeaturethroughconfiguration">Adding a Feature through configuration</h2><p>Here are some examples on using configuration files to add features. You can find more information about the CXF provides features at <a shape="rect" href="featureslist.html">FeaturesList</a>.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default">&lt;beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://cxf.apache.org/core"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"&gt;
&#160;&lt;!-- adding the feature to the bus--&gt;
&lt;cxf:bus&gt;
&lt;cxf:features&gt;
&lt;cxf:logging/&gt;
&lt;/cxf:features&gt;
&lt;/cxf:bus&gt;
&lt;bean id="myfeature" class="com.example.Myfeature"/&gt;
&lt;!-- adding the feature to the client --&gt;
&lt;jaxws:client id="client"
serviceClass="org.apache.hello_world_soap_http.Greeter"
wsdlLocation="wsdl/hello_world.wsdl"&gt;
&lt;jaxws:features&gt;
&lt;bean ref="myfeature" /&gt;
&lt;jaxws:features&gt;
&lt;/jaxws:client&gt;
&lt;!-- adding the feature to the server --&gt;
&lt;jaxws:server id="server" serviceBean="org.apache.hello_world_soap_http.GreetImpl" address="http://localhost:8080/simpleWithAddress"&gt;
&lt;jaxws:features&gt;
&lt;bean class="com.example.Myfeature"/&gt;
&lt;/jaxws:features&gt;
&lt;/jaxws:server&gt;
&lt;/beans&gt;
</pre>
</div></div></div>
</div>
<!-- Content -->
</td>
</tr>
</table>
</td>
<td id="cell-2-2" colspan="2">&nbsp;</td>
</tr>
<tr>
<td id="cell-3-0">&nbsp;</td>
<td id="cell-3-1">&nbsp;</td>
<td id="cell-3-2">
<div id="footer">
<!-- Footer -->
<div id="site-footer">
<a href="http://cxf.apache.org/privacy-policy.html">Privacy Policy</a> -
(<a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=78449">edit page</a>)
(<a href="https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=78449&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>