[MOBY-guts] biomoby commit
Paul Gordon
gordonp at dev.open-bio.org
Tue Jan 15 22:08:41 UTC 2008
gordonp
Tue Jan 15 17:08:41 EST 2008
Update of /home/repository/moby/moby-live/Java/src/Clients
In directory dev.open-bio.org:/tmp/cvs-serv15506/src/Clients
Modified Files:
MobyPinger.java
Log Message:
Update to allow test pinging of non-registered services
moby-live/Java/src/Clients MobyPinger.java,1.2,1.3
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/Clients/MobyPinger.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Java/src/Clients/MobyPinger.java 2008/01/09 20:25:36 1.2
+++ /home/repository/moby/moby-live/Java/src/Clients/MobyPinger.java 2008/01/15 22:08:41 1.3
@@ -1,8 +1,10 @@
import org.biomoby.client.CentralImpl;
import org.biomoby.client.MobyRequest;
-import org.biomoby.shared.Central;
-import org.biomoby.shared.MobyService;
+import org.biomoby.shared.*;
import org.biomoby.shared.data.*;
+import org.biomoby.shared.parser.ServiceException;
+
+import java.net.*;
import java.util.Iterator;
/**
@@ -14,69 +16,65 @@
public class MobyPinger{
public static void main(String[] args) {
+ long elapsedTimeMillis = 0;
try{
if(args.length != 2){
- System.err.println("Usage: java MobyPinger serviceName serviceProvider");
+ System.err.println("Usage: java MobyPinger serviceName (serviceProviderURI|serviceEndpointURL)");
System.exit(1);
}
Central worker = new CentralImpl ();
- worker.setDebug(true);
- // Make template for finding services
- MobyService templateService = new MobyService("dummy");
- templateService.setName(args[0]);
- templateService.setAuthority(args[1]);
-
- MobyService[] validServices = worker.findService(templateService);
-
- // Make sure we have a service to run for this input
- if(validServices == null || validServices.length == 0){
- System.err.println("Could not find a valid service with name "+
- args[0] + " and provider " + args[1]);
- System.exit(1);
+ MobyService service = null;
+ try{
+ String serviceURLString = (new URL(args[1])).toString();
+ service = new MobyService(args[0]);
+ service.setURL(serviceURLString);
+ }
+ catch(MalformedURLException murle){
}
- else{
- System.out.println("Found a services");
+ if(service == null){
+ // Make template for finding services from the registry instead
+ MobyService templateService = new MobyService(args[0]);
+ templateService.setAuthority(args[1]);
+
+ MobyService[] validServices = worker.findService(templateService);
+
+ // Make sure we have a service to run for this input
+ if(validServices == null || validServices.length == 0){
+ System.err.println("Could not find a valid service with name "+
+ args[0] + " and provider " + args[1]);
+ System.exit(1);
+ }
+ service = validServices[0];
}
MobyRequest mr = new MobyRequest(worker);
// Set input and run the service
- mr.setDebugMode(true);
- mr.setService(validServices[0]);
+ mr.setService(service);
mr.setInput(new MobyContentInstance()); // blank request
+ long startTimeMillis = System.currentTimeMillis();
MobyContentInstance responses = mr.invokeService();
+ elapsedTimeMillis = System.currentTimeMillis()-startTimeMillis;
// Process responses
// The service invocation may have had many requests, there is a response
// object for each request
- Iterator i = responses.keySet().iterator();
- while(i.hasNext()){
- MobyDataJob responseObjects = responses.get(i.next());
-
- // The response for a request may have many objects
- Iterator<MobyDataInstance> i2 = responseObjects.values().iterator();
- while(i2.hasNext()){
- MobyDataInstance responseObject = i2.next();
- // The response objects may either be simple data, or data sets
- if(responseObject instanceof MobyDataObject){
- System.out.println("Plain simple instance is "+((MobyDataInstance)responseObject).toXML());
- }
- else if(responseObject instanceof MobyDataObjectSet){
- System.out.println("Found a collection:");
- MobyDataObject[] simples = ((MobyDataObjectSet) responseObject).getElementInstances();
- for(int j = 0; j < simples.length; j++){
- System.out.println(" Member instance is \n"+simples[j].toXML());
- }
- }
- else{
- System.out.println("Found funky data!" + responseObject);
- }
- }
+ for(ServiceException ex: responses.getExceptions()){
+ if(ex.getSeverity() == ServiceException.ERROR){
+ System.err.println("Exception in response from service: " + ex);
+ System.exit(1);
+ }
+ }
+ if(responses.keySet().size() != 0){
+ System.err.println("Response from service was not blank as expected:");
+ MobyDataUtils.toXMLDocument(System.err, responses);
+ System.exit(1);
}
}catch(Exception e){
- System.out.println("Problem: "+e);
- e.printStackTrace();
+ System.out.println("Problem while running ping: "+e);
+ System.exit(1);
}
+ System.err.println("Ping successful, elapsed time for call was " + elapsedTimeMillis + "ms");
}
}
More information about the MOBY-guts
mailing list