You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Gary Weaver <ga...@duke.edu> on 2008/06/10 23:08:06 UTC

how do I enable logging of the SOAP request and response in CXF in straight Java?

Hello again,

In Axis2 I was able to enable logging of the SOAP request and response 
along with the headers using the following in log4j.properties:

log4j.logger.httpclient.wire.content=DEBUG #SOAP Request and Response
log4j.logger.httpclient.wire.header=DEBUG #HTTP Headers

However, in CXF, when I turn on full debug logging in log4j.properties via:

log4j.rootCategory=DEBUG, ...

I did a search through the log produced after calling the service and 
getting a response, but it appeared that the request and response were 
not logged.

I then read at the following page how to configure the logging 
interceptors using Spring:
http://cwiki.apache.org/CXF20DOC/configuration.html

However, the examples were all using Spring, which is fine, but for this 
simple test client, I was just using Java. Should I just switch to using 
the Spring config to configure CXF to enable logging, or is there an 
easy enough way to turn on logging either via log4j.properties (even 
though I don't think there is, since I had it on full-force) or via Java 
code?

Thanks in advance,

Gary

-- 
Gary Weaver
Internet Framework Services
Office of Information Technology
Duke University


RE: how do I enable logging of the SOAP request and response in CXF in straight Java?

Posted by Sergey Pulyaev <Se...@intego-group.com>.
I made this by implementing SOAP interceptor, store the message in
message and then get it if needed:

Add the following:
IN ApplicationContext.xml
    <bean id="messInterceptor" class="logging.SAAJInterceptor"/>
    <cxf:bus>
        <cxf:inInterceptors>
            <ref bean="messInterceptor" />
        </cxf:inInterceptors>
    </cxf:bus>

Create class  logging/SAAJInterceptor.java

package logging;
import javax.xml.soap.SOAPMessage;

import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor;
import org.apache.cxf.interceptor.Fault;

public class SAAJInterceptor extends SAAJInInterceptor {

    @Override
    public void handleMessage(SoapMessage message) throws Fault {
        super.handleMessage(message);
        message.put("SAAJ", message.getContent(SOAPMessage.class));
    }

}


Get the message if needed using:

      @Autowired
    	private WebServiceContext webServiceContext;

	Object getSOAPMessage(){
            WrappedMessageContext msgContext = ((WrappedMessageContext)
webServiceContext.getMessageContext());
            Object obj = msgContext.get("SAAJ");
	}

-----Original Message-----
From: Gary Weaver [mailto:gary.weaver@duke.edu] 
Sent: Wednesday, June 11, 2008 12:08 AM
To: users@cxf.apache.org
Subject: how do I enable logging of the SOAP request and response in CXF
in straight Java?

Hello again,

In Axis2 I was able to enable logging of the SOAP request and response 
along with the headers using the following in log4j.properties:

log4j.logger.httpclient.wire.content=DEBUG #SOAP Request and Response
log4j.logger.httpclient.wire.header=DEBUG #HTTP Headers

However, in CXF, when I turn on full debug logging in log4j.properties
via:

log4j.rootCategory=DEBUG, ...

I did a search through the log produced after calling the service and 
getting a response, but it appeared that the request and response were 
not logged.

I then read at the following page how to configure the logging 
interceptors using Spring:
http://cwiki.apache.org/CXF20DOC/configuration.html

However, the examples were all using Spring, which is fine, but for this

simple test client, I was just using Java. Should I just switch to using

the Spring config to configure CXF to enable logging, or is there an 
easy enough way to turn on logging either via log4j.properties (even 
though I don't think there is, since I had it on full-force) or via Java

code?

Thanks in advance,

Gary

-- 
Gary Weaver
Internet Framework Services
Office of Information Technology
Duke University


--------
This data is for general information only and shall not be used to produce documents of any kind without same being submitted to, reviewed by, and approved by Intego in writing. All data is subject to change. User assumes all liability relating to the use of this data and agrees to release, indemnify, and hold harmless Intego from any and all claims relating said use. User is responsible to check for any viruses before use. 

Re: Problem with CXF 2.0.6 and 2.1 setting objects on request to null when they are defined in response

Posted by Gary Weaver <ga...@duke.edu>.
Daniel,


Daniel Kulp wrote:
> Most likely, the response isn't correct compared to what CXF is 
> expecting (actually, in this case, JAXB as CXF has nothing to do with 
> this part).   The usual culprit for this is element qualification 
> issues and without seeing the wsdl/schema and the actual soap message, 
> it would be hard for me to diagnose.   Double check the soap message 
> to make sure the child elements are qualified or not qualified as per 
> the schema in the wsdl.    If the schema has 
> elementFormDefault=unqualified (or no elementFormDefault), the 
> elements should be unqualifed.   If the schema says 
> elementFormDefault=qualified, they need to be qualified.

Thanks!!! In the wsdl it specifies elementFormDefault="qualified"(twice, 
once for request namespace and once for response namespace). In the 
response, the namespace is only defined once in the first element of the 
data within the response, and it isn't the same namespace as the one 
defined for the response in the WSDL. So the namespace in the response 
not matching the namespace in the request was the problem.

I just verified that was the case by changing the response's namespace 
in the WSDL to match the namespace of the actual response and it finally 
works!!! (I'm now waiting on our guys to see if they can make the 
response namespace match the one that is defined for the response in the 
WSDL.)

Thanks again!!!

>>
>> An additional mystery (which may have something to do with it?) is 
>> that I've found that when I don't setAllowChunking(false) on a policy 
>> and set on the conduit, I get a server error back from the service 
>> I'm calling.
>
>
> Some of the older services toolkits don't support chunking.    Turning 
> chunking off drops performance by nearly 10% in some cases and 
> consumes more memory, but is required when working with some older 
> toolkits.
>

Thanks! I'll make sure to try to get a request in for them to update 
their service to support chunking.

Gary

-- 
Gary Weaver
Internet Framework Services
Office of Information Technology
Duke University


Re: Problem with CXF 2.0.6 and 2.1 setting objects on request to null when they are defined in response

Posted by Daniel Kulp <dk...@apache.org>.
On Jun 11, 2008, at 12:00 PM, Gary Weaver wrote:

> Hello,
>
> I'm having a problem in CXF 2.0.6, 2.1, and 2.1-SNAPSHOT  
> (20080605.204511-10) where objects on the response object are null,  
> but from looking at the output of the SOAP response coming back,  
> logged by CXF, CXF should have set those objects on the response.
>
> For example, in the code in TestClient.java below, when I call  
> sendRequest(...) I get back a response object, and I can see in the  
> logs the SOAP request and response, and they look good (the response  
> has all of the fields it is supposed to). However, when I call any  
> of the get methods on the response to get at the request data, they  
> all return null. :(

Most likely, the response isn't correct compared to what CXF is  
expecting (actually, in this case, JAXB as CXF has nothing to do with  
this part).   The usual culprit for this is element qualification  
issues and without seeing the wsdl/schema and the actual soap message,  
it would be hard for me to diagnose.   Double check the soap message  
to make sure the child elements are qualified or not qualified as per  
the schema in the wsdl.    If the schema has  
elementFormDefault=unqualified (or no elementFormDefault), the  
elements should be unqualifed.   If the schema says  
elementFormDefault=qualified, they need to be qualified.

>
> An additional mystery (which may have something to do with it?) is  
> that I've found that when I don't setAllowChunking(false) on a  
> policy and set on the conduit, I get a server error back from the  
> service I'm calling.


Some of the older services toolkits don't support chunking.    Turning  
chunking off drops performance by nearly 10% in some cases and  
consumes more memory, but is required when working with some older  
toolkits.

Dan


>
>
> HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
> httpClientPolicy.setAllowChunking(false);
> conduit.setClient(httpClientPolicy);
>
> Could you take a quick look at the code below and let me know if  
> there is anything I'm doing that I shouldn't be doing or should be  
> doing differently?
>
> Also, please let me know if there is anything I should look at to  
> determine why it isn't serializing the response back correctly. I  
> have full debug logging on in log4j.properties.
>
> Thanks in advance,
> Gary
>
>
> Here are the classes:
>
> TestClient.java
> ===========
>
> ...
> import org.apache.cxf.configuration.jsse.TLSClientParameters;
> import org.apache.cxf.endpoint.Client;
> import org.apache.cxf.endpoint.Endpoint;
> import org.apache.cxf.frontend.ClientProxy;
> import org.apache.cxf.interceptor.LoggingInInterceptor;
> import org.apache.cxf.interceptor.LoggingOutInterceptor;
> import org.apache.cxf.transport.http.HTTPConduit;
> import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
> import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
> import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
> import org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor;
> import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor;
> import org.apache.ws.security.WSConstants;
> import org.apache.ws.security.handler.WSHandlerConstants;
>
> import javax.xml.ws.BindingProvider;
> import java.util.HashMap;
> import java.util.Map;
> ...
>
> public class TestClient {
>
>   private static String URL = "https://some.host:1234/path/to/the/service 
> ";
>
>   private TestClient() {
>   }
>
>   public static MyServiceResponseTypeShape sendRequest(String  
> someRequestParam) throws Exception {
>       MyService service = new MyService();
>       MyServicePortType portType = service.getMyServicePort();
>
>       Client client = ClientProxy.getClient(portType);
>       Endpoint endpoint = client.getEndpoint();
>
>       // Enable Logging
>       // from http://cwiki.apache.org/CXF20DOC/debugging.html
>       client.getInInterceptors().add(new LoggingInInterceptor());
>       client.getOutInterceptors().add(new LoggingOutInterceptor());
>
>       HTTPConduit conduit = (HTTPConduit) client.getConduit();
>
>       // for more info see: http://cwiki.apache.org/confluence/display/CXF20DOC/Client+HTTP+Transport+%28including+SSL+support%29
>       // set timeout
>       HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
>       //httpClientPolicy.setConnectionTimeout(36000);
>       httpClientPolicy.setAllowChunking(false);
>       //httpClientPolicy.setReceiveTimeout(32000);
>       conduit.setClient(httpClientPolicy);
>
>       // set endpoint, since the default one in the wsdl has wrong  
> protocol and port
>       TLSClientParameters params = conduit.getTlsClientParameters();
>       if (params == null) {
>           params = new TLSClientParameters();
>           conduit.setTlsClientParameters(params);
>       }
>
>       // NOTE! ONLY DO THIS FOR TESTING, NOT PRODUCTION!
>       // this is to get around the error:
>       // The https URL hostname does not match the Common Name (CN)  
> on the server certificate.  To disable this check (NOT recommended  
> for production) set the CXF client TLS configuration property  
> "disableCNCheck" to true.
>       params.setDisableCNCheck(true);
>
>       // override the endpoint that is defined in WSDL as http with  
> old port to be https with new port              ((BindingProvider)  
> portType 
> ).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,  
> URL);
>
>       // set username and password
>       // see: http://cwiki.apache.org/CXF20DOC/ws-security.html
>       // No security on client-side
>       Map<String, Object> inProps = new HashMap<String, Object>();
>       inProps.put(WSHandlerConstants.ACTION,  
> WSHandlerConstants.NO_SECURITY);
>       WSS4JInInterceptor wssIn = new WSS4JInInterceptor(inProps);
>       endpoint.getInInterceptors().add(wssIn);
>       endpoint.getInInterceptors().add(new SAAJInInterceptor()); //  
> 2.0.x only; not needed in 2.1+
>       // Server-side authN
>       Map<String, Object> outProps = new HashMap<String, Object>();
>       outProps.put(WSHandlerConstants.ACTION,  
> WSHandlerConstants.USERNAME_TOKEN);
>       outProps.put(WSHandlerConstants.USER, "my_username");
>       outProps.put(WSHandlerConstants.PASSWORD_TYPE,  
> WSConstants.PW_TEXT);
>       //outProps.put(WSHandlerConstants.PASSWORD_TYPE,  
> WSConstants.PW_DIGEST);
>       outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS,  
> MyCallbackHandler.class.getName());
>       WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
>       endpoint.getOutInterceptors().add(wssOut);
>       endpoint.getOutInterceptors().add(new  
> SAAJOutInterceptor()); // 2.0.x only; not needed in 2.1+
>
>       // note: createMyServiceRequestTypeShape() is a method on this  
> class that creates the request object
>       MyServiceRequestTypeShape req =  
> createMyServiceRequestTypeShape(someRequestParam);
>
>       return portType.doSomething(req);
>   }
>
>   public MyServiceRequestTypeShape  
> createMyServiceRequestTypeShape(String someRequestParam) {
>       ...
>   }
> }
>
> MyCallbackHandler.java
> ==================
>
> ...
>
> import org.apache.ws.security.WSPasswordCallback;
>
> import javax.security.auth.callback.Callback;
> import javax.security.auth.callback.UnsupportedCallbackException;
> import javax.security.auth.callback.CallbackHandler;
> import java.io.IOException;
>
> public class MyCallbackHandler implements CallbackHandler {
>
>   public void handle(Callback[] callbacks) throws IOException,  
> UnsupportedCallbackException {
>
>       WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
>
>       // set the password for our message.
>       pc.setPassword("my_password");
>   }
>
> }
>
> pom.xml
> ======
>
> <project xmlns="http://maven.apache.org/POM/4.0.0"
>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd 
> ">
>
>   <modelVersion>4.0.0</modelVersion>
>
>   <groupId>cxftestclient</groupId>
>   <artifactId>cxftestclient</artifactId>
>   <packaging>jar</packaging>
>
>   <name>CXF Integration Test</name>
>   <version>1.0-SNAPSHOT</version>
>
>   <properties>
>       <cxf.version>2.1.1-SNAPSHOT</cxf.version>
>   </properties>
>
>   <dependencies>
>       <dependency>
>           <groupId>commons-logging</groupId>
>           <artifactId>commons-logging</artifactId>
>           <version>1.1</version>
>           <scope>provided</scope>
>           <exclusions>
>               <exclusion>
>                   <groupId>logkit</groupId>
>                   <artifactId>logkit</artifactId>
>               </exclusion>
>               <exclusion>
>                   <groupId>avalon-framework</groupId>
>                   <artifactId>avalon-framework</artifactId>
>               </exclusion>
>               <exclusion>
>                   <groupId>javax.servlet</groupId>
>                   <artifactId>servlet-api</artifactId>
>               </exclusion>
>           </exclusions>
>       </dependency>
>
>       <dependency>
>           <groupId>org.apache.cxf</groupId>
>           <artifactId>cxf-rt-frontend-jaxws</artifactId>
>           <version>${cxf.version}</version>
>       </dependency>
>
>       <dependency>
>           <groupId>org.apache.cxf</groupId>
>           <artifactId>cxf-rt-transports-http</artifactId>
>           <version>${cxf.version}</version>
>       </dependency>
>
>       <dependency>
>           <groupId>org.apache.cxf</groupId>
>           <artifactId>cxf-rt-ws-security</artifactId>
>           <version>${cxf.version}</version>
>       </dependency>
>
>       <!-- Jetty is needed if you're are not using the CXFServlet -->
>       <dependency>
>           <groupId>org.apache.cxf</groupId>
>           <artifactId>cxf-rt-transports-http-jetty</artifactId>
>           <version>${cxf.version}</version>
>       </dependency>
>
>       <dependency>
>           <groupId>junit</groupId>
>           <artifactId>junit</artifactId>
>           <version>3.8.1</version>
>           <scope>test</scope>
>       </dependency>
>   </dependencies>
>
>   <build>
>       <plugins>
>           <plugin>
>               <artifactId>maven-compiler-plugin</artifactId>
>               <configuration>
>                   <source>1.5</source>
>                   <target>1.5</target>
>               </configuration>
>           </plugin>
>
>           <plugin>
>               <groupId>org.apache.cxf</groupId>
>               <artifactId>cxf-codegen-plugin</artifactId>
>               <version>${cxf.version}</version>
>               <executions>
>                   <execution>
>                       <id>generate-sources</id>
>                       <phase>generate-sources</phase>
>                       <configuration>
>                           <sourceRoot>${basedir}/target/generated/ 
> src/main/java</sourceRoot>
>                           <wsdlOptions>
>                               <wsdlOption>
>                                   <wsdl>${basedir}/src/main/wsdl/ 
> myService.wsdl</wsdl>
>                               </wsdlOption>
>                           </wsdlOptions>
>                       </configuration>
>                       <goals>
>                           <goal>wsdl2java</goal>
>                       </goals>
>                   </execution>
>               </executions>
>           </plugin>
>
>           <plugin>
>               <groupId>org.apache.maven.plugins</groupId>
>               <artifactId>maven-surefire-plugin</artifactId>
>               <configuration>
>                   <reportFormat>brief</reportFormat>
>                   <useFile>false</useFile>
>               </configuration>
>           </plugin>
>       </plugins>
>   </build>
>
>   <repositories>
>       <repository>
>           <id>central-m2-repository</id>
>           <name>Central Maven 2 Repository</name>
>           <url>http://repo1.maven.org/maven2</url>
>           <snapshots>
>               <enabled>true</enabled>
>           </snapshots>
>       </repository>
>
>       <repository>
>           <id>apache.org</id>
>           <name>Maven Snapshots</name>
>           <url>http://people.apache.org/repo/m2-snapshot-repository</ 
> url>
>           <releases>
>               <enabled>false</enabled>
>           </releases>
>           <snapshots>
>               <enabled>true</enabled>
>           </snapshots>
>       </repository>
>   </repositories>
>
>   <pluginRepositories>
>       <pluginRepository>
>           <id>central-m2-repository</id>
>           <name>Central Maven 2 Repository</name>
>           <url>http://repo1.maven.org/maven2</url>
>           <snapshots>
>               <enabled>true</enabled>
>           </snapshots>
>       </pluginRepository>
>
>       <pluginRepository>
>           <id>apache.org</id>
>           <name>Maven Plugin Snapshots</name>
>           <url>http://people.apache.org/repo/m2-snapshot-repository</ 
> url>
>           <releases>
>               <enabled>false</enabled>
>           </releases>
>           <snapshots>
>               <enabled>true</enabled>
>           </snapshots>
>       </pluginRepository>
>   </pluginRepositories>
> </project>
>
>

---
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog





Problem with CXF 2.0.6 and 2.1 setting objects on request to null when they are defined in response

Posted by Gary Weaver <ga...@duke.edu>.
Hello,

I'm having a problem in CXF 2.0.6, 2.1, and 2.1-SNAPSHOT 
(20080605.204511-10) where objects on the response object are null, but 
from looking at the output of the SOAP response coming back, logged by 
CXF, CXF should have set those objects on the response.

For example, in the code in TestClient.java below, when I call 
sendRequest(...) I get back a response object, and I can see in the logs 
the SOAP request and response, and they look good (the response has all 
of the fields it is supposed to). However, when I call any of the get 
methods on the response to get at the request data, they all return null. :(

An additional mystery (which may have something to do with it?) is that 
I've found that when I don't setAllowChunking(false) on a policy and set 
on the conduit, I get a server error back from the service I'm calling.

HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setAllowChunking(false);
conduit.setClient(httpClientPolicy);

Could you take a quick look at the code below and let me know if there 
is anything I'm doing that I shouldn't be doing or should be doing 
differently?

Also, please let me know if there is anything I should look at to 
determine why it isn't serializing the response back correctly. I have 
full debug logging on in log4j.properties.

Thanks in advance,
Gary


Here are the classes:

TestClient.java
===========

...
import org.apache.cxf.configuration.jsse.TLSClientParameters;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor;
import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor;
import org.apache.ws.security.WSConstants;
import org.apache.ws.security.handler.WSHandlerConstants;

import javax.xml.ws.BindingProvider;
import java.util.HashMap;
import java.util.Map;
...

public class TestClient {

    private static String URL = 
"https://some.host:1234/path/to/the/service";

    private TestClient() {
    }

    public static MyServiceResponseTypeShape sendRequest(String 
someRequestParam) throws Exception {
        MyService service = new MyService();
        MyServicePortType portType = service.getMyServicePort();

        Client client = ClientProxy.getClient(portType);
        Endpoint endpoint = client.getEndpoint();

        // Enable Logging
        // from http://cwiki.apache.org/CXF20DOC/debugging.html
        client.getInInterceptors().add(new LoggingInInterceptor());
        client.getOutInterceptors().add(new LoggingOutInterceptor());

        HTTPConduit conduit = (HTTPConduit) client.getConduit();

        // for more info see: 
http://cwiki.apache.org/confluence/display/CXF20DOC/Client+HTTP+Transport+%28including+SSL+support%29
        // set timeout
        HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
        //httpClientPolicy.setConnectionTimeout(36000);
        httpClientPolicy.setAllowChunking(false);
        //httpClientPolicy.setReceiveTimeout(32000);
        conduit.setClient(httpClientPolicy);

        // set endpoint, since the default one in the wsdl has wrong 
protocol and port
        TLSClientParameters params = conduit.getTlsClientParameters();
        if (params == null) {
            params = new TLSClientParameters();
            conduit.setTlsClientParameters(params);
        }

        // NOTE! ONLY DO THIS FOR TESTING, NOT PRODUCTION!
        // this is to get around the error:
        // The https URL hostname does not match the Common Name (CN) on 
the server certificate.  To disable this check (NOT recommended for 
production) set the CXF client TLS configuration property 
"disableCNCheck" to true.
        params.setDisableCNCheck(true);

        // override the endpoint that is defined in WSDL as http with 
old port to be https with new port       
        ((BindingProvider) 
portType).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, 
URL);

        // set username and password
        // see: http://cwiki.apache.org/CXF20DOC/ws-security.html
        // No security on client-side
        Map<String, Object> inProps = new HashMap<String, Object>();
        inProps.put(WSHandlerConstants.ACTION, 
WSHandlerConstants.NO_SECURITY);
        WSS4JInInterceptor wssIn = new WSS4JInInterceptor(inProps);
        endpoint.getInInterceptors().add(wssIn);
        endpoint.getInInterceptors().add(new SAAJInInterceptor()); // 
2.0.x only; not needed in 2.1+
        // Server-side authN
        Map<String, Object> outProps = new HashMap<String, Object>();
        outProps.put(WSHandlerConstants.ACTION, 
WSHandlerConstants.USERNAME_TOKEN);
        outProps.put(WSHandlerConstants.USER, "my_username");
        outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
        //outProps.put(WSHandlerConstants.PASSWORD_TYPE, 
WSConstants.PW_DIGEST);
        outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, 
MyCallbackHandler.class.getName());
        WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
        endpoint.getOutInterceptors().add(wssOut);
        endpoint.getOutInterceptors().add(new SAAJOutInterceptor()); // 
2.0.x only; not needed in 2.1+

        // note: createMyServiceRequestTypeShape() is a method on this 
class that creates the request object
        MyServiceRequestTypeShape req = 
createMyServiceRequestTypeShape(someRequestParam);

        return portType.doSomething(req);
    }

    public MyServiceRequestTypeShape 
createMyServiceRequestTypeShape(String someRequestParam) {
        ...
    }
}

MyCallbackHandler.java
==================

...

import org.apache.ws.security.WSPasswordCallback;

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.auth.callback.CallbackHandler;
import java.io.IOException;

public class MyCallbackHandler implements CallbackHandler {

    public void handle(Callback[] callbacks) throws IOException, 
UnsupportedCallbackException {

        WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];

        // set the password for our message.
        pc.setPassword("my_password");
    }

}

pom.xml
======

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>cxftestclient</groupId>
    <artifactId>cxftestclient</artifactId>
    <packaging>jar</packaging>

    <name>CXF Integration Test</name>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <cxf.version>2.1.1-SNAPSHOT</cxf.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1</version>
            <scope>provided</scope>
            <exclusions>
                <exclusion>
                    <groupId>logkit</groupId>
                    <artifactId>logkit</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>avalon-framework</groupId>
                    <artifactId>avalon-framework</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.servlet</groupId>
                    <artifactId>servlet-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>${cxf.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>${cxf.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-ws-security</artifactId>
            <version>${cxf.version}</version>
        </dependency>

        <!-- Jetty is needed if you're are not using the CXFServlet -->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http-jetty</artifactId>
            <version>${cxf.version}</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>${cxf.version}</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            
<sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
                            <wsdlOptions>
                                <wsdlOption>
                                    
<wsdl>${basedir}/src/main/wsdl/myService.wsdl</wsdl>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <reportFormat>brief</reportFormat>
                    <useFile>false</useFile>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>central-m2-repository</id>
            <name>Central Maven 2 Repository</name>
            <url>http://repo1.maven.org/maven2</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>

        <repository>
            <id>apache.org</id>
            <name>Maven Snapshots</name>
            <url>http://people.apache.org/repo/m2-snapshot-repository</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>central-m2-repository</id>
            <name>Central Maven 2 Repository</name>
            <url>http://repo1.maven.org/maven2</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>

        <pluginRepository>
            <id>apache.org</id>
            <name>Maven Plugin Snapshots</name>
            <url>http://people.apache.org/repo/m2-snapshot-repository</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
</project>



Re: how do I enable logging of the SOAP request and response in CXF in straight Java?

Posted by Gary Weaver <ga...@duke.edu>.
Glen,

Thanks! That worked!

MyService service = new MyService();
MyServicePortType portType = service.getMyServicePort();
Client client = ClientProxy.getClient(portType);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());

Thanks again,

Gary


Glen Mazza wrote:
> http://cwiki.apache.org/CXF20DOC/debugging.html -- the fourth shaded block
> from the top?
>
> HTH,
> Glen
>
>
> Gary Weaver wrote:
>   
>> Hello again,
>>
>> In Axis2 I was able to enable logging of the SOAP request and response 
>> along with the headers using the following in log4j.properties:
>>
>> log4j.logger.httpclient.wire.content=DEBUG #SOAP Request and Response
>> log4j.logger.httpclient.wire.header=DEBUG #HTTP Headers
>>
>> However, in CXF, when I turn on full debug logging in log4j.properties
>> via:
>>
>> log4j.rootCategory=DEBUG, ...
>>
>> I did a search through the log produced after calling the service and 
>> getting a response, but it appeared that the request and response were 
>> not logged.
>>
>> I then read at the following page how to configure the logging 
>> interceptors using Spring:
>> http://cwiki.apache.org/CXF20DOC/configuration.html
>>
>> However, the examples were all using Spring, which is fine, but for this 
>> simple test client, I was just using Java. Should I just switch to using 
>> the Spring config to configure CXF to enable logging, or is there an 
>> easy enough way to turn on logging either via log4j.properties (even 
>> though I don't think there is, since I had it on full-force) or via Java 
>> code?
>>
>> Thanks in advance,
>>
>> Gary
>>
>> -- 
>> Gary Weaver
>> Internet Framework Services
>> Office of Information Technology
>> Duke University
>>
>>
>>
>>     
>
>   


-- 
Gary Weaver
Internet Framework Services
Office of Information Technology
Duke University


Re: how do I enable logging of the SOAP request and response in CXF in straight Java?

Posted by Glen Mazza <gl...@gmail.com>.
http://cwiki.apache.org/CXF20DOC/debugging.html -- the fourth shaded block
from the top?

HTH,
Glen


Gary Weaver wrote:
> 
> Hello again,
> 
> In Axis2 I was able to enable logging of the SOAP request and response 
> along with the headers using the following in log4j.properties:
> 
> log4j.logger.httpclient.wire.content=DEBUG #SOAP Request and Response
> log4j.logger.httpclient.wire.header=DEBUG #HTTP Headers
> 
> However, in CXF, when I turn on full debug logging in log4j.properties
> via:
> 
> log4j.rootCategory=DEBUG, ...
> 
> I did a search through the log produced after calling the service and 
> getting a response, but it appeared that the request and response were 
> not logged.
> 
> I then read at the following page how to configure the logging 
> interceptors using Spring:
> http://cwiki.apache.org/CXF20DOC/configuration.html
> 
> However, the examples were all using Spring, which is fine, but for this 
> simple test client, I was just using Java. Should I just switch to using 
> the Spring config to configure CXF to enable logging, or is there an 
> easy enough way to turn on logging either via log4j.properties (even 
> though I don't think there is, since I had it on full-force) or via Java 
> code?
> 
> Thanks in advance,
> 
> Gary
> 
> -- 
> Gary Weaver
> Internet Framework Services
> Office of Information Technology
> Duke University
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/how-do-I-enable-logging-of-the-SOAP-request-and-response-in-CXF-in-straight-Java--tp17764749p17766823.html
Sent from the cxf-user mailing list archive at Nabble.com.


Antwort: how do I enable logging of the SOAP request and response in CXF in straight Java? [Virus checked]

Posted by ja...@external.t-mobile.at.
Hi.

1)
if using the example i sent before with 
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
then you can use 
factory.setFeatures(...)

2)
if you use service stub implementation which was generated from wsdl2java, 
then there is an operation to fetch port with parameter 
[WebServiceFeature... features]
it should be enought to put loggingfeature instance there .. but question 
is how to initialize it .. maybe like this:
new LoggingFeature().initialize(server, null);


best regards
jano




Gary Weaver <ga...@duke.edu> 
06/10/2008 23:08
Bitte antworten an
users@cxf.apache.org


An
users@cxf.apache.org
Kopie

Thema
how do I enable logging of the SOAP request and response in CXF in 
straight Java?  [Virus checked]






Hello again,

In Axis2 I was able to enable logging of the SOAP request and response 
along with the headers using the following in log4j.properties:

log4j.logger.httpclient.wire.content=DEBUG #SOAP Request and Response
log4j.logger.httpclient.wire.header=DEBUG #HTTP Headers

However, in CXF, when I turn on full debug logging in log4j.properties 
via:

log4j.rootCategory=DEBUG, ...

I did a search through the log produced after calling the service and 
getting a response, but it appeared that the request and response were 
not logged.

I then read at the following page how to configure the logging 
interceptors using Spring:
http://cwiki.apache.org/CXF20DOC/configuration.html

However, the examples were all using Spring, which is fine, but for this 
simple test client, I was just using Java. Should I just switch to using 
the Spring config to configure CXF to enable logging, or is there an 
easy enough way to turn on logging either via log4j.properties (even 
though I don't think there is, since I had it on full-force) or via Java 
code?

Thanks in advance,

Gary

-- 
Gary Weaver
Internet Framework Services
Office of Information Technology
Duke University