/*
* Copyright 2011 Federal Chancellery Austria and
* Graz University of Technology
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package at.gv.util;
import java.io.ByteArrayOutputStream;
import java.io.OutputStreamWriter;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Handler to log JAX-WS messages to slf4j logging framework. Does currently not
* distinguish between incomig and outgoing messages.
*
* @author Arne Tauber
*
*/
public class LoggingHandler implements SOAPHandler {
Logger log = LoggerFactory.getLogger(LoggingHandler.class);
public boolean handleMessage(SOAPMessageContext context) {
SOAPMessage msg = context.getMessage();
boolean request = ((Boolean) context
.get(SOAPMessageContext.MESSAGE_OUTBOUND_PROPERTY)).booleanValue();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
if (request) {
msg.writeTo(bos);
} else { // This is the response message
msg.writeTo(bos);
}
OutputStreamWriter writer = new OutputStreamWriter(bos);
String encoding = writer.getEncoding();
log.trace(bos.toString());
log.trace(new String(bos.toByteArray()));
} catch (Exception e) {
log.trace(e.getMessage(), e);
}
return true;
}
public boolean handleFault(SOAPMessageContext context) {
return handleMessage(context);
}
public void close(MessageContext context) {
}
public Set getHeaders() {
return null;
}
}