[jbossws-users] [JBossWS] - Re: How Do I See the XML?

flindet do-not-reply at jboss.com
Fri Apr 6 12:24:48 EDT 2007


rmartony, here's what I ended up doing to log my full SOAP message.  It's based heavily on the example handlers included with JBossWS.


  | public class ProtocolHandler extends GenericSOAPHandler
  | {
  | 	/**
  | 	 * The {@link Logger} used for writing logging messages.
  | 	 */
  | 	private static Logger log = Logger.getLogger(ProtocolHandler.class);
  | 
  | 	/* (non-Javadoc)
  | 	 * @see org.jboss.ws.core.jaxws.handler.GenericSOAPHandler#handleOutbound(javax.xml.ws.handler.MessageContext)
  | 	 */
  | 	@Override
  | 	public boolean handleOutbound(final MessageContext msgContext)
  | 	{
  | 		if (log.isInfoEnabled())
  | 		{
  | 			return logMessage(msgContext);
  | 		}
  | 		return true;
  | 	}
  | 
  | 	/* (non-Javadoc)
  | 	 * @see org.jboss.ws.core.jaxws.handler.GenericSOAPHandler#handleInbound(javax.xml.ws.handler.MessageContext)
  | 	 */
  | 	@Override
  | 	public boolean handleInbound(final MessageContext msgContext)
  | 	{
  | 		if (log.isInfoEnabled())
  | 		{
  | 			return logMessage(msgContext);
  | 		}
  | 		return true;
  | 	}
  | 
  | 	/**
  | 	 * Logs the full SOAP message.
  | 	 * 
  | 	 * @param messageContext The message context containing the SOAP message to be handled.
  | 	 * @return True if handler processing should continue, false otherwise.
  | 	 * @throws WebServiceException If the SOAP message is malformed.
  | 	 */
  | 	private boolean logMessage(final MessageContext messageContext)
  | 	{
  | 		try
  | 		{
  | 			SOAPMessage soapMessage = ((SOAPMessageContext) messageContext).getMessage();
  | 			if (soapMessage.getSOAPBody().getChildElements().hasNext())
  | 			{
  | 				SOAPElement soapElement = (SOAPElement) soapMessage.getSOAPBody().getChildElements().next();
  | 				if (soapElement.getChildElements().hasNext())
  | 				{
  | 					soapElement = (SOAPElement) soapElement.getChildElements().next();
  | 
  | 					ByteArrayOutputStream xmlStream = new ByteArrayOutputStream();
  | 					soapMessage.writeTo(xmlStream);
  | 					log.info(new String(xmlStream.toByteArray()));
  | 				}
  | 			}
  | 
  | 			return true;
  | 		}
  | 		catch (SOAPException ex)
  | 		{
  | 			throw new WebServiceException(ex);
  | 		}
  | 		catch (IOException ex)
  | 		{
  | 			throw new WebServiceException(ex);
  | 		}
  | 	}
  | }
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4035389#4035389

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4035389



More information about the jbossws-users mailing list