Java tutorial
/* * HSM Proxy Project. * Copyright (C) 2013 FedICT. * Copyright (C) 2011-2012 AGIV. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version * 3.0 as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, see * http://www.gnu.org/licenses/. */ package be.fedict.hsm.ws.impl; import java.io.ByteArrayOutputStream; import java.util.Set; import javax.xml.namespace.QName; import javax.xml.soap.SOAPMessage; import javax.xml.ws.handler.MessageContext; import javax.xml.ws.handler.soap.SOAPHandler; import javax.xml.ws.handler.soap.SOAPMessageContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class LoggingSOAPHandler implements SOAPHandler<SOAPMessageContext> { private static final Log LOG = LogFactory.getLog(LoggingSOAPHandler.class); @Override public boolean handleMessage(SOAPMessageContext context) { Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); LOG.debug("outbound message: " + outboundProperty); SOAPMessage soapMessage = context.getMessage(); ByteArrayOutputStream output = new ByteArrayOutputStream(); try { soapMessage.writeTo(output); } catch (Exception e) { LOG.error("SOAP error: " + e.getMessage()); } LOG.debug("SOAP message: " + output.toString()); return true; } @Override public boolean handleFault(SOAPMessageContext context) { Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); LOG.debug("outbound message: " + outboundProperty); SOAPMessage soapMessage = context.getMessage(); ByteArrayOutputStream output = new ByteArrayOutputStream(); try { soapMessage.writeTo(output); } catch (Exception e) { LOG.error("SOAP error: " + e.getMessage()); } LOG.debug("SOAP fault: " + output.toString()); return true; } @Override public void close(MessageContext context) { } @Override public Set<QName> getHeaders() { return null; } }