1 5 package demo.handlers.common; 6 7 8 import java.io.PrintStream ; 9 import java.util.Map ; 10 import java.util.Set ; 11 12 import javax.xml.namespace.QName ; 13 import javax.xml.soap.SOAPMessage ; 14 import javax.xml.ws.handler.MessageContext; 15 import javax.xml.ws.handler.soap.SOAPHandler; 16 import javax.xml.ws.handler.soap.SOAPMessageContext; 17 18 22 public class LoggingHandler implements SOAPHandler<SOAPMessageContext> { 23 24 private PrintStream out; 25 26 public LoggingHandler() { 27 setLogStream(System.out); 28 } 29 30 protected final void setLogStream(PrintStream ps) { 31 out = ps; 32 } 33 34 public void init(Map c) { 35 System.out.println("LoggingHandler : init() Called...."); 36 } 37 38 public Set <QName > getHeaders() { 39 return null; 40 } 41 42 public boolean handleMessage(SOAPMessageContext smc) { 43 System.out.println("LoggingHandler : handleMessage Called...."); 44 logToSystemOut(smc); 45 return true; 46 } 47 48 public boolean handleFault(SOAPMessageContext smc) { 49 System.out.println("LoggingHandler : handleFault Called...."); 50 logToSystemOut(smc); 51 return true; 52 } 53 54 public void close(MessageContext messageContext) { 56 System.out.println("LoggingHandler : close() Called...."); 57 } 58 59 public void destroy() { 61 System.out.println("LoggingHandler : destroy() Called...."); 62 } 63 64 71 protected void logToSystemOut(SOAPMessageContext smc) { 72 Boolean outboundProperty = (Boolean ) 73 smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); 74 75 if (outboundProperty.booleanValue()) { 76 out.println("\nOutbound message:"); 77 } else { 78 out.println("\nInbound message:"); 79 } 80 81 SOAPMessage message = smc.getMessage(); 82 try { 83 message.writeTo(out); 84 out.println(); 85 } catch (Exception e) { 86 out.println("Exception in handler: " + e); 87 } 88 } 89 } 90 | Popular Tags |