1 22 package org.jboss.test.webservice.jbws456; 23 24 import java.util.Iterator ; 25 26 import javax.xml.namespace.QName ; 27 import javax.xml.rpc.JAXRPCException ; 28 import javax.xml.rpc.handler.GenericHandler ; 29 import javax.xml.rpc.handler.MessageContext ; 30 import javax.xml.rpc.handler.soap.SOAPMessageContext ; 31 import javax.xml.soap.Name ; 32 import javax.xml.soap.SOAPBody ; 33 import javax.xml.soap.SOAPElement ; 34 import javax.xml.soap.SOAPException ; 35 import javax.xml.soap.SOAPFactory ; 36 import javax.xml.soap.SOAPMessage ; 37 38 public class TestHandler extends GenericHandler 39 { 40 private static String returnParam; 41 42 public static String getReturnParam() 43 { 44 return returnParam; 45 } 46 47 public QName [] getHeaders() 48 { 49 return new QName [] {}; 50 } 51 52 public boolean handleResponse(MessageContext msgContext) 53 { 54 try 55 { 56 SOAPFactory factory = SOAPFactory.newInstance(); 57 58 SOAPMessage soapMessage = ((SOAPMessageContext )msgContext).getMessage(); 59 SOAPBody soapBody = soapMessage.getSOAPBody(); 60 SOAPElement soapElement = (SOAPElement )soapBody.getChildElements().next(); 61 Name resName = factory.createName("result"); 62 soapElement = (SOAPElement )soapElement.getChildElements(resName).next(); 63 64 Iterator itParams = soapElement.getChildElements(); 65 soapElement = (SOAPElement )itParams.next(); 66 String value = soapElement.getValue(); 67 returnParam = value + " - Processed"; 68 69 if (itParams.hasNext()) 70 { 71 soapElement = (SOAPElement )itParams.next(); 72 throw new IllegalStateException ("Unexpected extra parameter: " + soapElement.getValue()); 73 } 74 75 return true; 76 } 77 catch (SOAPException e) 78 { 79 throw new JAXRPCException (e.toString(), e); 80 } 81 } 82 } 83 | Popular Tags |