How can I display to screen the contents of a Soap Message

I am writing a JAX-RPC client and just want to look at the actual XML soap message I get back. I have access to the class SoapDeserializationContext and to the XMLReader. Can anyone help?Thanks,Richard
[229 byte] By [Richard_Cromera] at [2007-11-27 8:20:33]
# 1
just intercept the http response and write it out somewhere.
jwentinga at 2007-7-12 20:08:53 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Thanks for the reply.

Unfortunately, I do not have obvious access to the response from the JAX client. The details are buried in hidden code that when I am debugging I can not get to.

For those of you who might have peeked at the code that is auto generated with wscompile, perhaps you have some insight into where I should go to find the actual messages, so I can display them.

Thanks Again.

richardcromera at 2007-7-12 20:08:53 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

hi richard,

you have to study about A SOAP message handler. It's concept very easy, it open to you to do something before soap request will send and after soap response was received. Normally i do these step.

- create a class that extends from javax.xml.rpc.handler.GenericHandler.

- implements these method

* handlerRequest(MessageContext context)

* handleResponse(MessageContext context)

- register this handle in web.xml(if your app is web, if not i think it have an api for register the handle manually)

From MessageContext object you can write soap message to console or any OutputStream.

below is an example from my work.

=============================

import java.io.ByteArrayOutputStream;

import javax.xml.namespace.QName;

import javax.xml.rpc.handler.GenericHandler;

import javax.xml.rpc.handler.HandlerInfo;

import javax.xml.rpc.handler.MessageContext;

import javax.xml.rpc.handler.soap.SOAPMessageContext;

import javax.xml.soap.SOAPMessage;

import org.apache.log4j.Logger;

/**

*

* @author Administrator

*/

public class MessageHandler extends GenericHandler{

private static Logger logger = Logger.getLogger("MessageHandler.class");

private QName[] headers;

/** Creates a new instance of MessageHandler */

public MessageHandler() {

}

public boolean handleResponse(MessageContext context) {

if (logger.isDebugEnabled()) {

logger.debug("RESPONSE MESSAGE = '" + convertSoapToString(context) + "'");

}

return true;

}

public boolean handleRequest(MessageContext context) {

if (logger.isDebugEnabled()) {

logger.debug("REQUEST MESSAGE = '" + convertSoapToString(context) + "'");

}

return true;

}

public boolean handleFault(MessageContext context) {

if (logger.isDebugEnabled()) {

logger.debug("FAULT MESSAGE = '" + convertSoapToString(context) + "'");

}

return true;

}

private String convertSoapToString(MessageContext context) {

try{

SOAPMessageContext smc = (SOAPMessageContext) context;

SOAPMessage soapMsg = smc.getMessage();

ByteArrayOutputStream byteOS = new ByteArrayOutputStream();

//soapMsg.writeTo(System.out);// print soap message to console

soapMsg.writeTo(byteOS);// convert soap message to stringreturn new String(byteOS.toByteArray());

} catch(Exception e) {

logger.error(e.getMessage());

}

return new String("Cannot get message, please see the log file.");

}

public void init(HandlerInfo config) {

headers = config.getHeaders();

}

public javax.xml.namespace.QName[] getHeaders() {

return headers;

}

}

============================================

Below is what i do in web.xml

<service-ref>

<service-ref-name>service/WSEnquiry</service-ref-name>

<service-interface>cbsws.test.ws.WSEnquiry</service-interface>

<wsdl-file>WEB-INF/wsdl/WSEnquiry.wsdl</wsdl-file>

<jaxrpc-mapping-file>WEB-INF/WSEnquiry-mapping.xml</jaxrpc-mapping-file>

<port-component-ref>

<service-endpoint-interface>cbsws.test.ws.WSEnquirySEI</service-endpoint-interface>

</port-component-ref>

<handler>

<handler-name>cbsws.test.services.impl.MessageHandler</handler-name>

<handler-class>cbsws.test.services.impl.MessageHandler</handler-class>

</handler></service-ref>===================================

Hope this help.

anurak

anuraktha at 2007-7-12 20:08:53 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
Try using wsmonitor (https://wsmonitor.dev.java.net/) it allows you to intercept and view HTTP based SOAP messages.
dkohlerta at 2007-7-12 20:08:53 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...