1 22 package org.jboss.test.webservice.jbws68; 23 24 import javax.xml.namespace.QName ; 25 import javax.xml.rpc.handler.GenericHandler ; 26 import javax.xml.rpc.handler.MessageContext ; 27 import javax.xml.rpc.handler.soap.SOAPMessageContext ; 28 import javax.xml.soap.Name ; 29 import javax.xml.soap.SOAPBody ; 30 import javax.xml.soap.SOAPElement ; 31 import javax.xml.soap.SOAPException ; 32 import javax.xml.soap.SOAPFactory ; 33 import javax.xml.soap.SOAPMessage ; 34 35 public class ClientHandler extends GenericHandler 36 { 37 private static final String TARGET_NAMESPACE = "http://org.jboss.test.webservice/jbws68"; 38 39 protected QName [] headers; 40 41 public QName [] getHeaders() 42 { 43 return headers; 44 } 45 46 public boolean handleRequest(MessageContext msgContext) 47 { 48 try 49 { 50 SOAPMessageContext soapContext = (SOAPMessageContext )msgContext; 51 SOAPMessage soapMessage = soapContext.getMessage(); 52 SOAPBody soapBody = soapMessage.getSOAPBody(); 53 SOAPElement rpcElement = (SOAPElement )soapBody.getChildElements().next(); 54 55 SOAPFactory factory = SOAPFactory.newInstance(); 56 Name rpcName = factory.createName("echoUserType", "ns1", TARGET_NAMESPACE); 57 if (rpcName.equals(rpcElement.getElementName()) == false) 58 throw new IllegalStateException ("Invalid rpc name: " + rpcElement.getElementName()); 59 60 SOAPElement paramElement = (SOAPElement )rpcElement.getChildElements().next(); 61 Name paramName = factory.createName("UserType_1"); 62 if (paramName.equals(paramElement.getElementName()) == false) 63 throw new IllegalStateException ("Invalid param name: " + paramElement.getElementName()); 64 65 75 76 return true; 77 } 78 catch (SOAPException e) 79 { 80 throw new IllegalArgumentException (e.toString()); 81 } 82 } 83 84 public boolean handleResponse(MessageContext msgContext) 85 { 86 try 87 { 88 SOAPMessageContext soapContext = (SOAPMessageContext )msgContext; 89 SOAPMessage soapMessage = soapContext.getMessage(); 90 SOAPBody soapBody = soapMessage.getSOAPBody(); 91 SOAPElement rpcElement = (SOAPElement )soapBody.getChildElements().next(); 92 93 SOAPFactory factory = SOAPFactory.newInstance(); 94 Name rpcName = factory.createName("echoUserTypeResponse", "ns1", TARGET_NAMESPACE); 95 if (rpcName.equals(rpcElement.getElementName()) == false) 96 throw new IllegalStateException ("Invalid rpc name: " + rpcElement.getElementName()); 97 98 SOAPElement paramElement = (SOAPElement )rpcElement.getChildElements().next(); 99 Name paramName = factory.createName("result"); 100 if (paramName.equals(paramElement.getElementName()) == false) 101 throw new IllegalStateException ("Invalid param name: " + paramElement.getElementName()); 102 103 113 114 return true; 115 } 116 catch (SOAPException e) 117 { 118 throw new IllegalArgumentException (e.toString()); 119 } 120 } 121 } 122 | Popular Tags |