Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Logging Messages, Debugging

...

Tools and Helpful Utilities

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.

...

Code Block
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
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>

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. This is achieved through the use of configuration files. There are two options to bootstrapping CXF logging and each is listed below:

...

Code Block
org.apache.cxf.common.logging.Log4jLogger

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. This is achieved through the use of configuration files. There are two options to bootstrapping CXF logging and each is listed below:

...

Code Block
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

TCPMon allows you to easily view messages as they go back and forth on the wire.

WSMonitor

WSMonitor in another option to Tcpmon with slightly more functionality.

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 Eclipse, IDEA and NetBeans.

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.

Helpful Utilities

WSDL Viewer

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

cURL

cURLis 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.