1 22 package org.jboss.test.webservice.jbws464; 23 24 import javax.xml.namespace.QName ; 25 import javax.xml.rpc.handler.GenericHandler ; 26 import javax.xml.rpc.handler.HandlerInfo ; 27 import javax.xml.rpc.handler.MessageContext ; 28 import javax.xml.rpc.handler.soap.SOAPMessageContext ; 29 import javax.xml.soap.SOAPEnvelope ; 30 import javax.xml.soap.SOAPPart ; 31 import javax.xml.soap.SOAPException ; 32 33 import org.jboss.logging.Logger; 34 import org.w3c.dom.Document ; 35 36 public class SAAJTestHandler extends GenericHandler 37 { 38 private static Logger log = Logger.getLogger(SAAJTestHandler.class); 40 41 protected QName [] headers; 42 43 public QName [] getHeaders() 44 { 45 return headers; 46 } 47 48 public void init(HandlerInfo config) 49 { 50 headers = config.getHeaders(); 51 } 52 53 public void destroy() 54 { 55 } 56 57 public boolean handleRequest(MessageContext msgContext) 58 { 59 try 60 { 61 log.info("handleRequest"); 62 SOAPMessageContext context = (SOAPMessageContext ) msgContext; 63 SOAPPart part = context.getMessage().getSOAPPart(); 64 SOAPEnvelope env = (SOAPEnvelope ) part.getDocumentElement(); 65 Document doc = env.getOwnerDocument(); 66 if (doc == null) 67 throw new IllegalStateException ("Document from SOAPPart is null"); 68 if (part != doc) 69 throw new IllegalStateException ("Document != SOAPPart"); 70 if (env.getBody().getOwnerDocument() != doc) 71 throw new IllegalStateException ("SOAPBody does not have SOAPPart as its parent!"); 72 } 73 catch (SOAPException e) 74 { 75 throw new RuntimeException (e); 76 } 77 78 return true; 79 } 80 81 public boolean handleResponse(MessageContext msgContext) 82 { 83 log.info("handleResponse"); 84 SOAPMessageContext context = (SOAPMessageContext ) msgContext; 85 SOAPPart part = context.getMessage().getSOAPPart(); 86 SOAPEnvelope env = (SOAPEnvelope ) part.getDocumentElement(); 87 Document doc = env.getOwnerDocument(); 88 if (doc == null) 89 throw new IllegalStateException ("Document from SOAPPart is null"); 90 91 return true; 92 } 93 94 public boolean handleFault(MessageContext msgContext) 95 { 96 log.info("handleFault"); 97 log.info("IGNORE THE EXCEPTION:This is a test only"); 98 SOAPMessageContext context = (SOAPMessageContext ) msgContext; 99 SOAPPart part = context.getMessage().getSOAPPart(); 100 SOAPEnvelope env = (SOAPEnvelope ) part.getDocumentElement(); 101 Document doc = env.getOwnerDocument(); 102 if (doc == null) 103 throw new IllegalStateException ("Document from SOAPPart is null"); 104 105 return true; 106 } 107 } 108 | Popular Tags |