KickJava   Java API By Example, From Geeks To Geeks.

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


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 public class ClientHandler2 extends HandlerBase
35 {
36    public boolean handleRequest(MessageContext JavaDoc msgContext)
37    {
38       boolean retflag = super.handleRequest(msgContext);
39       
40       try
41       {
42          SOAPMessageContext JavaDoc soapContext = (SOAPMessageContext JavaDoc)msgContext;
43          SOAPMessage JavaDoc soapMessage = soapContext.getMessage();
44          SOAPBody JavaDoc soapBody = soapMessage.getSOAPBody();
45          SOAPElement JavaDoc soapElement = (SOAPElement JavaDoc)soapBody.getChildElements().next();
46          soapElement = (SOAPElement JavaDoc)soapElement.getChildElements().next();
47          String JavaDoc value = soapElement.getValue();
48          
49          /*
50           * Return false to indicate blocking of the request handler chain. In this case, further
51           * processing of the request handler chain is blocked and the target service endpoint is
52           * not dispatched. The JAX-RPC runtime system takes the responsibility of invoking the
53           * response handler chain next with the appropriate SOAPMessageContext. The Handler
54           * implementation class has the responsibility of setting the response SOAP message in
55           * the handleRequest method and perform additional processing in the
56           * handleResponse method. In the default processing model, the response handler
57           * chain starts processing from the same Handler instance (that returned false) and
58           * goes backward in the execution sequence.
59           */

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