KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > webservice > handlerflow > ServerHandler2


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.test.webservice.handlerflow;
23
24 import java.io.ByteArrayInputStream JavaDoc;
25
26 import javax.xml.rpc.handler.MessageContext JavaDoc;
27 import javax.xml.rpc.handler.soap.SOAPMessageContext JavaDoc;
28 import javax.xml.soap.MessageFactory JavaDoc;
29 import javax.xml.soap.SOAPBody JavaDoc;
30 import javax.xml.soap.SOAPElement JavaDoc;
31 import javax.xml.soap.SOAPMessage JavaDoc;
32
33
34
35 public class ServerHandler2 extends HandlerBase
36 {
37    public boolean handleRequest(MessageContext JavaDoc msgContext)
38    {
39       boolean retflag = super.handleRequest(msgContext);
40       
41       try
42       {
43          SOAPMessageContext JavaDoc soapContext = (SOAPMessageContext JavaDoc)msgContext;
44          SOAPMessage JavaDoc soapMessage = soapContext.getMessage();
45          SOAPBody JavaDoc soapBody = soapMessage.getSOAPBody();
46          SOAPElement JavaDoc soapElement = (SOAPElement JavaDoc)soapBody.getChildElements().next();
47          soapElement = (SOAPElement JavaDoc)soapElement.getChildElements().next();
48          String JavaDoc value = soapElement.getValue();
49
50          /*
51           * Return false to indicate blocking of the request handler chain. In this case, further
52           * processing of the request handler chain is blocked and the target service endpoint is
53           * not dispatched. The JAX-RPC runtime system takes the responsibility of invoking the
54           * response handler chain next with the appropriate SOAPMessageContext. The Handler
55           * implementation class has the responsibility of setting the response SOAP message in
56           * the handleRequest method and perform additional processing in the
57           * handleResponse method. In the default processing model, the response handler
58           * chain starts processing from the same Handler instance (that returned false) and
59           * goes backward in the execution sequence.
60           */

61          if ("ServerReturn".equals(value))
62          {
63             String JavaDoc resMsg =
64                "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" +
65                " <env:Header/>" +
66                " <env:Body>" +
67                " <ns1:sayHelloResponse xmlns:ns1='http://test.jboss.org/webservice/handlerflow'>" +
68                " <result>Return in ServerHandler2</result>" +
69                " </ns1:sayHelloResponse>" +
70                " </env:Body>" +
71                "</env:Envelope>";
72             
73             MessageFactory JavaDoc factory = MessageFactory.newInstance();
74             soapMessage = factory.createMessage(null, new ByteArrayInputStream JavaDoc(resMsg.getBytes()));
75             soapContext.setMessage(soapMessage);
76             
77             return false;
78          }
79       }
80       catch (Exception JavaDoc ex)
81       {
82          throw new IllegalStateException JavaDoc("Cannot handle request::" + ex.getMessage());
83       }
84       return retflag;
85    }
86 }
87
Popular Tags