A secure client

The client used to invoke the secure service will be almost identical to clients seen in the previous part of the tutorial (GT3 Core). In fact, to configure our client for a basic secure invocation we only need to add two lines!

((Stub)math)._setProperty(Constants.GSI_SEC_CONV,Constants.ENCRYPTION);
((Stub)math)._setProperty(Constants.AUTHORIZATION,NoAuthorization.getInstance());

What these two lines do is configure the stub class (a MathPortType object) to use security. More specifically, we're doing the following:

As mentioned before, besides those two lines, the rest of the client is practically identical to the previous ones seen in the tutorial. The only difference is that we'll be putting the add, subtract, and getValue calls inside try...catch blocks to observe how certain exceptions are raised in certain circumstances (we'll see this in the following sections).

package org.globus.progtutorial.clients.MathService;

import org.globus.progtutorial.stubs.MathService.service.MathServiceGridLocator;
import org.globus.progtutorial.stubs.MathService.MathPortType;

import org.globus.ogsa.impl.security.Constants;
import org.globus.ogsa.impl.security.authorization.NoAuthorization;

import javax.xml.rpc.Stub;
import java.net.URL;

public class ClientGSIConvEncrypt
{
  public static void main(String[] args)
  {
    try
    {
      // Get command-line arguments
      URL GSH = new java.net.URL(args[0]);
      int a = Integer.parseInt(args[1]);

      // Get a reference to the MathService instance
      MathServiceGridLocator mathLocator =   new MathServiceGridLocator();
      MathPortType math = mathLocator.getMathServicePort(GSH);
      
      // Setup security options
      ((Stub)math)._setProperty(Constants.GSI_SEC_CONV,Constants.ENCRYPTION);
      ((Stub)math)._setProperty(Constants.AUTHORIZATION,NoAuthorization.getInstance());
      

      // Call remote method 'add'
      try{
        math.add(a);
        System.out.println("Added " + a);
      } catch(Exception e)
      {
        System.out.println("ERROR: " + e.getMessage());
      }

      // Call remote method 'subtract'
      try{
        math.subtract(1);
        System.out.println("Subtracted 1");
      } catch(Exception e)
      {
        System.out.println("ERROR: " + e.getMessage());
      }

      // Get current value through remote method 'getValue'
      try{
        int value = math.getValue();
        System.out.println("Current value: " + value);
      } catch(Exception e)
      {
        System.out.println("ERROR: " + e.getMessage());
      }
    }catch(Exception e)
    {
      System.out.println("ERROR!");
      e.printStackTrace();
    }
  }
}
[Note]

This file is $TUTORIAL_DIR/org/globus/progtutorial/clients/MathService/ClientGSIConvEncrypt.java