assignment 2 modifying, compiling, and deploying a simple service presenter information goes here
Post on 19-Dec-2015
215 views
TRANSCRIPT
Assignment 2Modifying, Compiling, and Deploying a Simple Service
Presenter Information goes Here
Beyond Axis -> Globus Web Services
• The axis program from Assignment 1 was stateless, that is, the service did not remember previous operations.
• Globus Web Services now introduce the idea of state, that is, a service can remember what was previously done to the service.
An Interface For Our Service• Supposing we were going to
create a Java interface for our service, we would create:
public class MathService {
public void add( int num );
public void subtract( int num );
public int getValue();
}
Defining the Service in WSDL
• Instead of having a Java class and creating the WSDL as we did in Assignment 1, we are given the WSDL here:
/home/username/assignment2/schema/examples/MathService_instance/Math.wsdl
Excerpts from the WSDL
• <definitions name="MathService“ targetNamespace="http://www.globus.org/namespaces/examples/core/MathService_instance“ – Defines that the service name is “MathService” and specifies the default name space.
• <xsd:element name="add" type="xsd:int"/><xsd:element name="addResponse"> <xsd:complexType/></xsd:element> - Specifies that there is a method called ‘add’ which takes an ‘int’.
• Each response (i.e. ‘addResponse’) must also have an entry.
(Con’t) Excerpts from the WSDL• <xsd:element name="Value"
type="xsd:int"/><xsd:element name="LastOp" type="xsd:string"/> - The fields from the service. That is, there is a field called ‘value’ and a field called ‘lastOp’ in the Java class.
• <message name="AddInputMessage"><part name="parameters“ element="tns:add"/></message><message name="AddOutputMessage"><part name="parameters“ element="tns:addResponse"/></message> - Creates the response for the method invocation of ‘add’.
(Con’t) Excerpts from the WSDL
<portType name="MathPortType" <!-- …. --> <operation name="add"> <input message="tns:AddInputMessage"/> <output message="tns:AddOutputMessage"/> </operation> <!-- …--></portType>
Creating The Service
• From the ‘assignment2’ directory, the source for the client is located in
org/globus/examples/services/core/first/impl/MathService.java
Important Sections of The Source
• private int value;private String lastOp;These fields provide state to the service.
• This method provides the ‘add’ method.
public AddResponse add(int a) throws RemoteException { value += a; lastOp = "ADDITION"; return new AddResponse();}
A Brief Mention of the Deployment Descriptor
• Another XML document is the deployment descriptor. (WSDD)
• This document provides the necessary details for the server.
• A few of the lines ‘just has to be there’. We will skip showing this file.
Finally! - Building The Service
• The Soyomotor tutorial provided a script file to build the service using Ant (Another Neat Tool).
• Steve McKinney, from ASU, created two scripts (nameChanger.sh and build.sh) to allow multiple people to run the same web service.
• Run the build:% ./build.sh first
Deploying the GAR file
• As a security precaution, only the globus user can deploy web services.
• To allow multiple users to deploy services, we use sudo.
• Sudo allows one user to execute a command as another user.
Deployment (Con’t)
• From the command line:
% sudo –u globus globus-deploy-gar \org_globus_examples_services_core_username_first.gar
• The result should be ‘Deploy Successful’.
Starting the Container
• To be able to access our service, we must have a container that lists the service.
• To start the new container, the globus user runs the following command:
% globus-start-container -nosec
Compiling The Client
• The client is provided at:
• The client contains several important parts, which will be explained next.
/home/yourusername/Assignment2/org/globus/examples/clients/MathService_instance/Client.java
Client Source Code – Explained!
MathServiceAddressingLocator locator = new MathServiceAddressingLocator();
This code creates the locator for the MathService.
EndpointReferenceType endpoint = new EndpointReferenceType();
endpoint.setAddress(new Address(serviceURI));
This code sets the location of the service.
math = locator.getMathPortTypePort(endpoint);
This code points the MathPortType to the end point.
Client Source Code – Explained! (Con’t)
• The actual call to the service is done on the following line:
math.add(10);
• The service should now register an increase of 10 units. (When the code is ran.)
Compile the Client
• From the command line:javac -classpath \
./build/classes/org/globus/examples/services/core/yourusername_first/impl/:$CLASSPATH \
org/globus/examples/clients/MathService_instance/Client.java
Run The Client
• From the command line:
• The output should be similar to:
Current value: 15Current value: 10
java –classpath \./build/classes/org/globus/examples/
services/core/yourusername_first/impl/:$CLASSPATH \org/globus/examples/clients/MathService_instance/Client \http://localhost:yourportnumber/wsrf/services/examples/
core/yourusername_first/MathService
Undeploy The Service
• To undeploy the service, run the following from the command line:
% sudo -u globus \globus-undeploy-gar \org_globus_examples_services_core_yourusername_first*The bottom piece is all on one line!
What’s Next?
• Students in the course are asked to extend the functionality of the MathService by adding multiplication capabilities.
Conclusion
• We have– Defined a Globus Web
Service using the WSDL– Build the Web Service– Compiled a client for the
Web Service– Used the client to contact
the Web Service.
Questions?
Please ask!