This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

What's Feature

A Feature is something that is able to customize a Server, Client, or Bus, typically adding capabilities. For instance, there may be a LoggingFeature which configures one of the above to log each of their messages.
By default the initialize methods all delegate to initializeProvider(InterceptorProvider), If you're simply adding interceptors to a Server, Client, or Bus, this allows you to add them easily.

public abstract class AbstractFeature {
    public void initialize(Server server, Bus bus) {
        initializeProvider(server.getEndpoint(), bus);
    public void initialize(Client client, Bus bus) {
        initializeProvider(client, bus);
    public void initialize(Bus bus) {
        initializeProvider(bus, bus);
    protected void initializeProvider(InterceptorProvider provider, Bus bus) {
        // you could customized 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 <T> T getActive(List<AbstractFeature> features,
                                  Class<T> type) {
        T active = null;
        if (features != null) {
            for (AbstractFeature feature : features) {
                if (type.isInstance(feature)) {
                    active = type.cast(feature);
        return active;

Writing and configure the feature

CXF provides several features for configure different capabilities, such as logging, failover, policies, addressing , reliable messaging. You can go to the CXF Features for information.

Writing a feature

It is very easy to write a new feature , your feature just need to extends the AbstractFeature and implement initializeProvider or write customizing code for configuring client or server interceptors. Here is an example for implementing the logging feature.

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;
    protected void initializeProvider(InterceptorProvider provider, Bus bus) {
        if (limit == DEFAULT_LIMIT) {
        } else {
            LoggingInInterceptor in = new LoggingInInterceptor(limit);
            LoggingOutInterceptor out = new LoggingOutInterceptor(limit);

     * 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;

Adding feature programmatically

To add the feature to both server and client, you can use the Feature annotation on the service class

    @org.apache.cxf.feature.Features (features = "org.apache.cxf.jaxws.service.AnnotationFeature")
    public class HelloServiceImpl implements HelloService {
        public String sayHi() {
            return "HI";

You can also add the feature to the server by using ServerFactoryBean ,or the client by using the ClientFactoryBean

import org.apache.cxf.frontend.ServerFactoryBean;
import org.apache.cxf.frontend.ClientFactoryBean;
ServerFactoryBean serverFactoryBean = new ServerFactoryBean();
MyFeature myFeature = new MyFeature();
// added my feature to the serverFactoryBean
serverFactoryBean.setFeatures(new ArrayList().add(myFeature));

ClientFactoryBean clientFactoryBean = new ClientFactoryBean();
clientFactoryBean.setFeatures(new ArrayList().add(myFeature));

Adding a feature through configuration

Here are some examples on using configuration files to add features.
You can find more information about the CXF provides at CXF Features

<beans xmlns=""
    <!-- adding the feature to the bus-->

    <bean id="myfeature" class="com.example.Myfeature"/>
    <!-- adding the feature to the client -->    
    <jaxws:client id="client" 
         <bean ref="myfeature" />
    <!-- adding the feature to the server -->
    <jaxws:server id="server" serviceBean="org.apache.hello_world_soap_http.GreetImpl" address="http://localhost:8080/simpleWithAddress">
        <bean class="com.example.Myfeature"/>

  • No labels