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 > Configuration
Date Fri, 11 Jan 2013 10:18: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/Configuration">Configuration</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 (4)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-unchanged" >h1. Configuration <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">...
<br></td></tr>
            <tr><td class="diff-unchanged" > <br>h2. Subpages <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >*Enabling message logging using plain
Spring bean elements* <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{note}Using
this format is STRONGLY discouraged as it ties your configuration with internal CXF class
names (like SpringBus).  It is much better to use the cxf:bus element described below <br>{note}
<br> <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" >{code} <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >In this example, you specify that
the CXF bus is implemented by class org.apache.cxf.bus.spring.SpringBus, and that <span
class="diff-changed-words">it<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">&#39;</span>s</span>
id is &quot;cxf&quot;. This is the default, but you have to re-iterate the fact if
you want the bus to contribute the logging interceptors to the outbound and inbound interceptor
chain for all client and server endpoints. You can avoid this duplication by using the next
form of configuration: <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;">{note}Using
this format is STRONGLY discouraged as it ties your configuration with internal CXF class
names (like SpringBus).  It is much better to use the cxf:bus element described below <br>{note}
<br> <br> <br></td></tr>
            <tr><td class="diff-unchanged" >*Enabling message logging using custom
CXF bean elements* <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h1><a name="Configuration-Configuration"></a>Configuration</h1>

<h2><a name="Configuration-Subpages"></a>Subpages</h2>
<ul><li><a href="/confluence/display/CXF20DOC/Bus+Configuration" title="Bus
Configuration">Bus Configuration</a></li><li><a href="/confluence/display/CXF20DOC/FeaturesList"
title="FeaturesList">FeaturesList</a></li><li><a href="/confluence/display/CXF20DOC/JMX+Management"
title="JMX Management">JMX Management</a></li><li><a href="/confluence/display/CXF20DOC/WSAConfiguration"
title="WSAConfiguration">WSAConfiguration</a></li><li><a href="/confluence/display/CXF20DOC/WSPConfiguration"
title="WSPConfiguration">WSPConfiguration</a></li><li><a href="/confluence/display/CXF20DOC/WSRMConfiguration"
title="WSRMConfiguration">WSRMConfiguration</a></li></ul>

<h2><a name="Configuration-SupplyingaConfigurationfiletoCXF"></a>Supplying
a Configuration file to CXF</h2>
<p>CXF can discover XML configuration files which you have written. For both web service
clients and servers, the default location that CXF will look for a configuration for is "/cxf.xml"
on the class path. For example, when running your application in a servlet container, this
file is expected to be located in a /WEB-INF/classes folder of your web application.</p>

<p>If you wish to override this location, you can specify a command line property: -Dcxf.config.file=some_other_config.xml.
This custom configuration file is also expected to be on the class path.</p>

<p>To use a url as the configuration location, specify as follows: -Dcxf.config.file.url=config_file_url.</p>


<p>A CXF configuration file is really a <a href="http://springframework.org" class="external-link"
rel="nofollow">Spring</a> configuration file, so all configuration files will start
with the following:</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>
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"&gt;

<span class="code-tag"><span class="code-comment">&lt;!-- Configuration goes
here! --&gt;</span></span>

<span class="code-tag">&lt;/beans&gt;</span>
</pre>
</div></div>

<p>If you are new to Spring or do not desire to learn more about it, don't worry, you
won't have to. The only piece of Spring that you will see is the &lt;beans&gt; element
outlined above. Simply create this file, place it on your classpath, and add the configuration
for a component you wish to configure (see below).  Note starting with CXF 2.6.0, Maven users
will need to add the following dependency for the cxf.xml file to be read:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;dependency&gt;</span>
   <span class="code-tag">&lt;groupId&gt;</span>org.springframework<span
class="code-tag">&lt;/groupId&gt;</span>
   <span class="code-tag">&lt;artifactId&gt;</span>spring-context<span
class="code-tag">&lt;/artifactId&gt;</span>
   <span class="code-tag">&lt;version&gt;</span>3.0.6.RELEASE<span
class="code-tag">&lt;/version&gt;</span>  (or most recent supported)
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

<h2><a name="Configuration-TypesofConfigurationfiles"></a>Types of Configuration
files</h2>

<h3><a name="Configuration-Clientconfigurationfile"></a>Client configuration
file  </h3>

<p>Placing a cxf.xml file (or other-named file as configured above) in the classpath
of the Web Service Client can be used to configure client-specific functionality.  For example,
the following client cxf.xml file turns off <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.4"
class="external-link" rel="nofollow">chunked transfer encoding</a> for a specific
service in requests and responses:</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:http-conf</span>=<span class="code-quote">"http://cxf.apache.org/transports/http/configuration"</span>
       xsi:schemaLocation="http://cxf.apache.org/transports/http/configuration
           http://cxf.apache.org/schemas/configuration/http-conf.xsd
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd"&gt;

  &lt;http-conf:conduit 
           name=<span class="code-quote">"{urn:ebay:apis:eBLBaseComponents}Shopping.http-conduit"</span>&gt;
      <span class="code-tag">&lt;http-conf:client AllowChunking=<span class="code-quote">"false"</span>/&gt;</span>
  <span class="code-tag">&lt;/http-conf:conduit&gt;</span>
<span class="code-tag">&lt;/beans&gt;</span>
</pre>
</div></div>

<h3><a name="Configuration-Serverconfigurationfiles"></a>Server configuration
files</h3>

<p>Typically, the cxf.xml file in the classpath of the web service is intended primarily
for configuration of the CXF bus, the object used for the creation of all services and endpoints.
 Endpoint configuration is primarily done either via a WEB-INF/cxf-servlet.xml file or a Spring
application context file designated by the web application deployment descriptor (web.xml
file).  The cxf-servlet.xml file is somewhat slower because it loads all possible CXF modules
for an endpoint; the Spring application context method is faster because it allows you to
specify which CXF modules are needed.</p>

<p>For an example configuration via a cxf-servlet.xml file, our <a href="http://svn.apache.org/viewvc/cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/servlet/"
class="external-link" rel="nofollow">system tests</a> have a <a href="http://svn.apache.org/viewvc/cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/servlet/cxf-servlet.xml?view=markup"
class="external-link" rel="nofollow">cxf-servlet.xml file</a> which is explicitly
referenced in the init-param element in the <a href="http://svn.apache.org/viewvc/cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/servlet/web-external.xml?view=markup"
class="external-link" rel="nofollow">web.xml</a> deployment descriptor.  (Note it
is not necessary to use the <b>init-param</b> element if you use the file name
"cxf-servlet.xml"; this is the default name that CXF uses to look for such a file.)</p>

<p>For an example of using a Spring application context file for endpoint configuration,
refer to our <a href="http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/java_first_spring_support/"
class="external-link" rel="nofollow">Java First Spring Support</a> sample.  You can
see how the web.xml deployment descriptor explicitly references the beans.xml application
context file via a <b>context-param</b> element (and ContextLoaderListener object);
also that the application context file manually imports the three cxf modules that it needs.</p>

<h1><a name="Configuration-WhatcanIconfigureandhowdoIdoit%3F"></a>What can
I configure and how do I do it?</h1>
<p>If you want to change CXF's default behaviour, enable specific functionality or fine
tune a component's behaviour, you can in most cases do so without writing a single line of
code, simply by supplying a Spring configuration file. <br/>
In some cases it also possible to achieve the same end by extending your wsdl contract: you
can add CXF specific extension elements to the wsdl:port element and in that way fine tune
the behaviour of the specified transport. Or you can use WS-Policy to express the fact that
your application uses WS-Addressing, for example.</p>

<p>Using Spring configuration files however is the most versatile way to achieve a specific
goal: you can use it to</p>

<ol>
	<li>Enable functionality via simple constructs called features.</li>
	<li>Set properties of runtime components by referring to these runtime components using
either plain Spring bean elements, or, more conveniently, using CXF custom beans elements.</li>
	<li>Modify the actual composition of the runtime (change the way the runtime is wired
up).</li>
</ol>


<p>The following examples show the what the Spring configuration would look like if
you wanted to enable the logging of inbound and outbound messages and faults.</p>

<p><b>Enabling message logging using plain Spring bean elements</b></p>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>Using this format is STRONGLY
discouraged as it ties your configuration with internal CXF class names (like SpringBus).
 It is much better to use the cxf:bus element described below</td></tr></table></div>

<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>
    xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"&gt;

    <span class="code-tag">&lt;bean id=<span class="code-quote">"logInbound"</span>
class=<span class="code-quote">"org.apache.cxf.interceptor.LoggingInInterceptor"</span>/&gt;</span>
    <span class="code-tag">&lt;bean id=<span class="code-quote">"logOutbound"</span>
class=<span class="code-quote">"org.apache.cxf.interceptor.LoggingOutInterceptor"</span>/&gt;</span>
	
    <span class="code-tag">&lt;bean id=<span class="code-quote">"cxf"</span>
class=<span class="code-quote">"org.apache.cxf.bus.spring.SpringBus"</span>&gt;</span>
        <span class="code-tag">&lt;property name=<span class="code-quote">"inInterceptors"</span>&gt;</span>
            <span class="code-tag">&lt;list&gt;</span>
                <span class="code-tag">&lt;ref bean=<span class="code-quote">"logInbound"</span>/&gt;</span>
            <span class="code-tag">&lt;/list&gt;</span>
        <span class="code-tag">&lt;/property&gt;</span>
        <span class="code-tag">&lt;property name=<span class="code-quote">"outInterceptors"</span>&gt;</span>
            <span class="code-tag">&lt;list&gt;</span>
                <span class="code-tag">&lt;ref bean=<span class="code-quote">"logOutbound"</span>/&gt;</span>
            <span class="code-tag">&lt;/list&gt;</span>
        <span class="code-tag">&lt;/property&gt;</span>
        <span class="code-tag">&lt;property name=<span class="code-quote">"outFaultInterceptors"</span>&gt;</span>
            <span class="code-tag">&lt;list&gt;</span>
                <span class="code-tag">&lt;ref bean=<span class="code-quote">"logOutbound"</span>/&gt;</span>
            <span class="code-tag">&lt;/list&gt;</span>
        <span class="code-tag">&lt;/property&gt;</span>
        <span class="code-tag">&lt;property name=<span class="code-quote">"inFaultInterceptors"</span>&gt;</span>
            <span class="code-tag">&lt;list&gt;</span>
                <span class="code-tag">&lt;ref bean=<span class="code-quote">"logInbound"</span>/&gt;</span>
            <span class="code-tag">&lt;/list&gt;</span>
        <span class="code-tag">&lt;/property&gt;</span>
    <span class="code-tag">&lt;/bean&gt;</span> 
<span class="code-tag">&lt;/beans&gt;</span>
</pre>
</div></div>

<p>In this example, you specify that the CXF bus is implemented by class org.apache.cxf.bus.spring.SpringBus,
and that its id is "cxf". This is the default, but you have to re-iterate the fact if you
want the bus to contribute the logging interceptors to the outbound and inbound interceptor
chain for all client and server endpoints. You can avoid this duplication by using the next
form of configuration:</p>

<p><b>Enabling message logging using custom CXF bean elements</b></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>
      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"&gt;

    <span class="code-tag">&lt;bean id=<span class="code-quote">"logInbound"</span>
class=<span class="code-quote">"org.apache.cxf.interceptor.LoggingInInterceptor"</span>/&gt;</span>
    <span class="code-tag">&lt;bean id=<span class="code-quote">"logOutbound"</span>
class=<span class="code-quote">"org.apache.cxf.interceptor.LoggingOutInterceptor"</span>/&gt;</span>

    <span class="code-tag">&lt;cxf:bus&gt;</span>
        <span class="code-tag">&lt;cxf:inInterceptors&gt;</span>
            <span class="code-tag">&lt;ref bean=<span class="code-quote">"logInbound"</span>/&gt;</span>
        <span class="code-tag">&lt;/cxf:inInterceptors&gt;</span>
        <span class="code-tag">&lt;cxf:outInterceptors&gt;</span>
            <span class="code-tag">&lt;ref bean=<span class="code-quote">"logOutbound"</span>/&gt;</span>
        <span class="code-tag">&lt;/cxf:outInterceptors&gt;</span>
        <span class="code-tag">&lt;cxf:outFaultInterceptors&gt;</span>
            <span class="code-tag">&lt;ref bean=<span class="code-quote">"logOutbound"</span>/&gt;</span>
        <span class="code-tag">&lt;/cxf:outFaultInterceptors&gt;</span>
        <span class="code-tag">&lt;cxf:inFaultInterceptors&gt;</span>
            <span class="code-tag">&lt;ref bean=<span class="code-quote">"logInbound"</span>/&gt;</span>
        <span class="code-tag">&lt;/cxf:inFaultInterceptors&gt;</span>
    <span class="code-tag">&lt;/cxf:bus&gt;</span> 
<span class="code-tag">&lt;/beans&gt;</span>
</pre>
</div></div>

<p>Here, there is no need to specify the implementation class of the bus - nor the fact
that the inInterceptors, outInterceptors, outFaultInterceptors, and inFaultInterceptors child
elements are of type list. All of this information is embedded in the underlying schema and
the bean definition parser that's invoked for &lt;cxf:bus&gt; elemens. Note that you
have to specify the location of this schema in the schemaLocation attribute of the &lt;beans&gt;
element so that Spring can validate the configuration file. But it gets even simpler in the
next example:</p>

<p><b>Enabling message logging using the Logging feature</b></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>
      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"&gt;

    <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;/beans&gt;</span>
</pre>
</div></div>

<p>The following sections explain which of the above mechanisms (feature, custom CXF
bean or plain Spring bean; or indeed others such as wsdl extensors or policy assertions) you
can use to enable and/or configure the various components in CXF, and what your configuration
options are:</p>

<ul>
	<li><a href="/confluence/display/CXF20DOC/Bus+Configuration" title="Bus Configuration">Bus</a></li>
	<li><a href="/confluence/display/CXF20DOC/JAX-WS+Configuration" title="JAX-WS Configuration">JAX&#45;WS
Configuration</a></li>
	<li>HTTP <a href="/confluence/display/CXF20DOC/Client+HTTP+Transport+%28including+SSL+support%29"
title="Client HTTP Transport (including SSL support)">Client</a> and <a href="/confluence/display/CXF20DOC/Standalone+HTTP+Transport"
title="Standalone HTTP Transport">Server</a></li>
	<li><a href="/confluence/display/CXF20DOC/JMS+Transport" title="JMS Transport">JMS
Transport</a></li>
	<li>Soap Binding</li>
	<li>XML Binding</li>
	<li><a href="/confluence/display/CXF20DOC/WSAConfiguration" title="WSAConfiguration">WS-Addressing</a></li>
	<li><a href="/confluence/display/CXF20DOC/WSRMConfiguration" title="WSRMConfiguration">WS-Reliable
Messaging</a></li>
	<li><a href="/confluence/display/CXF20DOC/WSPConfiguration" title="WSPConfiguration">WS-Policy
Framework</a></li>
</ul>


<p>For a list of available features, see <a href="/confluence/display/CXF20DOC/FeaturesList"
title="FeaturesList">here</a>.</p>

<h2><a name="Configuration-AdvancedConfiguration"></a>Advanced Configuration</h2>
<p>If you are writing your own component for CXF, please see <a href="/confluence/display/CXF20DOC/Configuration+for+Developers"
title="Configuration for Developers">Configuration for Developers</a> page.</p>
    </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/Configuration">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=46346&revisedVersion=36&originalVersion=35">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CXF20DOC/Configuration?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message