1 22 package org.jboss.test.webservice.jbws381; 23 24 import javax.xml.namespace.QName ; 25 import javax.xml.rpc.JAXRPCException ; 26 import javax.xml.rpc.handler.GenericHandler ; 27 import javax.xml.rpc.handler.MessageContext ; 28 import javax.xml.rpc.handler.soap.SOAPMessageContext ; 29 import javax.xml.soap.Name ; 30 import javax.xml.soap.SOAPBody ; 31 import javax.xml.soap.SOAPElement ; 32 import javax.xml.soap.SOAPException ; 33 import javax.xml.soap.SOAPFactory ; 34 import javax.xml.soap.SOAPMessage ; 35 36 public class ServerHandler extends GenericHandler 37 { 38 public QName [] getHeaders() 39 { 40 return new QName [] {}; 41 } 42 43 public boolean handleRequest(MessageContext msgContext) 44 { 45 try 46 { 47 SOAPFactory factory = SOAPFactory.newInstance(); 48 49 SOAPMessage soapMessage = ((SOAPMessageContext )msgContext).getMessage(); 50 SOAPBody soapBody = soapMessage.getSOAPBody(); 51 SOAPElement soapElement = (SOAPElement )soapBody.getChildElements().next(); 52 53 Name elName = soapElement.getElementName(); 54 if (elName.equals(factory.createName("GetWeatherByZipCode", null, "http://www.webservicex.net"))) 55 { 56 soapElement = (SOAPElement )soapElement.getChildElements().next(); 57 elName = soapElement.getElementName(); 58 if (elName.equals(factory.createName("ZipCode", null, "http://www.webservicex.net")) == false) 59 { 60 throw new IllegalStateException ("Unexpected element: " + elName); 61 } 62 } 63 else if (elName.equals(factory.createName("GetWeatherByPlaceName", null, "http://www.webservicex.net"))) 64 { 65 soapElement = (SOAPElement )soapElement.getChildElements().next(); 66 elName = soapElement.getElementName(); 67 if (elName.equals(factory.createName("PlaceName", null, "http://www.webservicex.net")) == false) 68 { 69 throw new IllegalStateException ("Unexpected element: " + elName); 70 } 71 } 72 else 73 { 74 throw new IllegalStateException ("Unexpected request element: " + elName); 75 } 76 77 return true; 78 } 79 catch (SOAPException e) 80 { 81 throw new JAXRPCException (e.toString(), e); 82 } 83 } 84 } 85 | Popular Tags |