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 > Features
Date Wed, 23 Jan 2013 10:51: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/Features">Features</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~coheigea@apache.org">Colm
O hEigeartaigh</a>
    </h4>
        <br/>
                         <h4>Changes (16)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">h1.
What&#39;s Feature <br>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. <br>By default the
initialize methods all delegate to initializeProvider(InterceptorProvider), If you&#39;re
simply adding interceptors to a Server, Client, or Bus, this allows you to add them easily.
<br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h1.
Features in CXF <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">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 AbstractFeature below. By default
the initialize methods all delegate to initializeProvider(InterceptorProvider), so if you&#39;re
simply adding interceptors to a Server, Client, or Bus, this allows you to add them easily.
<br> <br></td></tr>
            <tr><td class="diff-unchanged" >{code:java} <br>public abstract
class AbstractFeature { <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >        initializeProvider(server.getEndpoint(),
bus); <br>    } <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-unchanged" >    public void initialize(Client
client, Bus bus) { <br>        initializeProvider(client, bus); <br>    } <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-unchanged" >    public void initialize(Bus bus)
{ <br>        initializeProvider(bus, bus); <br>    } <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-unchanged" >    protected void initializeProvider(InterceptorProvider
provider, Bus bus) { <br>        // you could customized the interceptors in the provider
here <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >    /** <br>     * Convenience
method to extract a feature by type from an active list. <br></td></tr>
            <tr><td class="diff-unchanged" >     * <br></td></tr>
            <tr><td class="diff-unchanged" >     * @param features the given feature
list <br>     * @param type the feature type required <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" >h1. Writing and configure the
<span class="diff-changed-words"><span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">f</span><span
class="diff-added-chars"style="background-color: #dfd;">F</span>eature</span>
<br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">CXF
provides several features for configure different capabilities, such as logging, failover,
policies, addressing , reliable messaging. You can go to the [FeaturesList] for information.
<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.
Writing a feature <br>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. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">CXF
provides several features to configure commonly used capabilities, such as logging, failover,
policies, addressing, reliable messaging. You can go to the [FeaturesList] for more information.
<br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h2.
Writing a Feature <br> <br>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. <br> <br></td></tr>
            <tr><td class="diff-unchanged" >{code:java} <br>public class
LoggingFeature extends AbstractFeature { <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >    private static final LoggingInInterceptor
IN = new LoggingInInterceptor(DEFAULT_LIMIT); <br>    private static final LoggingOutInterceptor
OUT = new LoggingOutInterceptor(DEFAULT_LIMIT); <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-unchanged" >    int limit = DEFAULT_LIMIT; <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-unchanged" >    @Override <br>    protected
void initializeProvider(InterceptorProvider provider, Bus bus) { <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >        limit = lim; <br>  
 } <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-unchanged" >    /** <br>     * Retrieve
the value set with {@link #setLimit(int)}. <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >    public int getLimit() { <br>
       return limit; <br></td></tr>
            <tr><td class="diff-unchanged" >    } <br></td></tr>
            <tr><td class="diff-unchanged" >} <br>{code} <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">h2.
Adding feature programmatically <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h2.
Adding a Feature programmatically <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >To add the feature <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> to both server and client, you can use the Feature annotation on the service
class <br></td></tr>
            <tr><td class="diff-unchanged" >{code:java} <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-unchanged" >    @org.apache.cxf.feature.Features
(features = &quot;org.apache.cxf.jaxws.service.AnnotationFeature&quot;) <br>
   public class HelloServiceImpl implements HelloService { <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >            return &quot;HI&quot;;
<br>        } <br></td></tr>
            <tr><td class="diff-unchanged" >    }
 <br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >You can also add the feature to
the server by using <span class="diff-changed-words">ServerFactoryBean<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span>,<span class="diff-added-chars"style="background-color: #dfd;"> </span>or</span>
the client by using the ClientFactoryBean <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{code:java} <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" >h2. Adding a <span class="diff-changed-words"><span
class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">f</span><span
class="diff-added-chars"style="background-color: #dfd;">F</span>eature</span>
through configuration <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
<br></td></tr>
            <tr><td class="diff-changed-lines" >Here are some examples on using
configuration files to add features. <span class="diff-added-words"style="background-color:
#dfd;">You can find more information about the CXF provides features at [FeaturesList].</span>
<br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">You
can find more information about the CXF provides features at [FeaturesList]. <br></td></tr>
            <tr><td class="diff-unchanged" >{code:xml} <br>&lt;beans
xmlns=&quot;http://www.springframework.org/schema/beans&quot; <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >            &lt;cxf:logging/&gt;
<br>        &lt;/cxf:features&gt; <br></td></tr>
            <tr><td class="diff-unchanged" >    &lt;/cxf:bus&gt; <br></td></tr>
            <tr><td class="diff-unchanged" > <br>    &lt;bean id=&quot;myfeature&quot;
class=&quot;com.example.Myfeature&quot;/&gt; <br></td></tr>
            <tr><td class="diff-unchanged" >
    &lt;!-- adding the feature to the client --&gt;
    &lt;jaxws:client id=&quot;client&quot;
        serviceClass=&quot;org.apache.hello_world_soap_http.Greeter&quot;
        wsdlLocation=&quot;wsdl/hello_world.wsdl&quot;&gt;
        &lt;jaxws:features&gt;
            &lt;bean ref=&quot;myfeature&quot; /&gt;
        &lt;jaxws:features&gt; <br></td></tr>
            <tr><td class="diff-unchanged" >    &lt;/jaxws:client&gt;
<br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-unchanged" >    &lt;!-- adding the feature
to the server --&gt; <br>    &lt;jaxws:server id=&quot;server&quot;
serviceBean=&quot;org.apache.hello_world_soap_http.GreetImpl&quot; address=&quot;http://localhost:8080/simpleWithAddress&quot;&gt;
<br></td></tr>
            <tr><td class="diff-unchanged" >        &lt;jaxws:features&gt;
            &lt;bean class=&quot;com.example.Myfeature&quot;/&gt;
        &lt;/jaxws:features&gt; <br></td></tr>
            <tr><td class="diff-unchanged" >    &lt;/jaxws:server&gt;
<br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h1><a name="Features-FeaturesinCXF"></a>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 AbstractFeature 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" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> <span class="code-keyword">abstract</span>
class AbstractFeature {
    <span class="code-keyword">public</span> void initialize(Server server, Bus
bus) {
        initializeProvider(server.getEndpoint(), bus);
    }

    <span class="code-keyword">public</span> void initialize(Client client, Bus
bus) {
        initializeProvider(client, bus);
    }

    <span class="code-keyword">public</span> void initialize(Bus bus) {
        initializeProvider(bus, bus);
    }

    <span class="code-keyword">protected</span> void initializeProvider(InterceptorProvider
provider, Bus bus) {
        <span class="code-comment">// you could customized the interceptors in the provider
here
</span>    }

    /**
     * Convenience method to extract a feature by type from an active list.
     *
     * @param features the given feature list
     * @param type the feature type required
     * @<span class="code-keyword">return</span> the feature of the specified
type <span class="code-keyword">if</span> active
     */
    <span class="code-keyword">public</span> <span class="code-keyword">static</span>
&lt;T&gt; T getActive(List&lt;AbstractFeature&gt; features,
                                  <span class="code-object">Class</span>&lt;T&gt;
type) {
        T active = <span class="code-keyword">null</span>;
        <span class="code-keyword">if</span> (features != <span class="code-keyword">null</span>)
{
            <span class="code-keyword">for</span> (AbstractFeature feature : features)
{
                <span class="code-keyword">if</span> (type.isInstance(feature))
{
                    active = type.<span class="code-keyword">cast</span>(feature);
                    <span class="code-keyword">break</span>;
                }
            }
        }
        <span class="code-keyword">return</span> active;
    }
}

</pre>
</div></div>

<h1><a name="Features-WritingandconfiguretheFeature"></a>Writing and configure
the Feature</h1>

<p>CXF provides several features to configure commonly used capabilities, such as logging,
failover, policies, addressing, reliable messaging. You can go to the <a href="/confluence/display/CXF20DOC/FeaturesList"
title="FeaturesList">FeaturesList</a> for more information.</p>

<h2><a name="Features-WritingaFeature"></a>Writing a Feature</h2>

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

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> class LoggingFeature <span class="code-keyword">extends</span>
AbstractFeature {
    <span class="code-keyword">private</span> <span class="code-keyword">static</span>
<span class="code-keyword">final</span> <span class="code-object">int</span>
DEFAULT_LIMIT = 100 * 1024;
    <span class="code-keyword">private</span> <span class="code-keyword">static</span>
<span class="code-keyword">final</span> LoggingInInterceptor IN = <span class="code-keyword">new</span>
LoggingInInterceptor(DEFAULT_LIMIT);
    <span class="code-keyword">private</span> <span class="code-keyword">static</span>
<span class="code-keyword">final</span> LoggingOutInterceptor OUT = <span class="code-keyword">new</span>
LoggingOutInterceptor(DEFAULT_LIMIT);

    <span class="code-object">int</span> limit = DEFAULT_LIMIT;

    @Override
    <span class="code-keyword">protected</span> void initializeProvider(InterceptorProvider
provider, Bus bus) {
        <span class="code-keyword">if</span> (limit == DEFAULT_LIMIT) {
            provider.getInInterceptors().add(IN);
            provider.getInFaultInterceptors().add(IN);
            provider.getOutInterceptors().add(OUT);
            provider.getOutFaultInterceptors().add(OUT);
        } <span class="code-keyword">else</span> {
            LoggingInInterceptor in = <span class="code-keyword">new</span> LoggingInInterceptor(limit);
            LoggingOutInterceptor out = <span class="code-keyword">new</span>
LoggingOutInterceptor(limit);
            provider.getInInterceptors().add(in);
            provider.getInFaultInterceptors().add(in);
            provider.getOutInterceptors().add(out);
            provider.getOutFaultInterceptors().add(out);
        }
    }

    /**
     * This function has no effect at <span class="code-keyword">this</span> time.
     * @param lim
     */
    <span class="code-keyword">public</span> void setLimit(<span class="code-object">int</span>
lim) {
        limit = lim;
    }

    /**
     * Retrieve the value set with {@link #setLimit(<span class="code-object">int</span>)}.
     * @<span class="code-keyword">return</span>
     */
    <span class="code-keyword">public</span> <span class="code-object">int</span>
getLimit() {
        <span class="code-keyword">return</span> limit;
    }
}
</pre>
</div></div>

<h2><a name="Features-AddingaFeatureprogrammatically"></a>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" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">

    @org.apache.cxf.feature.Features (features = <span class="code-quote">"org.apache.cxf.jaxws.service.AnnotationFeature"</span>)
    <span class="code-keyword">public</span> class HelloServiceImpl <span class="code-keyword">implements</span>
HelloService {
        <span class="code-keyword">public</span> <span class="code-object">String</span>
sayHi() {
            <span class="code-keyword">return</span> <span class="code-quote">"HI"</span>;
        }
    }

</pre>
</div></div>

<p>You can also add the feature to the server by using ServerFactoryBean, or the client
by using the ClientFactoryBean</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">import</span> org.apache.cxf.frontend.ServerFactoryBean;
<span class="code-keyword">import</span> org.apache.cxf.frontend.ClientFactoryBean;
...
ServerFactoryBean serverFactoryBean = <span class="code-keyword">new</span> ServerFactoryBean();
MyFeature myFeature = <span class="code-keyword">new</span> MyFeature();
<span class="code-comment">// added my feature to the serverFactoryBean
</span>serverFactoryBean.setFeatures(<span class="code-keyword">new</span>
ArrayList().add(myFeature));
...

ClientFactoryBean clientFactoryBean = <span class="code-keyword">new</span> ClientFactoryBean();
clientFactoryBean.setFeatures(<span class="code-keyword">new</span> ArrayList().add(myFeature));
...

</pre>
</div></div>

<h2><a name="Features-AddingaFeaturethroughconfiguration"></a>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 href="/confluence/display/CXF20DOC/FeaturesList"
title="FeaturesList">FeaturesList</a>.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
&lt;beans xmlns=<span class="code-quote">"http://www.springframework.org/schema/beans"</span>
      <span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
      <span class="code-keyword">xmlns:cxf</span>=<span class="code-quote">"http://cxf.apache.org/core"</span>
      <span class="code-keyword">xmlns:jaxws</span>=<span class="code-quote">"http://cxf.apache.org/jaxws"</span>
      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;
    <span class="code-tag"><span class="code-comment">&lt;!-- adding the feature
to the bus--&gt;</span></span>
    <span class="code-tag">&lt;cxf:bus&gt;</span>
        <span class="code-tag">&lt;cxf:features&gt;</span>
            <span class="code-tag">&lt;cxf:logging/&gt;</span>
        <span class="code-tag">&lt;/cxf:features&gt;</span>
    <span class="code-tag">&lt;/cxf:bus&gt;</span>

    <span class="code-tag">&lt;bean id=<span class="code-quote">"myfeature"</span>
class=<span class="code-quote">"com.example.Myfeature"</span>/&gt;</span>

    <span class="code-tag"><span class="code-comment">&lt;!-- adding the feature
to the client --&gt;</span></span>
    &lt;jaxws:client id=<span class="code-quote">"client"</span>
        serviceClass=<span class="code-quote">"org.apache.hello_world_soap_http.Greeter"</span>
        wsdlLocation=<span class="code-quote">"wsdl/hello_world.wsdl"</span>&gt;
        <span class="code-tag">&lt;jaxws:features&gt;</span>
            <span class="code-tag">&lt;bean ref=<span class="code-quote">"myfeature"</span>
/&gt;</span>
        <span class="code-tag">&lt;jaxws:features&gt;</span>
    <span class="code-tag">&lt;/jaxws:client&gt;</span>

    <span class="code-tag"><span class="code-comment">&lt;!-- adding the feature
to the server --&gt;</span></span>
    <span class="code-tag">&lt;jaxws:server id=<span class="code-quote">"server"</span>
serviceBean=<span class="code-quote">"org.apache.hello_world_soap_http.GreetImpl"</span>
address=<span class="code-quote">"http://localhost:8080/simpleWithAddress"</span>&gt;</span>
        <span class="code-tag">&lt;jaxws:features&gt;</span>
            <span class="code-tag">&lt;bean class=<span class="code-quote">"com.example.Myfeature"</span>/&gt;</span>
        <span class="code-tag">&lt;/jaxws:features&gt;</span>
    <span class="code-tag">&lt;/jaxws:server&gt;</span>

<span class="code-tag">&lt;/beans&gt;</span>
</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/Features">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=78449&revisedVersion=4&originalVersion=3">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CXF20DOC/Features?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message