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 TestDelegation {
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 delegate(args[0]);
26 }
27 catch (Exception e) {
28 System.err.println(e.getMessage());
29 }
30 }
31
32
33 private static void delegate (String url) throws Exception {
34
35
36
37 OGSIServiceLocator factoryLocator = new OGSIServiceLocator();
38 Factory factory = factoryLocator.getFactoryPort(new URL(url));
39 GridServiceFactory gridFactory = new GridServiceFactory(factory);
40
41
42
43 GregorianCalendar timeout = new GregorianCalendar();
44 timeout.add(GregorianCalendar.MINUTE, 3);
45 LocatorType instanceLocator = gridFactory.createService(timeout);
46 EchoServiceGridLocator portLocator = new EchoServiceGridLocator();
47 EchoPortType port = portLocator.getEchoPortType(instanceLocator);
48
49 SecurityHelper.configureSecureCall(port);
50 SecurityHelper.configureDelegation(port);
51
52
53 System.out.println("Client: address of service: " + url);
54 System.out.println("Client: result from service: " +
55 port.testDelegatedCredentials());
56 }
57 }