Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Wiki Markup
{span:style=font-size:2em;font-weight:bold} Debugging and

...

...

Logging Messages

CXF uses Java SE Logging 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.

Configuration files are probably best. They offer two benefits over programmatic configuration:

  1. Logging requirements can be altered without needing to recompile the code
  2. 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

Enabling message logging through configuration files is shown here.

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

Code Block
 Logging {span}

{toc}

h1. Logging Messages

CXF uses [Java SE Logging|http://www.oracle.com/technology/pub/articles/hunter_logging.html] 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.

Configuration files are probably best.  They offer two benefits over programmatic configuration:  
# Logging requirements can be altered without needing to recompile the code
# 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

Enabling message logging through configuration files is shown [here|http://cxf.apache.org/docs/configuration.html].  

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

{code}
import javax.xml.ws.Endpoint;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.EndpointImpl;

Object implementor = new GreeterImpl();
EndpointImpl ep = (EndpointImpl) Endpoint.publish("http://localhost/service", implementor);

ep.getServer().getEndpoint().getInInterceptors().add(new LoggingInInterceptor());
ep.getServer().getEndpoint().getOutInterceptors().add(new LoggingOutInterceptor());
{code}


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.

...



{code
}
import org.apache.cxf.feature.Features;

@javax.jws.WebService(portName = "MyWebServicePort", serviceName = "MyWebService", ...)
@Features(features = "org.apache.cxf.feature.LoggingFeature")        
public class MyWebServicePortTypeImpl implements MyWebServicePortType {
{code}

or (equivalent)

...



{code
}
import org.apache.cxf.interceptor.InInterceptors;
import org.apache.cxf.interceptor.OutInterceptors;

@javax.jws.WebService(portName = "WebServicePort", serviceName = "WebServiceService", ...)
@InInterceptors(interceptors = "org.apache.cxf.interceptor.LoggingInInterceptor")
@OutInterceptors(interceptors = "org.apache.cxf.interceptor.LoggingOutInterceptor")
public class WebServicePortTypeImpl implements WebServicePortType {
{code}


For programmatic client-side logging, the following code snippet can be used as an example:

...



{code
}
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;

public class WSClient {
    public static void main (String[] args) {
        MyService ws = new MyService();
        MyPortType port = ws.getPort();
        
        Client client = ClientProxy.getClient(port);
        client.getInInterceptors().add(new LoggingInInterceptor());
        client.getOutInterceptors().add(new LoggingOutInterceptor()); 
        
        // make WS calls...

Configure logging levels.

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:

Code Block
xmlxml

{code}

h2. Configure logging levels. 

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:

{code:xml}
.level= FINE
java.util.logging.ConsoleHandler.level = FINE
{code}

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

...



{code
:xml
xml
}
<target name="runClient">
   <java classname="client.WSClient" fork="true">	    	
      <classpath>
         <pathelement location="${build.classes.dir}"/>
         <fileset dir="${env.CXF_HOME}/lib">
            <include name="*.jar"/>
         </fileset>
      </classpath>
      <jvmarg value="-Djava.util.logging.config.file=/usr/myclientapp/logging.properties"/>
   </java>
</target>

...

{code}

h2. Using Log4j Instead of java.util.logging

...

 

As noted above, CXF uses the {{java.util.logging}} package by default. But it is possible to switch CXF to instead use [Log4J|http://logging.apache.org/log4j/]. This is achieved through the use of configuration files. There are two options to bootstrapping CXF logging and each is listed below:

...

 

* Add the following system property to the classpath from which CXF is initialized:

...

Code Block
 

{code}
-Dorg.apache.cxf.Logger=org.apache.cxf.common.logging.Log4jLogger

...

{code}

* Add the file {{META-INF/cxf/org.apache.cxf.Logger}} to the classpath and make sure it contains the following content:

...

Code Block
 

{code}
org.apache.cxf.common.logging.Log4jLogger

...


{code}

h2. Using SLF4J Instead of java.util.logging (since 2.2.8)

...



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:

...

 

* Add the following system property to the classpath from which CXF is initialized:

...

Code Block
 

{code}
-Dorg.apache.cxf.Logger=org.apache.cxf.common.logging.Slf4jLogger

...


{code}

* Add the file {{META-INF/cxf/org.apache.cxf.Logger}} to the classpath and make sure it contains the following content:

...

Code Block
 

{code}
org.apache.cxf.common.logging.Slf4jLogger

Debugging Tools

Eclipse IDE

See this blog entry 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.

NetBeans IDE

NetBeans include a debugger, profiler and an HTTP monitor that can assist in troubleshooting SOA applications.

tcpmon and tcptrace

tcpmon allows you to easily view messages as they go back and forth on the wire. The companion utility tcptrace can be used for analysis of the dump.

WSMonitor

WSMonitor in another option to Tcpmon with slightly more functionality.

NetSniffer

NetSniffer makes it possible to track the network traffic between arbitrary devices within a LAN segment.

Wireshark

Wireshark, 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 blog entry for more information.

SOAP UI

SOAP UI 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 the Eclipse IDE, NetBeans IDE and IntelliJ IDEA.

Helpful Tools and Utilities

WSDL Viewer

WSDL Viewer is a small tool to visualize the web-service in a more intuitive way.

cURL

cURL is a command line tool for transferring data with URL syntax, supporting DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, TELNET and TFTP. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, kerberos...), file transfer resume, proxy tunneling and a busload of other useful tricks.

Sonar

Sonar is an open source quality management platform, dedicated to continuously analyze and measure source code quality, from the portfolio to the method. Here is CXF on Sonar.

Fisheye

...


{code}

h1. Debugging Tools

h2. Eclipse IDE

See this [blog entry|http://www.jroller.com/gmazza/entry/eclipse_debug_web_services] 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.

h2. NetBeans IDE
NetBeans include a [debugger|http://www.netbeans.org/features/java/debugger.html], [profiler|http://www.netbeans.org/features/java/profiler.html] and an HTTP monitor that can assist in troubleshooting SOA applications.

h2. tcpmon and tcptrace
[tcpmon|http://tcpmon.dev.java.net] allows you to easily view messages as they go back and forth on the wire. The companion utility [tcptrace|http://www.tcptrace.org] can be used for analysis of the dump.

h2. WSMonitor
[WSMonitor|https://wsmonitor.dev.java.net/] in another option to Tcpmon with slightly more functionality.

h2. NetSniffer
[NetSniffer|http://www.miray.de/products/sat.netsniffer.html] makes it possible to track the network traffic between arbitrary devices within a LAN segment.

h2. Wireshark
[Wireshark|http://www.wireshark.org/], 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 [blog entry|http://www.jroller.com/gmazza/entry/soap_calls_over_wireshark] for more information.

h2. SOAP UI
[SOAP UI|http://soapui.org] 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 the [Eclipse IDE|http://soapui.org/IDE-Plugins/eclipse-plugin.html], [NetBeans IDE|http://www.soapui.org/IDE-Plugins/netbean.html] and [IntelliJ IDEA|http://www.soapui.org/IDE-Plugins/intellij.html].

h1. Helpful Tools and Utilities

h2. WSDL Viewer
[WSDL Viewer|http://tomi.vanek.sk/index.php?page=wsdl-viewer] is a small tool to visualize the web-service in a more intuitive way. 

h2. cURL
[cURL|http://curl.haxx.se/] is a command line tool for transferring data with URL syntax, supporting DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, TELNET and TFTP. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, kerberos...), file transfer resume, proxy tunneling and a busload of other useful tricks. 

h2. Sonar
[Sonar|http://www.sonarsource.org/] is an open source quality management platform, dedicated to continuously analyze and measure source code quality, from the portfolio to the method. Here is [CXF on Sonar|http://nemo.sonarsource.org/project/index/117804].

h2. Fisheye
 [Fisheye|http://www.atlassian.com/software/fisheye/] provides a web interface for Subversion, Git, CVS, Perforce & ClearCase source control repositories. Here is [CXF on Fisheye|https://fisheye6.atlassian.com/browse/cxf].