axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Avadhanula, Suresh " <>
Subject RE: Logging all requests
Date Fri, 08 Apr 2005 17:04:27 GMT
Here is the methods I wrote to marshal SOAPMessages. This would provide output similar to what
you see in TCPMon.
I have modified it to take any object and add it as <element ...>..</element>
in the SOAP.
Email me if you need any specific details about it

	* @param object passed to create SOAPMessage
	public static String marshal(Object msg)
		if (msg == null)
			return null;

		RPCElement rpcElement = new RPCElement("soapmessage");

		// Structure of a SOAP Envelope is
		// SOAPEnvelope
		//   		--> RPCElement 
		// 						---> RPCParam * n
		// Create RPCParam of each ISMessage param.
		// Serialize. Encapuslate it with RPCElement
		// that contains the dummy method name. Set 
		// RPCElement as body in SOAPEnvelope
			String paramName = "param"
			Class cl = param.getClass();
			Object value = param;
			QName xmlTypeQName = getTypeQName(cl);  // AxisEngine provides implementation of this.
I have not shown it here. If you need it email me.
			ParameterDesc paramDesc = new ParameterDesc();

			paramDesc.setQName(new QName("", paramName));

			RPCParam rpcParam = new RPCParam(paramName, value);

		SOAPEnvelope message = new SOAPEnvelope();

		StringBuffer sb = new StringBuffer();
		String retStr = null;
			// This is Axis Specific code to serialize SOAPEnvelope
			// MessageContext is used through out AxisEngine which
			// is used as scratchpad by different modules of Axis.
			// Hence it is important tha twe set the SOAPEnvelope in 
			// message context

			MessageContext mc = new MessageContext(aa.getAxisEngine());
			Message soapMsg = new Message(message);

			// We need to add content type header as it is used during
			// deserialization to unmarshal any attachements present.
			// Content header will specify the multipart mime header contents
			// along with boundry tags.
			sb.append(HTTPConstants.HEADER_CONTENT_TYPE).append(": ");
			long contentLength = soapMsg.getContentLength();
			if (log.isDebugEnabled())
				log.debug(" ContentLength " + contentLength);
			// This Call does all the magic of analyzing soap message and 
			// any attachements to form the header
			String contentType = soapMsg.getContentType(mc.getSOAPConstants()); 
			sb.append("\r\n"); // Required CR for Content Header

			ByteArrayOutputStream bos = new ByteArrayOutputStream();
			soapMsg.writeTo(bos); // Serialize the actual soap message along with attachments

			retStr = sb.toString(); // Combine content header with body and we are done

			if (log.isDebugEnabled())
				log.debug(" Marshalled Msg is \n" + retStr);

		catch (Exception e)
			log.error(" Exception occured while dumping ISMessage ", e);
		return retStr;


-----Original Message-----
From: Ralph Pöllath [] 
Sent: Friday, April 08, 2005 11:40 AM
Subject: Logging all requests


I'm using code generated by wsdl2java in my spring based app and would like to log the SOAP
envelopes of all outgoing requests and their responses - basically what tcpmon does, but without
running a separate process.

Any ideas?


View raw message