KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > transport > http > HTTPInvokerTestClient


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

21 public class HTTPInvokerTestClient extends AbstractInvokerTest
22 {
23    // Default locator values
24
private static String JavaDoc transport = "http";
25    private static String JavaDoc host = "localhost";
26    private static int port = 8888;
27
28    public HTTPInvokerTestClient(String JavaDoc name)
29    {
30       super(name);
31    }
32
33    public HTTPInvokerTestClient(String JavaDoc name, int numberOfInstances)
34    {
35       super(name, numberOfInstances);
36    }
37
38    public HTTPInvokerTestClient(String JavaDoc name, String JavaDoc transport, int port)
39    {
40       super(name, transport, port);
41    }
42
43    public HTTPInvokerTestClient(String JavaDoc name, String JavaDoc transport, int port, int numberOfInstances)
44    {
45       super(name, transport, port, numberOfInstances);
46    }
47
48    public void testInvocation() throws Exception JavaDoc
49    {
50       String JavaDoc locatorURI = transport + "://" + host + ":" + port;
51       InvokerLocator locator = new InvokerLocator(locatorURI);
52       System.out.println("Calling remoting server with locator uri of: " + locatorURI);
53
54       // This could have been new Client(locator), but want to show that subsystem param is null
55
// Could have also been new Client(locator, "sample");
56
Client remotingClient = new Client(locator, null);
57
58       Map JavaDoc metadata = new HashMap JavaDoc();
59       metadata.put(Client.RAW, Boolean.TRUE);
60       metadata.put("TYPE", "POST");
61
62       Properties JavaDoc headerProps = new Properties JavaDoc();
63       headerProps.put("SOAPAction", "http://www.example.com/fibonacci");
64       headerProps.put("Content-type", "application/soap+xml");
65
66       metadata.put("HEADER", headerProps);
67
68       Object JavaDoc response = null;
69
70       // test with null return expected
71
try
72       {
73          response = remotingClient.invoke(HTTPInvokerTestServer.NULL_RETURN_PARAM, metadata);
74       }
75       catch(Throwable JavaDoc throwable)
76       {
77          throw new Exception JavaDoc(throwable);
78       }
79
80       assertNull(response);
81
82       try
83       {
84          response = remotingClient.invoke("Do something", metadata);
85       }
86       catch(Throwable JavaDoc throwable)
87       {
88          throw new Exception JavaDoc(throwable);
89       }
90
91       assertEquals(HTTPInvokerTestServer.RESPONSE_VALUE, response);
92
93       headerProps.put("Content-type", HTTPServerInvoker.BINARY);
94       try
95       {
96          response = remotingClient.invoke(new ComplexObject(2, "foo", true), metadata);
97       }
98       catch(Throwable JavaDoc throwable)
99       {
100          throw new Exception JavaDoc(throwable);
101       }
102
103       assertEquals(HTTPInvokerTestServer.OBJECT_RESPONSE_VALUE, response);
104
105    }
106
107    /**
108     * Can pass transport and port to be used as parameters.
109     * Valid transports are 'rmi' and 'socket'.
110     *
111     * @param args
112     */

113    public static void main(String JavaDoc[] args)
114    {
115       int numberOfInstances = 2;
116
117       if(args != null && args.length == 1)
118       {
119          numberOfInstances = Integer.parseInt(args[0]);
120       }
121       if(args != null && args.length == 2)
122       {
123          transport = args[0];
124          port = Integer.parseInt(args[1]);
125       }
126
127       HTTPInvokerTestClient client = new HTTPInvokerTestClient(HTTPInvokerTestClient.class.getName(), numberOfInstances);
128       try
129       {
130          //regular class run
131
MultipleTestRunner runner = new MultipleTestRunner();
132          runner.doRun(client, true);
133       }
134       catch(Throwable JavaDoc e)
135       {
136          e.printStackTrace();
137          System.exit(1);
138       }
139       System.exit(0);
140
141    }
142
143 }
Popular Tags