Skip to content

Instantly share code, notes, and snippets.

@klcodanr
Created August 15, 2014 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klcodanr/d5305a7a985876854eee to your computer and use it in GitHub Desktop.
Save klcodanr/d5305a7a985876854eee to your computer and use it in GitHub Desktop.
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* 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 com.client.ws.impl;
import java.util.Iterator;
import org.apache.axis.AxisFault;
import org.apache.axis.Message;
import org.apache.axis.MessageContext;
import org.apache.axis.handlers.BasicHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A simple Handler which logs the request and response messages to either the
* console or a specified file (default "axis.log").
*
* To use this, deploy it either in both the request and response flows (global,
* service, or transport) or in just the response flow. If deployed in both
* places, you'll also get an elapsed time indication, which can be handy for
* debugging.
*
* @author Doug Davis (dug@us.ibm.com)
* @author Glen Daniels (gdaniels@apache.org)
*/
public class SLF4JLogHandler extends BasicHandler {
/**
*
*/
private static final long serialVersionUID = 8908942870057216780L;
protected static Logger log = LoggerFactory
.getLogger(SLF4JLogHandler.class);
public void init() {
super.init();
}
public void invoke(MessageContext msgContext) throws AxisFault {
logMessages(msgContext);
}
private void logMessages(MessageContext msgContext) throws AxisFault {
try {
if (log.isDebugEnabled()) {
Message inMsg = msgContext.getRequestMessage();
Message outMsg = msgContext.getResponseMessage();
@SuppressWarnings("unchecked")
Iterator<String> names = msgContext.getAllPropertyNames();
while (names.hasNext()) {
String name = names.next();
log.debug("Axis Property name={}, value={}", new Object[] {
name, msgContext.getProperty(name) });
}
log.debug("SOAP Request: "
+ (inMsg == null ? "null" : inMsg.getSOAPPartAsString()));
log.debug("SOAP Response: "
+ (outMsg == null ? "null" : outMsg
.getSOAPPartAsString()));
}
} catch (Exception e) {
log.error("Exception logging SOAP messages", e);
}
}
public void onFault(MessageContext msgContext) {
try {
logMessages(msgContext);
} catch (AxisFault axisFault) {
log.error("Exception logging SOAP messages", axisFault);
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment