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 > Debugging and Logging
Date Tue, 04 May 2010 22:19:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/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="http://cwiki.apache.org/confluence/display/CXF20DOC/Debugging+and+Logging">Debugging
and Logging</a></h2>
    <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~cleclerc">Cyrille
Le Clerc</a>
    </h4>
        <div id="versionComment">
        <b>Comment:</b>
        Document usage of Slf4jLogger<br />
    </div>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
            <table class="diff" cellpadding="0" cellspacing="0">
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h1.
Using SLF4J Instead of java.util.logging (since 2.2.8) <br> <br>As noted above,
CXF uses the {{java.util.logging}} package by default. But it is possible to switch CXF to
instead use [SLF4J|http://www.slf4j.org/]. This is achieved through the use of configuration
files. There are two options to bootstrapping CXF logging and each is listed below:  <br>
<br>* Add the following system property to the classpath from which CXF is initialized:
 <br> <br>{code} <br>-Dorg.apache.cxf.Logger=org.apache.cxf.common.logging.Slf4jLogger
<br>{code} <br> <br>* Add the file {{META-INF/cxf/org.apache.cxf.Logger}}
to the classpath and make sure it contains the following content:  <br> <br>{code}
<br>org.apache.cxf.common.logging.Slf4jLogger <br>{code} <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h1. Debugging Tools <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h1><a name="DebuggingandLogging-LoggingMessages"></a>Logging Messages</h1>

<p>CXF uses <a href="http://www.oracle.com/technology/pub/articles/hunter_logging.html"
class="external-link" rel="nofollow">Java SE Logging</a> for both client- and server-side
logging of SOAP requests and responses.  Logging is activated by use of separate in/out interceptors
that can be attached to the client and/or service as required.  These interceptors can be
specified either programmatically (via Java code and/or annotations) or via use of configuration
files.</p>

<p>Configuration files are probably best.  They offer two benefits over programmatic
configuration:  </p>
<ol>
	<li>Logging requirements can be altered without needing to recompile the code</li>
	<li>No Apache CXF-specific APIs need to be added to your code, which helps it remain
interoperable with other JAX-WS compliant web service stacks</li>
</ol>


<p>Enabling message logging through configuration files is shown <a href="http://cxf.apache.org/docs/configuration.html"
class="external-link" rel="nofollow">here</a>.  </p>

<p>For programmatic configuration, the logging interceptors can be added to your service
endpoint as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">import</span> javax.xml.ws.Endpoint;
<span class="code-keyword">import</span> org.apache.cxf.interceptor.LoggingInInterceptor;
<span class="code-keyword">import</span> org.apache.cxf.interceptor.LoggingOutInterceptor;
<span class="code-keyword">import</span> org.apache.cxf.jaxws.EndpointImpl;

<span class="code-object">Object</span> implementor = <span class="code-keyword">new</span>
GreeterImpl();
EndpointImpl ep = (EndpointImpl) Endpoint.publish(<span class="code-quote">"http:<span
class="code-comment">//localhost/service"</span>, implementor);
</span>
ep.getServer().getEndpoint().getInInterceptors().add(<span class="code-keyword">new</span>
LoggingInInterceptor());
ep.getServer().getEndpoint().getOutInterceptors().add(<span class="code-keyword">new</span>
LoggingOutInterceptor());
</pre>
</div></div>


<p>For web services running on CXFServlet, the below annotations can be used on either
the SEI or the SEI implementation class.  If placed on the SEI, they activate logging both
for client and server; if on the SEI implementation class, they are relevant just for server-side
logging.</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.feature.Features;

@javax.jws.WebService(portName = <span class="code-quote">"MyWebServicePort"</span>,
serviceName = <span class="code-quote">"MyWebService"</span>, ...)
@Features(features = <span class="code-quote">"org.apache.cxf.feature.LoggingFeature"</span>)
       
<span class="code-keyword">public</span> class MyWebServicePortTypeImpl <span
class="code-keyword">implements</span> MyWebServicePortType {
</pre>
</div></div>

<p>or (equivalent)</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.interceptor.InInterceptors;
<span class="code-keyword">import</span> org.apache.cxf.interceptor.OutInterceptors;

@javax.jws.WebService(portName = <span class="code-quote">"WebServicePort"</span>,
serviceName = <span class="code-quote">"WebServiceService"</span>, ...)
@InInterceptors(interceptors = <span class="code-quote">"org.apache.cxf.interceptor.LoggingInInterceptor"</span>)
@OutInterceptors(interceptors = <span class="code-quote">"org.apache.cxf.interceptor.LoggingOutInterceptor"</span>)
<span class="code-keyword">public</span> class WebServicePortTypeImpl <span
class="code-keyword">implements</span> WebServicePortType {
</pre>
</div></div>


<p>For programmatic client-side logging, the following code snippet can be used as an
example:</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.endpoint.Client;
<span class="code-keyword">import</span> org.apache.cxf.frontend.ClientProxy;
<span class="code-keyword">import</span> org.apache.cxf.interceptor.LoggingInInterceptor;
<span class="code-keyword">import</span> org.apache.cxf.interceptor.LoggingOutInterceptor;

<span class="code-keyword">public</span> class WSClient {
    <span class="code-keyword">public</span> <span class="code-keyword">static</span>
void main (<span class="code-object">String</span>[] args) {
        MyService ws = <span class="code-keyword">new</span> MyService();
        MyPortType port = ws.getPort();
        
        Client client = ClientProxy.getClient(port);
        client.getInInterceptors().add(<span class="code-keyword">new</span> LoggingInInterceptor());
        client.getOutInterceptors().add(<span class="code-keyword">new</span>
LoggingOutInterceptor()); 
        
        <span class="code-comment">// make WS calls...</span>
</pre>
</div></div>

<h1><a name="DebuggingandLogging-Configurelogginglevels."></a>Configure
logging levels. </h1>

<p>In the /etc folder of the CXF distribution there is a sample Java SE logging.properties
file you can use to configure logging.  For example, if you want to change the console logging
level from WARNING to FINE, you need to update two properties in this logging.properties file
as below:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
.level= FINE
java.util.logging.ConsoleHandler.level = FINE
</pre>
</div></div>

<p>Once this is done, you will need to set the <b>-Djava.util.logging.config.file</b>
property to the location of the logging.properties file.  As an example, the Ant target below
has this property set:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;target name=<span class="code-quote">"runClient"</span>&gt;</span>
   <span class="code-tag">&lt;java classname=<span class="code-quote">"client.WSClient"</span>
fork=<span class="code-quote">"true"</span>&gt;</span>	    	
      <span class="code-tag">&lt;classpath&gt;</span>
         <span class="code-tag">&lt;pathelement location=<span class="code-quote">"${build.classes.dir}"</span>/&gt;</span>
         <span class="code-tag">&lt;fileset dir=<span class="code-quote">"${env.CXF_HOME}/lib"</span>&gt;</span>
            <span class="code-tag">&lt;include name=<span class="code-quote">"*.jar"</span>/&gt;</span>
         <span class="code-tag">&lt;/fileset&gt;</span>
      <span class="code-tag">&lt;/classpath&gt;</span>
      <span class="code-tag">&lt;jvmarg value=<span class="code-quote">"-Djava.util.logging.config.file=/usr/myclientapp/logging.properties"</span>/&gt;</span>
   <span class="code-tag">&lt;/java&gt;</span>
<span class="code-tag">&lt;/target&gt;</span>
</pre>
</div></div>

<h1><a name="DebuggingandLogging-UsingLog4jInsteadofjava.util.logging"></a>Using
Log4j Instead of java.util.logging </h1>

<p>As noted above, CXF uses the <tt>java.util.logging</tt> package by default.
But it is possible to switch CXF to instead use <a href="http://logging.apache.org/log4j/"
class="external-link" rel="nofollow">Log4J</a>. This is achieved through the use
of configuration files. There are two options to bootstrapping CXF logging and each is listed
below: </p>

<ul>
	<li>Add the following system property to the classpath from which CXF is initialized:</li>
</ul>


<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
-Dorg.apache.cxf.Logger=org.apache.cxf.common.logging.Log4jLogger
</pre>
</div></div>

<ul>
	<li>Add the file <tt>META-INF/cxf/org.apache.cxf.Logger</tt> to the classpath
and make sure it contains the following content:</li>
</ul>


<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
org.apache.cxf.common.logging.Log4jLogger
</pre>
</div></div>

<h1><a name="DebuggingandLogging-UsingSLF4JInsteadofjava.util.logging%28since2.2.8%29"></a>Using
SLF4J Instead of java.util.logging (since 2.2.8)</h1>

<p>As noted above, CXF uses the <tt>java.util.logging</tt> package by default.
But it is possible to switch CXF to instead use <a href="http://www.slf4j.org/" class="external-link"
rel="nofollow">SLF4J</a>. This is achieved through the use of configuration files.
There are two options to bootstrapping CXF logging and each is listed below: </p>

<ul>
	<li>Add the following system property to the classpath from which CXF is initialized:</li>
</ul>


<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
-Dorg.apache.cxf.Logger=org.apache.cxf.common.logging.Slf4jLogger
</pre>
</div></div>

<ul>
	<li>Add the file <tt>META-INF/cxf/org.apache.cxf.Logger</tt> to the classpath
and make sure it contains the following content:</li>
</ul>


<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
org.apache.cxf.common.logging.Slf4jLogger
</pre>
</div></div>

<h1><a name="DebuggingandLogging-DebuggingTools"></a>Debugging Tools</h1>

<h2><a name="DebuggingandLogging-EclipseIDE"></a>Eclipse IDE</h2>

<p>See this <a href="http://www.jroller.com/gmazza/entry/eclipse_debug_web_services"
class="external-link" rel="nofollow">blog entry</a> for information on debugging
web services using Eclipse.  Note this is primarily for tracing/debugging source code; you
will probably still want to use one of the tools below to capture network traffic, view SOAP
requests and responses, etc.</p>

<h2><a name="DebuggingandLogging-Tcpmon"></a>Tcpmon</h2>
<p><a href="http://tcpmon.dev.java.net" class="external-link" rel="nofollow">TCPMon</a>
allows you to easily view messages as they go back and forth on the wire.</p>

<h2><a name="DebuggingandLogging-WSMonitor"></a>WSMonitor</h2>
<p><a href="https://wsmonitor.dev.java.net/" class="external-link" rel="nofollow">WSMonitor</a>
in another option to Tcpmon with slightly more functionality.</p>

<h2><a name="DebuggingandLogging-SOAPUI"></a>SOAP UI</h2>
<p><a href="http://soapui.org" class="external-link" rel="nofollow">SOAP UI</a>
can also be used for debugging. In addition to viewing messages, it allows you send messages
and load test your services. It also has plugins for Eclipse, IDEA and NetBeans.</p>

<h2><a name="DebuggingandLogging-Wireshark"></a>Wireshark</h2>
<p><a href="http://www.wireshark.org/" class="external-link" rel="nofollow">Wireshark</a>,
a network packet analyzer, is useful for following the routing of SOAP messages.  It can also
help when you are getting an HTML error message from the server that your CXF client cannot
normally process, by allowing you to see the non-SOAP error message.  See this <a href="http://www.jroller.com/gmazza/entry/soap_calls_over_wireshark"
class="external-link" rel="nofollow">blog entry</a> for more information.</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/Debugging+and+Logging">View
Online</a>
        |
        <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=29161&revisedVersion=24&originalVersion=23">View
Changes</a>
                |
        <a href="http://cwiki.apache.org/confluence/display/CXF20DOC/Debugging+and+Logging?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message