1 package org.astrogrid.ogsa.echo;
2
3 import java.net.URL;
4 import java.util.GregorianCalendar;
5 import org.astrogrid.ogsa.echo.EchoServiceLocator;
6 import org.astrogrid.ogsa.echo.EchoPortType;
7 import org.gridforum.ogsi.Factory;
8 import org.gridforum.ogsi.LocatorType;
9 import org.gridforum.ogsi.OGSIServiceLocator;
10 import org.globus.ogsa.utils.GridServiceFactory;
11
12 /***
13 * Exercises an echo service with a single invocation.
14 */
15 public class TestWhoAmI {
16
17 public static void main (String[] args) throws Exception {
18
19 if (args.length != 1) {
20 System.err.println("usage: java org.astrogrid.ogsa.echo.TestWhoAmI <factory-URL>");
21 return;
22 }
23
24 try {
25 whoAmI(args[0]);
26 }
27 catch (Exception e) {
28 System.err.println(e.getMessage());
29 }
30 }
31
32
33 private static void whoAmI (String url) throws Exception {
34 System.out.println("Client: service factory: " + url);
35
36
37
38
39 OGSIServiceLocator factoryLocator = new OGSIServiceLocator();
40 Factory factory = factoryLocator.getFactoryPort(new URL(url));
41 GridServiceFactory gridFactory = new GridServiceFactory(factory);
42
43
44
45 GregorianCalendar timeout = new GregorianCalendar();
46 timeout.add(GregorianCalendar.MINUTE, 10);
47 LocatorType instanceLocator = gridFactory.createService(timeout);
48 EchoServiceGridLocator portLocator = new EchoServiceGridLocator();
49 EchoPortType port = portLocator.getEchoPortType(instanceLocator);
50
51
52
53 SecurityHelper.configureSecureCall(port);
54
55
56 System.out.println("Client: result from service: " + port.whoAmI());
57 System.out.println("Client: the test finished without exceptions.");
58 }
59 }