ACGT Web Service Wizard Guide

From HealthGrid wiki

Jump to: navigation, search

ACGT Web Service Wizard

This guide presents how to work with simple application for generating skeleton of the service compliant with ACGT infrastructure. The application has a form of wizard that simplifies the procedure, which is described in details in ACGT Web Service reference implementation guide. You can download the application from here

“Hello World!” Tutorial

The aim of this tutorial is to create the most basic Web Service displaying the “Hello World” string using ACGT Web Service Wizard.

1. Run the application. In the first window choose 'Create a new service' and click 'OK'.

Acgtwsw001.png

2. Enter the name and destination package of your service. In this example the name is HelloWorld, and the package is example.helloworld. Open the settings window and insert Location and Namespace of the service.

Acgtwsw000.png

In the methods section click the 'Add' button and define a new method called sayHello returning a String value. Do not add any arguments or exceptions.

Acgtwsw002.png

Click 'OK' in the operation window and 'Next' in the main window.

Acgtwsw003.png

3. The second panel contains dummy java code generated from the data entered in the previous step. Do not modify anything, click 'Next'.

Acgtwsw004.png

4. Browse the generated WSDL code and click 'Next'.

Acgtwsw005.png

5. In this step you can fill your methods with the actual code. Modify sayHello() method to return the “Hello World!” string. Click 'Next'.

Acgtwsw006.png

6. The service is ready. Now it needs to be deployed into a service container. If you have already installed Apache Tomcat on your computer choose the first option to use it. Otherwise select the second one. Notice, that to run a gsi-enabled service you must use a dedicated Tomcat distribution, so if you choose the first option make sure that you use a correct version. Click 'Next'.

Acgtwsw007.png

7. Select the destination location for the service container. Enter paths to service certificates. Leave other fields unchanged. If you wish to use a local tarball as a source for Tomcat installation click an appropriate radio button and enter the path. Click 'Next'.

Acgtwsw008.png

8. Downloading the server may take a while, depending on your Internet connection speed. Once the installation is done, your service is ready to use. Code of a simple client using the HelloWorld service is listed below. For details on running the client refer to ACGT Web Service tutorial. helloworld.jar can be found in $ApplicationDir/client/HelloWorld/ directory.
package acgt.examples.hello; 

import java.net.MalformedURLException; 
import java.net.URL; 
import java.rmi.RemoteException; 
import javax.xml.rpc.ServiceException; 
import org.apache.axis.client.Stub; 
import org.globus.axis.gsi.GSIConstants; 
import org.globus.axis.util.Util; 
import org.globus.wsrf.impl.security.authentication.Constants; 
import org.globus.wsrf.impl.security.authorization.IdentityAuthorization; 
import org.gridforum.jgss.ExtendedGSSManager; 
import org.ietf.jgss.GSSCredential; 
import org.ietf.jgss.GSSException; 
import helloworld.HelloWorld_PortType; 
import helloworld.HelloWorldServiceLocator; 

public class HelloWorldClient{ 
   public static void main( String[] args){ 
      String url = "https://localhost:8443/acgt/services/HelloWorld"; 
      URL hello_url = null; 
      try{ 
         hello_url = new URL( url); 
         }catch( MalformedURLException e1){ 
         System.err.println( "Malformed url: " + url); 
         System.exit( 1); 
         } 
      String hello_dn = "/C=PL/O=GRID/O=PSNC/CN=grms/fury.man.poznan.pl"; 
      ExtendedGSSManager manager = (ExtendedGSSManager)ExtendedGSSManager.getInstance(); 
      GSSCredential credential = null; 
      try{ 
         credential = manager.createCredential( GSSCredential.INITIATE_AND_ACCEPT); 
      }catch( GSSException e){ 
         System.err.println( "Failed to load user's proxy"); 
         System.out.println(e.getStackTrace()); 
         e.printStackTrace(); 
         System.exit( 1); 
      } 
      HelloWorldServiceLocator locator = new HelloWorldServiceLocator(); 
      HelloWorld_PortType helloWorld = null; 
      try{ 
         helloWorld = locator.getHelloWorld(hello_url); 
      } catch( ServiceException e){ 
         System.err.println( "Failed to get port type"); 
         System.exit( 1); 
      } 
      ((Stub)helloWorld)._setProperty(GSIConstants.GSI_CREDENTIALS, credential); 
      ((Stub)helloWorld)._setProperty(GSIConstants.GSI_MODE, GSIConstants.GSI_MODE_FULL_DELEG); 
      ((Stub)helloWorld)._setProperty(Constants.GSI_TRANSPORT, Constants.ENCRYPTION); 
      ((Stub)helloWorld)._setProperty(Constants.GSI_SEC_CONV, Constants.SIGNATURE); 
      ((Stub)helloWorld)._setProperty(Constants.AUTHORIZATION, new IdentityAuthorization(hello_dn)); 
      Util.registerTransport(); 
      try{ 
         String message = helloWorld.sayHello(); 
         System.out.println( message); 
      }catch( RemoteException e){ 
         System.err.println(e); 
         e.printStackTrace(); 
      } 
   } 
}

“Showing who's calling” Tutorial

This tutorial shows how to create a gsi-enabled service displaying basic information about invoking person.

1. Run the application, select 'Create a new service' and click 'OK'.
2. Enter the name (Hello) and destination package of the service (acgt.examples.hello). Click the 'Structures' button. This will open a new window.

Acgtwsw009.png

Click 'Add' to create a new structure. Fill the fields like in the image below.

Acgtwsw010.png

Click 'OK'. In the editor window enter the following code:
package acgt.examples.hello; 
public class HelloException extends Throwable{ 
   public int errorCode; 
   public String errorMessage; 
} 
Click 'OK'.
Create an operation called hello returning a String value. In the 'Exceptions' tab add a HelloException.

Acgtwsw011.png

If you wish to use Grid Authorization Service go back to the main window, tick the checkbox and insert GAS Location and port number.

Acgtwsw012.png

In the 'Settings' window set the classpath using the + button so that it contains paths to the following set of jars:
  • axis.jar
  • jaxrpc.jar
  • wsrf_core.jar
Remember also to fill the Location and Namespace fields.

Acgtwsw015.png

3. Click 'Next' until the fourth panel appears. Replace its content with the following code:
package acgt.examples.hello; 

import java.security.Principal; 
import javax.security.auth.Subject; 
import org.apache.axis.MessageContext; 
import org.globus.wsrf.impl.security.authentication.Constants; 

public class HelloSoapBindingImpl implements acgt.examples.hello.Hello_PortType{ 

   public java.lang.String hello() throws java.rmi.RemoteException, acgt.examples.hello.HelloException{ 
        String userDN = null; 
        Subject subject = (Subject)MessageContext.getCurrentContext().getProperty(Constants.PEER_SUBJECT); 
        if( subject != null){ 
           Principal principal = null; 
           if( subject.getPrincipals().isEmpty() == false){ 
              principal = (Principal)subject.getPrincipals().iterator().next(); 
              if( principal != null){ 
                 userDN = principal.getName(); 
              } 
           } 
        } 
        return userDN; 
   } 
}
4. Deploy the service like in the 'HelloWorld' tutorial.
Personal tools