View Javadoc

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      // Get access to the factory port.  Use the GridServiceFactory
35      // wrapper to the port to simplify the interface of the
36      // createService method.
37      OGSIServiceLocator factoryLocator = new OGSIServiceLocator();
38      Factory factory = factoryLocator.getFactoryPort(new URL(url));
39      GridServiceFactory gridFactory = new GridServiceFactory(factory);
40          
41      // Create a service instance and locate its echo port.
42      // Set a 10-minute timeout.
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      // Invoke the echo port.
53      System.out.println("Client: address of service: " + url);
54      System.out.println("Client: result from service: " +
55                         port.testDelegatedCredentials());
56    }
57  }