KickJava   Java API By Example, From Geeks To Geeks.

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


1 package test.wsdl.jaxrpchandler2;
2
3 import org.w3c.dom.Node JavaDoc;
4
5 import javax.xml.namespace.QName JavaDoc;
6 import javax.xml.rpc.handler.Handler JavaDoc;
7 import javax.xml.rpc.handler.HandlerInfo JavaDoc;
8 import javax.xml.rpc.handler.MessageContext JavaDoc;
9 import javax.xml.rpc.handler.soap.SOAPMessageContext JavaDoc;
10 import javax.xml.soap.SOAPMessage JavaDoc;
11
12 public class EchoServiceServerHandler3 implements Handler JavaDoc {
13     private HandlerInfo JavaDoc info;
14
15     public void init(HandlerInfo JavaDoc handlerInfo) {
16         info = handlerInfo;
17     }
18
19     public void destroy() {
20     }
21
22     public QName JavaDoc[] getHeaders() {
23         return info.getHeaders();
24     }
25
26     public boolean handleRequest(MessageContext JavaDoc mc) {
27         try {
28             SOAPMessage JavaDoc msg = ((SOAPMessageContext JavaDoc) mc).getMessage();
29             Node JavaDoc child = msg.getSOAPPart().getEnvelope().getBody()
30                     .getFirstChild()
31                     .getFirstChild()
32                     .getFirstChild();
33             String JavaDoc name = child.getNodeValue();
34             if (name != null && name.equals("Joe")) {
35                 child.setNodeValue("Sam");
36             }
37             return true;
38         } catch (Exception JavaDoc ex) {
39             ex.printStackTrace();
40             return false;
41         }
42     }
43
44     public boolean handleResponse(MessageContext JavaDoc mc) {
45         return true;
46     }
47
48     public boolean handleFault(MessageContext JavaDoc mc) {
49         return true;
50     }
51 }
52     
Popular Tags