KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > webservice > handler > ServerHandlerChain


1 /**
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.webservice.handler;
8
9 // $Id: ServerHandlerChain.java,v 1.6.2.4 2005/04/22 11:28:31 tdiesler Exp $
10

11 import org.jboss.axis.providers.java.RPCInvocation;
12 import org.jboss.axis.providers.java.RPCProvider;
13 import org.jboss.logging.Logger;
14
15 import javax.xml.rpc.handler.MessageContext JavaDoc;
16 import java.util.List JavaDoc;
17 import java.util.Set JavaDoc;
18
19 /**
20  * Represents a list of handlers. All elements in the
21  * HandlerChain are of the type javax.xml.rpc.handler.Handler.
22  * <p/>
23  * Abstracts the policy and mechanism for the invocation of the registered handlers.
24  *
25  * @author Thomas.Diesler@jboss.org
26  * @since 06-May-2004
27  */

28 public class ServerHandlerChain extends HandlerChainBaseImpl
29 {
30    private static Logger log = Logger.getLogger(ServerHandlerChain.class);
31
32    public ServerHandlerChain(List JavaDoc infos, Set JavaDoc roles)
33    {
34       super(infos, roles);
35    }
36
37    /**
38     * Gets the RPCInvocation before the the server handler chain is invoked, gets it again
39     * after handler processing and replaces it in the message contaxt in case the handlers
40     * modified the request SOAPEnvelope.
41     */

42    public boolean handleRequest(MessageContext JavaDoc msgContext)
43    {
44       RPCInvocation invBefore = (RPCInvocation)msgContext.getProperty(RPCProvider.RPC_INVOCATION);
45       if (invBefore == null)
46          throw new IllegalStateException JavaDoc("Cannot obtain RPCInvocation from message context");
47
48       String JavaDoc xmlBefore = invBefore.getRequestEnvelope().getAsStringFromInternal();
49       if (log.isTraceEnabled())
50          log.trace("RequestEnvelope before request handlers: " + xmlBefore);
51
52       boolean doNext = super.handleRequest(msgContext);
53
54       checkMustUnderstand(msgContext);
55
56       RPCInvocation invAfter = new RPCInvocation(invBefore);
57       invAfter.prepareFromRequestEnvelope();
58
59       String JavaDoc xmlAfter = invAfter.getRequestEnvelope().getAsStringFromInternal();
60       if (xmlBefore.equals(xmlAfter) == false)
61       {
62          if (log.isTraceEnabled())
63             log.trace("RequestEnvelope after request handlers: " + xmlAfter);
64
65          msgContext.setProperty(RPCProvider.RPC_INVOCATION, invAfter);
66       }
67
68       return doNext;
69    }
70
71    /**
72     * Initiates the response processing for this handler chain.
73     * <p/>
74     * In this implementation, the response handler chain starts processing from the same Handler
75     * instance (that returned false) and goes backward in the execution sequence.
76     *
77     * @return Returns true if all handlers in chain have been processed.
78     * Returns false if a handler in the chain returned false from its handleResponse method.
79     * @throws javax.xml.rpc.JAXRPCException if any processing error happens
80     */

81    public boolean handleResponse(MessageContext JavaDoc msgContext)
82    {
83       boolean status = super.handleResponse(msgContext);
84
85       checkMustUnderstand(msgContext);
86
87       return status;
88    }
89 }
90
Popular Tags