KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > remoting > transport > web > WebInvocationHandler


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.test.remoting.transport.web;
8
9 import javax.management.MBeanServer JavaDoc;
10 import org.jboss.remoting.InvocationRequest;
11 import org.jboss.remoting.ServerInvocationHandler;
12 import org.jboss.remoting.ServerInvoker;
13 import org.jboss.remoting.callback.InvokerCallbackHandler;
14
15 /**
16  * @author <a HREF="mailto:tom.elrod@jboss.com">Tom Elrod</a>
17  */

18 public class WebInvocationHandler implements ServerInvocationHandler
19 {
20    // String to be returned from invocation handler upon client invocation calls.
21
public static final String JavaDoc RESPONSE_VALUE = "This is the return to SampleInvocationHandler invocation";
22    public static final ComplexObject OBJECT_RESPONSE_VALUE = new ComplexObject(5, "dub", false);
23
24    public static final String JavaDoc NULL_RETURN_PARAM = "return_null";
25    public static final String JavaDoc OBJECT_RETURN_PARAM = "return_object";
26    public static final String JavaDoc THROW_EXCEPTION_PARAM = "throw_exception";
27    public static final String JavaDoc STRING_RETURN_PARAM = "return_string";
28    public static final String JavaDoc HTML_PAGE_RESPONSE = "<html><head><title>Test HTML page</title></head><body>" +
29                                                    "<h1>HTTP/Servlet Test HTML page</h1><p>This is a simple page served for test." +
30                                                    "<p>Should show up in browser or via invoker client</body></html>";
31
32
33    /**
34     * called to handle a specific invocation
35     *
36     * @param invocation
37     * @return
38     * @throws Throwable
39     */

40    public Object JavaDoc invoke(InvocationRequest invocation) throws Throwable JavaDoc
41    {
42       // Print out the invocation request
43
System.out.println("Invocation request is: " + invocation.getParameter());
44       if(NULL_RETURN_PARAM.equals(invocation.getParameter()))
45       {
46          return null;
47       }
48       else if(THROW_EXCEPTION_PARAM.equals(invocation.getParameter()))
49       {
50          throw new Exception JavaDoc("This is an exception being thrown as part of test case. It is intentional.");
51       }
52       else if(invocation.getParameter() instanceof ComplexObject)
53       {
54          return OBJECT_RESPONSE_VALUE;
55       }
56       else if(STRING_RETURN_PARAM.equals(invocation.getParameter()))
57       {
58          // Just going to return static string as this is just simple example code.
59
return RESPONSE_VALUE;
60       }
61       else
62       {
63          return HTML_PAGE_RESPONSE;
64       }
65    }
66
67    /**
68     * Adds a callback handler that will listen for callbacks from
69     * the server invoker handler.
70     *
71     * @param callbackHandler
72     */

73    public void addListener(InvokerCallbackHandler callbackHandler)
74    {
75       // NO OP as do not handling callback listeners in this example
76
}
77
78    /**
79     * Removes the callback handler that was listening for callbacks
80     * from the server invoker handler.
81     *
82     * @param callbackHandler
83     */

84    public void removeListener(InvokerCallbackHandler callbackHandler)
85    {
86       // NO OP as do not handling callback listeners in this example
87
}
88
89    /**
90     * set the mbean server that the handler can reference
91     *
92     * @param server
93     */

94    public void setMBeanServer(MBeanServer JavaDoc server)
95    {
96       // NO OP as do not need reference to MBeanServer for this handler
97
}
98
99    /**
100     * set the invoker that owns this handler
101     *
102     * @param invoker
103     */

104    public void setInvoker(ServerInvoker invoker)
105    {
106       // NO OP as do not need reference back to the server invoker
107
}
108
109 }
Popular Tags