Skip to content

Instantly share code, notes, and snippets.

@rajeevshukla
Created October 14, 2018 23:05
Show Gist options
  • Save rajeevshukla/675998454f2381217e3c97513b4667ce to your computer and use it in GitHub Desktop.
Save rajeevshukla/675998454f2381217e3c97513b4667ce to your computer and use it in GitHub Desktop.
Registering Axis handler
import org.apache.axis.AxisFault;
import org.apache.axis.AxisFault;
import org.apache.axis.Message;
import org.apache.axis.MessageContext;
import org.apache.axis.handlers.BasicHandler;
import org.apache.axis.utils.Messages;
public class AxisLogHandler extends BasicHandler {
private static final long serialVersionUID = 1L;
@Override public void invoke(MessageContext msgContext) throws AxisFault {
try {
logMessage(msgContext);
} catch (Exception e) {
e.printStackTrace();
}
}
private void logMessage(MessageContext msgContext) throws Exception{
Message inMsg = msgContext.getRequestMessage();
Message outMsg = msgContext.getResponseMessage();
if(outMsg == null) {
//replace it with logger if you need it log in different file.
System.out.println("============================= REQUEST ============================================");
System.out.println(Messages.getMessage("inMsg00", (inMsg == null ? "" : inMsg.getSOAPEnvelope().getAsString())));
}
else {
System.out.println("===================================RESPONSE======================================");
System.out.println(Messages.getMessage("outMsg00", (outMsg == null ? "" : outMsg.getSOAPEnvelope().getAsString())));
}
}
@Override public void onFault(MessageContext msgContext) { super.onFault(msgContext);
try {
logMessage(msgContext);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment