KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.HashMap JavaDoc;
10 import java.util.Map JavaDoc;
11 import java.util.Properties JavaDoc;
12 import org.jboss.remoting.Client;
13 import org.jboss.remoting.InvokerLocator;
14 import org.jboss.remoting.transport.http.HTTPServerInvoker;
15
16 import junit.framework.TestCase;
17
18 /**
19  * @author <a HREF="mailto:tom.elrod@jboss.com">Tom Elrod</a>
20  */

21 public abstract class WebInvokerTestClient extends TestCase
22 {
23    public abstract String JavaDoc getLocatorURI();
24
25    public void testInvocation() throws Exception JavaDoc
26    {
27       Client remotingClient = null;
28
29       try
30       {
31          InvokerLocator locator = new InvokerLocator(getLocatorURI());
32          System.out.println("Calling remoting server with locator uri of: " + getLocatorURI());
33
34          remotingClient = new Client(locator);
35
36          Map JavaDoc metadata = new HashMap JavaDoc();
37          metadata.put(Client.RAW, Boolean.TRUE);
38          metadata.put("TYPE", "POST");
39
40          Properties JavaDoc headerProps = new Properties JavaDoc();
41          headerProps.put("Content-type", "application/soap+xml");
42
43          metadata.put("HEADER", headerProps);
44
45          Object JavaDoc response = null;
46
47          // test with null return expected
48
response = remotingClient.invoke(WebInvocationHandler.NULL_RETURN_PARAM, metadata);
49          System.out.println("First response should be null and was: " + response);
50          assertNull(response);
51
52          response = remotingClient.invoke("Do something", metadata);
53          System.out.println("Second response should be " + WebInvocationHandler.HTML_PAGE_RESPONSE + " and was: " + response);
54          assertEquals(WebInvocationHandler.HTML_PAGE_RESPONSE, response);
55
56          headerProps.put("Content-type", HTTPServerInvoker.BINARY);
57          response = remotingClient.invoke(new ComplexObject(2, "foo", true), metadata);
58          System.out.println("Third response should be " + WebInvocationHandler.OBJECT_RESPONSE_VALUE + " and was: " + response);
59          assertEquals(WebInvocationHandler.OBJECT_RESPONSE_VALUE, response);
60
61          response = remotingClient.invoke(WebInvocationHandler.STRING_RETURN_PARAM, metadata);
62          System.out.println("Fourth response should be " + WebInvocationHandler.RESPONSE_VALUE + " and was: " + response);
63          assertEquals(WebInvocationHandler.RESPONSE_VALUE, response);
64
65          try
66          {
67             response = remotingClient.invoke(WebInvocationHandler.THROW_EXCEPTION_PARAM, metadata);
68             assertTrue("Should have received an exception.", false);
69          }
70          catch(Throwable JavaDoc throwable)
71          {
72             assertTrue("Received exception as expected", true);
73             //throwable.printStackTrace();
74
}
75
76          remotingClient.invokeOneway("Do something", metadata, true);
77
78          remotingClient.invokeOneway("Do something", metadata, false);
79       }
80       catch(Throwable JavaDoc throwable)
81       {
82          throw new Exception JavaDoc(throwable);
83       }
84       finally
85       {
86          if(remotingClient != null)
87          {
88             remotingClient.disconnect();
89          }
90       }
91
92
93    }
94 }
Popular Tags