1 package org.netbeans.test.examples.logging; 2 3 4 9 import javax.xml.rpc.handler.MessageContext ; 11 import javax.xml.rpc.handler.HandlerInfo ; 12 import javax.xml.rpc.handler.soap.SOAPMessageContext ; 13 import javax.xml.namespace.QName ; 14 import javax.xml.soap.SOAPElement ; 15 import javax.xml.soap.SOAPMessage ; 16 import javax.xml.soap.SOAPPart ; 17 import javax.xml.soap.SOAPEnvelope ; 18 import javax.xml.soap.SOAPHeader ; 19 import javax.xml.soap.SOAPBody ; 20 import java.util.Date ; 21 public class DummyHandler extends javax.xml.rpc.handler.GenericHandler { 23 25 private QName [] headers; 26 27 public void init(HandlerInfo config) { 28 headers = config.getHeaders(); 29 } 30 31 public javax.xml.namespace.QName [] getHeaders() { 32 return headers; 33 } 34 35 public boolean handleRequest(MessageContext context) { 37 try{ 38 SOAPMessageContext smc = (SOAPMessageContext ) context; 39 SOAPMessage msg = smc.getMessage(); 40 SOAPPart sp = msg.getSOAPPart(); 41 SOAPEnvelope se = sp.getEnvelope(); 42 SOAPHeader shd = se.getHeader(); 43 44 SOAPBody sb = se.getBody(); 45 java.util.Iterator childElems = sb.getChildElements(); 46 SOAPElement child; 47 StringBuffer message = new StringBuffer (); 48 while (childElems.hasNext()) { 49 child = (SOAPElement ) childElems.next(); 50 message.append(new Date ().toString() + "--"); 51 formLogMessage(child, message); 52 } 53 54 System.out.println("Log message: " + message.toString()); 55 } catch(Exception e){ 56 e.printStackTrace(); 57 } 58 return true; 59 } 60 61 public boolean handleResponse(MessageContext context) { 62 return true; 63 } 64 65 public boolean handleFault(MessageContext context) { 66 return true; 67 } 68 69 public void destroy() { 70 } 71 72 private void formLogMessage(SOAPElement child, StringBuffer message) { 73 message.append(child.getElementName().getLocalName()); 74 message.append(child.getValue() != null ? ":" + child.getValue() + " " : " "); 75 76 try{ 77 java.util.Iterator childElems = child.getChildElements(); 78 while (childElems.hasNext()) { 79 Object c = childElems.next(); 80 if(c instanceof SOAPElement ) 81 formLogMessage((SOAPElement )c, message); 82 } 83 }catch(Exception e){ 84 e.printStackTrace(); 85 } 86 } 87 } 88 | Popular Tags |