assignment 2 modifying, compiling, and deploying a simple service presenter information goes here

23
Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

Post on 19-Dec-2015

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

Assignment 2Modifying, Compiling, and Deploying a Simple Service

Presenter Information goes Here

Page 2: Assignment 2 Modifying, 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.

Page 3: Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

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();

}

Page 4: Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

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

Page 5: Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

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.

Page 6: Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

(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’.

Page 7: Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

(Con’t) Excerpts from the WSDL

<portType name="MathPortType" <!-- …. --> <operation name="add"> <input message="tns:AddInputMessage"/> <output message="tns:AddOutputMessage"/> </operation> <!-- …--></portType>

Page 8: Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

Creating The Service

• From the ‘assignment2’ directory, the source for the client is located in

org/globus/examples/services/core/first/impl/MathService.java

Page 9: Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

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();}

Page 10: Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

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.

Page 11: Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

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

Page 12: Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

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.

Page 13: Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

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’.

Page 14: Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

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

Page 15: Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

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

Page 16: Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

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.

Page 17: Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

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.)

Page 18: Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

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

Page 19: Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

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

Page 20: Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

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!

Page 21: Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

What’s Next?

• Students in the course are asked to extend the functionality of the MathService by adding multiplication capabilities.

Page 22: Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

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.

Page 23: Assignment 2 Modifying, Compiling, and Deploying a Simple Service Presenter Information goes Here

Questions?

Please ask!