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 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      // Get access to the factory port.  Use the GridServiceFactory
37      // wrapper to the port to simplify the interface of the
38      // createService method.
39      OGSIServiceLocator factoryLocator = new OGSIServiceLocator();
40      Factory factory = factoryLocator.getFactoryPort(new URL(url));
41      GridServiceFactory gridFactory = new GridServiceFactory(factory);
42          
43      // Create a service instance and locate its echo port.
44      // Set a 10-minute timeout.
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      // Set up authenticated access: make credentials available in
52      // calls to the service.
53      SecurityHelper.configureSecureCall(port);
54                                 
55      // Invoke the echo port.
56      System.out.println("Client: result from service: " + port.whoAmI());
57      System.out.println("Client: the test finished without exceptions.");
58    }
59  }