KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > wsdl > jaxrpchandler2 > EchoServiceServerHandler


1 package test.wsdl.jaxrpchandler2;
2
3 import java.io.*;
4 import java.io.InputStream JavaDoc;
5 import java.util.*;
6 import java.util.Iterator JavaDoc;
7
8 import javax.xml.namespace.QName JavaDoc;
9 import javax.xml.rpc.handler.*;
10 import javax.xml.rpc.handler.soap.SOAPMessageContext JavaDoc;
11 import javax.xml.soap.*;
12 import javax.xml.soap.SOAPMessage JavaDoc;
13 import javax.xml.transform.stream.*;
14
15 public class EchoServiceServerHandler implements Handler {
16
17     public boolean handleRequest(MessageContext JavaDoc messageContext) {
18
19     try {
20         SOAPMessageContext JavaDoc soapMsgCtx = (SOAPMessageContext JavaDoc) messageContext;
21         
22         SOAPMessage JavaDoc 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 JavaDoc e) {
34         e.printStackTrace();
35     }
36     
37     return true;
38     }
39     
40     public boolean handleResponse(MessageContext JavaDoc messageContext) {
41     return true;
42     }
43
44     
45     public boolean handleFault(MessageContext JavaDoc messageContext) {
46     return true;
47     }
48
49     public void init(HandlerInfo arg0) {
50     }
51
52     public void destroy() {
53     }
54
55     public QName JavaDoc[] getHeaders() {
56     return null;
57     }
58     
59 }
60
Popular Tags