KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > remoting > transport > http > HTTPInvokerTestServer


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.http;
8
9 import org.jboss.jrunit.extensions.ServerTestCase;
10 import org.jboss.remoting.InvokerLocator;
11 import org.jboss.remoting.transport.Connector;
12 import org.jboss.test.remoting.transport.web.ComplexObject;
13 import org.jboss.test.remoting.transport.web.WebInvocationHandler;
14
15 /**
16  * @author <a HREF="mailto:tom.elrod@jboss.com">Tom Elrod</a>
17  */

18 public class HTTPInvokerTestServer extends ServerTestCase implements HTTPInvokerConstants
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
27    private Connector connector = null;
28
29    public void setupServer() throws Exception JavaDoc
30    {
31       String JavaDoc locatorURI = transport + "://" + host + ":" + port;
32       InvokerLocator locator = new InvokerLocator(locatorURI);
33       System.out.println("Starting remoting server with locator uri of: " + locatorURI);
34       connector = new Connector();
35       connector.setInvokerLocator(locator.getLocatorURI());
36       connector.start();
37
38       WebInvocationHandler invocationHandler = new WebInvocationHandler();
39       // first parameter is sub-system name. can be any String value.
40
connector.addInvocationHandler("sample", invocationHandler);
41    }
42
43    protected void setUp() throws Exception JavaDoc
44    {
45       setupServer();
46    }
47
48    protected void tearDown() throws Exception JavaDoc
49    {
50       if(connector != null)
51       {
52          connector.stop();
53          connector.destroy();
54       }
55    }
56
57    public static void main(String JavaDoc[] args)
58    {
59       HTTPInvokerTestServer server = new HTTPInvokerTestServer();
60       try
61       {
62          server.setUp();
63          Thread.currentThread().sleep(300000);
64       }
65       catch(Exception JavaDoc e)
66       {
67          e.printStackTrace();
68       }
69       finally
70       {
71          try
72          {
73             server.tearDown();
74          }
75          catch(Exception JavaDoc e)
76          {
77             e.printStackTrace();
78          }
79       }
80    }
81
82 }
Popular Tags