We will try out our service first with a simple client that creates a new resource and performs a couple operations on it. This client expects only one argument from the command line, the factory service's URI
package org.globus.examples.clients.FactoryService_Math;
import org.apache.axis.message.addressing.Address;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.globus.examples.stubs.MathService_instance.GetValueRP;
import org.globus.examples.stubs.MathService_instance.MathPortType;
import org.globus.examples.stubs.MathService_instance.service.MathServiceAddressingLocator;
import org.globus.examples.stubs.Factory.service.FactoryServiceAddressingLocator;
import org.globus.examples.stubs.Factory.FactoryPortType;
import org.globus.examples.stubs.Factory.CreateResource;
import org.globus.examples.stubs.Factory.CreateResourceResponse;
/* This client creates a new MathService instance through a FactoryService. This client
* expects one parameter: the factory URI.
*/
public class Client {
public static void main(String[] args) {
FactoryServiceAddressingLocator factoryLocator = new FactoryServiceAddressingLocator();
MathServiceAddressingLocator instanceLocator = new MathServiceAddressingLocator();
try {
String factoryURI = args[0];
EndpointReferenceType factoryEPR, instanceEPR;
FactoryPortType mathFactory;
MathPortType math;
factoryEPR = new EndpointReferenceType();
factoryEPR.setAddress(new Address(factoryURI));
mathFactory = factoryLocator.getFactoryPortTypePort(factoryEPR);
CreateResourceResponse createResponse = mathFactory
.createResource(new CreateResource());
instanceEPR = createResponse.getEndpointReference();
math = instanceLocator.getMathPortTypePort(instanceEPR);
System.out.println("Created instance.");
// Perform an addition
math.add(10);
// Perform another addition
math.add(5);
// Access value
System.out
.println("Current value:" + math.getValueRP(new GetValueRP()));
// Perform a subtraction
math.subtract(5);
// Access value
System.out
.println("Current value:" + math.getValueRP(new GetValueRP()));
} catch (Exception e) {
e.printStackTrace();
}
}
}
![]() | |
This file is
|
Compile and run the client:
javac \ -classpath ./build/stubs/classes/:$CLASSPATH \ org/globus/examples/clients/FactoryService_Math/Client.java
java \ -classpath ./build/stubs/classes/:$CLASSPATH \ org.globus.examples.clients.FactoryService_Math.Client \ http://127.0.0.1:8080/wsrf/services/examples/core/factory/MathFactoryService
If all goes well, you should see the following:
Created instance. Current value:15 Current value:10
If you run it again, you will get the exact same result. This is because we are creating a new resource every time we run the client.
Created instance. Current value:15 Current value:10