LogHandlerpublic class LogHandler extends BasicHandler 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. |
Fields Summary |
---|
protected static Log | log | long | start | private boolean | writeToConsole | private String | filename |
Methods Summary |
---|
private java.io.PrintWriter | getWriter()
PrintWriter writer;
// Allow config info to control where we write.
if (writeToConsole) {
// Writing to the console
writer = new PrintWriter(System.out);
} else {
// Writing to a file.
if (filename == null) {
filename = "axis.log";
}
writer = new PrintWriter(new FileWriter( filename, true ));
}
return writer;
| public void | init()
super.init();
Object opt = this.getOption("LogHandler.writeToConsole");
if (opt != null && opt instanceof String &&
"true".equalsIgnoreCase((String)opt))
writeToConsole = true;
opt = this.getOption("LogHandler.fileName");
if (opt != null && opt instanceof String)
filename = (String)opt;
| public void | invoke(org.apache.axis.MessageContext msgContext)
log.debug("Enter: LogHandler::invoke");
if (msgContext.getPastPivot() == false) {
start = System.currentTimeMillis();
} else {
logMessages(msgContext);
}
log.debug("Exit: LogHandler::invoke");
| private void | logMessages(org.apache.axis.MessageContext msgContext)
try {
PrintWriter writer = null;
writer = getWriter();
Message inMsg = msgContext.getRequestMessage();
Message outMsg = msgContext.getResponseMessage();
writer.println( "=======================================================" );
if (start != -1) {
writer.println( "= " + Messages.getMessage("elapsed00",
"" + (System.currentTimeMillis() - start)));
}
writer.println( "= " + Messages.getMessage("inMsg00",
(inMsg == null ? "null" : inMsg.getSOAPPartAsString())));
writer.println( "= " + Messages.getMessage("outMsg00",
(outMsg == null ? "null" : outMsg.getSOAPPartAsString())));
writer.println( "=======================================================" );
//START FIX: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16646
if (!writeToConsole) {
writer.close();
}
//END FIX: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16646
} catch( Exception e ) {
log.error( Messages.getMessage("exception00"), e );
throw AxisFault.makeFault(e);
}
| public void | onFault(org.apache.axis.MessageContext msgContext)
try {
logMessages(msgContext);
} catch (AxisFault axisFault) {
log.error(Messages.getMessage("exception00"), axisFault);
}
|
|