1 package test.wsdl.jaxrpchandler2; 2 3 import java.io.*; 4 import java.io.InputStream ; 5 import java.util.*; 6 import java.util.Iterator ; 7 8 import javax.xml.namespace.QName ; 9 import javax.xml.rpc.handler.*; 10 import javax.xml.rpc.handler.soap.SOAPMessageContext ; 11 import javax.xml.soap.*; 12 import javax.xml.soap.SOAPMessage ; 13 import javax.xml.transform.stream.*; 14 15 public class EchoServiceServerHandler implements Handler { 16 17 public boolean handleRequest(MessageContext messageContext) { 18 19 try { 20 SOAPMessageContext soapMsgCtx = (SOAPMessageContext ) messageContext; 21 22 SOAPMessage soapMsg = soapMsgCtx.getMessage(); 23 SOAPPart soapPart = soapMsg.getSOAPPart(); 24 SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); 25 soapEnvelope.getBody().detachNode(); 26 SOAPBody soapBody = soapEnvelope.addBody(); 27 SOAPBodyElement echoElement = soapBody.addBodyElement(soapEnvelope.createName("echo", "ns1", "http://soapinterop.org/")); 28 SOAPElement argElement = echoElement.addChildElement("arg0"); 29 argElement = argElement.addAttribute(soapEnvelope.createName("type", "xsi", "http://www.w3.org/2001/XMLSchema-instance"), "xsd:string"); 30 argElement.addTextNode("my echo string"); 31 soapMsg.saveChanges(); 32 33 } catch (Exception e) { 34 e.printStackTrace(); 35 } 36 37 return true; 38 } 39 40 public boolean handleResponse(MessageContext messageContext) { 41 return true; 42 } 43 44 45 public boolean handleFault(MessageContext messageContext) { 46 return true; 47 } 48 49 public void init(HandlerInfo arg0) { 50 } 51 52 public void destroy() { 53 } 54 55 public QName [] getHeaders() { 56 return null; 57 } 58 59 } 60 | Popular Tags |