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 Sep 2009 15:59:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CXF20DOC&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/CXF20DOC/Configuration">Configuration</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~christian%2Bschneider">Christian
Schneider</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <h1><a name="Configuration-Subpages"></a>Subpages</h1>
<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>

<h1><a name="Configuration-SupplyingaConfigurationfiletoCXF"></a>Supplying
a Configuration file to CXF</h1>
<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" 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).</p>

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

<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"
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/src/test/java/org/apache/cxf/systest/servlet/"
rel="nofollow">system tests</a> have a <a href="http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/cxf-servlet.xml?view=markup"
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/src/test/java/org/apache/cxf/systest/servlet/web.xml?view=markup"
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://tinyurl.com/3bp7xn" rel="nofollow">Java First Spring Support</a>
sample.  You can see how the <a href="http://tinyurl.com/33se9c" rel="nofollow">web.xml</a>
deployment descriptor explicitly references the <a href="http://tinyurl.com/382xvp" rel="nofollow">beans.xml</a>
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="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.CXFBusImpl"</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;/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.CXFBusImpl,
and that it's 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:inFaultInterceptors&gt;</span>
            <span class="code-tag">&lt;ref bean=<span class="code-quote">"logOutbound"</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 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>

<h1><a name="Configuration-AdvancedConfiguration"></a>Advanced Configuration</h1>
<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="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/CXF20DOC/Configuration">View
Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=46346&revisedVersion=29&originalVersion=28">View
Change</a>
              |
       <a href="http://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