KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > samples > simple > SimpleClient


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.samples.simple;
8
9 import org.jboss.remoting.Client;
10 import org.jboss.remoting.InvokerLocator;
11
12 /**
13  * Simple test client to make an invocation on remoting server.
14  *
15  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
16  */

17 public class SimpleClient
18 {
19    // Default locator values
20
private static String JavaDoc transport = "socket";
21    private static String JavaDoc host = "localhost";
22    private static int port = 5400;
23
24    public void makeInvocation(String JavaDoc locatorURI) throws Throwable JavaDoc
25    {
26       // create InvokerLocator with the url type string
27
// indicating the target remoting server to call upon.
28
InvokerLocator locator = new InvokerLocator(locatorURI);
29       System.out.println("Calling remoting server with locator uri of: " + locatorURI);
30
31       Client remotingClient = new Client(locator);
32       String JavaDoc request = "Do something";
33       System.out.println("Invoking server with request of '" + request + "'");
34       Object JavaDoc response = remotingClient.invoke(request);
35
36       System.out.println("Invocation response: " + response);
37    }
38
39    /**
40     * Can pass transport and port to be used as parameters.
41     * Valid transports are 'rmi' and 'socket'.
42     *
43     * @param args
44     */

45    public static void main(String JavaDoc[] args)
46    {
47       if(args != null && args.length == 3)
48       {
49          transport = args[0];
50          host = args[1];
51          port = Integer.parseInt(args[2]);
52       }
53       String JavaDoc locatorURI = transport + "://" + host + ":" + port;
54       SimpleClient client = new SimpleClient();
55       try
56       {
57          client.makeInvocation(locatorURI);
58       }
59       catch(Throwable JavaDoc e)
60       {
61          e.printStackTrace();
62       }
63    }
64
65
66 }
Popular Tags