[MOBY-guts] biomoby commit

Paul Gordon gordonp at pub.open-bio.org
Sat Aug 20 01:58:13 UTC 2005


gordonp
Fri Aug 19 21:58:13 EDT 2005
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/client
In directory pub.open-bio.org:/tmp/cvs-serv27410/src/main/org/biomoby/client

Modified Files:
	MobyRequest.java 
Log Message:
Updates to deal with requirements for named parameters in MOBY API 0.86, and some relaxing of this rule to allow existing anonymously parameterized one-input services to still be valid

moby-live/Java/src/main/org/biomoby/client MobyRequest.java,1.15,1.16
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/MobyRequest.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/MobyRequest.java	2005/08/07 23:46:12	1.15
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/MobyRequest.java	2005/08/20 01:58:13	1.16
@@ -2,6 +2,7 @@
 
 // Defines Web service input, output, access
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.PrintStream;
 import java.util.Hashtable;
 import java.util.Vector;
@@ -42,8 +43,7 @@
 public class MobyRequest{
 
     protected MobyService mobyService = null;
-    protected MobyDataInstance[] inputData = null;
-    protected MobyDataSecondaryInstance[] secondaryData = null;
+    protected MobyContentInstance inputData = null;
     protected MobyContentInstance outputData = null;
     protected Central mobyCentral = null;
     protected PrefixResolver mobyPrefixResolver = null;
@@ -187,37 +187,29 @@
      *
      * @throws IllegalArgumentException if the input does not fit the criteria of the service (e.g. wrong data type)
      */
-    public void setInput(MobyDataInstance[] data) throws IllegalArgumentException{
+    public void setInput(MobyContentInstance data) throws MobyException{
 	inputData = data;
     }
 
     /**
      * Convenience method to run services that take one unnamed argument.
      */
-    public void setInput(MobyDataInstance datum) throws IllegalArgumentException{
-        inputData = new MobyDataInstance[1];
-        inputData[0] = datum;
+    public void setInput(MobyDataInstance datum) throws MobyException{
+	setInput(datum, "");
     }
 
     /**
-     * @return the MobyService that will be executed when invokeService is called
-     */
-    public MobyDataInstance[] getInput(){
-	return inputData;
-    }
-
-    /**
-     * @param params the list of secondary input values to pass to the service
+     * Convenience method to run services that take one named argument.
      */
-    public void setSecondaryInput(MobyDataSecondaryInstance[] params) throws IllegalArgumentException{
-	secondaryData = params;
+    public void setInput(MobyDataInstance datum, String paramName) throws MobyException{
+        inputData = new MobyContentInstance(datum, paramName);
     }
 
     /**
-     * @return the list of secondary input values to pass to the service
+     * @return the MobyService that will be executed when invokeService is called
      */
-    public MobyDataSecondaryInstance[] setSecondaryInput(){
-	return secondaryData;
+    public MobyContentInstance getInput(){
+	return inputData;
     }
 
     /**
@@ -254,7 +246,7 @@
 
         getServiceFromWSDL();
 	verifyInput();
-	String mobyXML = convertMOBYDataToMOBYRequest(inputData, secondaryData);
+	String mobyXML = convertMOBYDataToMOBYRequest(inputData);
 	Element mobyDOM = performSOAPRequest(mobyXML);
 	// The following parses the DOM and extracts all the appropriate jMOBY objects to represent the XML in Java
 	outputData = MobyDataUtils.fromXMLDocument(mobyDOM);  
@@ -320,23 +312,23 @@
      * @throws MobyException if the number of input parameters was wrong, or the paramters were of the wrong type.
      */
     protected void verifyInput() throws MobyException{
-	MobyData[] requiredInputData = mobyService.getPrimaryInputs();
-
+	/*MobyData[] requiredInputData = mobyService.getPrimaryInputs();
+	
 	if(requiredInputData == null){
-	    if(inputData != null && inputData.length != 0){
+	    if(inputData != null && inputData.size() != 0){
 		throw new MobyException("Service invocation expects no input parameters, " +
 					"but setInput has not been called with a null or zero-length array argument");
 	    }
 	    return;  // otherwise there are no parameters to check
 	}
-	if(inputData == null || inputData.length == 0){
+	if(inputData == null || inputData.size() == 0){
 	    throw new MobyException("Service invocation expects " + requiredInputData.length + " input " +
 				    "parameters, but setInput has not been called to provide any input");
 	}
 	if (requiredInputData.length != inputData.length){
 	    throw new MobyException("Wrong number of input parameters to service invocation method: expected " +
 				    requiredInputData.length + ", but setInput was provided " + inputData.length);
-	}
+				    }*/
 
 	// BUG WORKAROUND: Since the Moby-generated WSDL doesn't define the input, we assume the
 	// data types are right, and we just have to check the number of them.
@@ -623,10 +615,9 @@
 	return domDoc.getDocumentElement();
     }
 
-    public String convertMOBYDataToMOBYRequest(MobyDataInstance data, MobyDataSecondaryInstance[] secondary) throws MobyException{
-        MobyDataInstance[] mdsis = new MobyDataInstance[1];
-        mdsis[0] = data;
-        return convertMOBYDataToMOBYRequest(mdsis, secondary);
+    public String convertMOBYDataToMOBYRequest(MobyDataInstance data) throws MobyException{
+	// Create a mobyContent with an anonymous one-input mobyData
+        return convertMOBYDataToMOBYRequest(new MobyContentInstance(data, ""));
     }
 
     /**
@@ -634,65 +625,25 @@
      *
      * @return the XML representation of the input data
      */
-    public String convertMOBYDataToMOBYRequest(MobyDataInstance[] data, MobyDataSecondaryInstance[] secondary) throws MobyException{
-	// Start of envelope
-	String mobyRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
-	    "       <moby:MOBY xmlns:moby=\"" + MobyPrefixResolver.MOBY_XML_NAMESPACE + "\">\n" +
-	    "          <moby:mobyContent>\n" +
-	    "<moby:mobyData moby:queryID='1'>";
-
-	// Real input data payload
-	if(data != null){
-	    for(int i = 0; i < data.length; i++){
-                int oldXmlMode = data[i].getXmlMode();
-                if(oldXmlMode != MobyDataInstance.SERVICE_XML_MODE){
-                    data[i].setXmlMode(MobyDataInstance.SERVICE_XML_MODE);
-                }
-
-		if(data[i] instanceof MobyDataObject){
-		    // This line should be replaced with a named field
-		    mobyRequest += "<Simple articleName=''>"+
-			((MobyDataObject) data[i]).toXML()+
-			"</Simple>";
-		}
-		else if(data[i] instanceof MobyDataObjectSet){
-		    mobyRequest += ((MobyDataObjectSet) data[i]).toXML();
-		}
-		else{
-		    // Could just call toXML, but don't know if it has a Simple wrapper
-		    // already or not, or even if it's a set.
-		    throw new MobyException("Element #" + i + 
-					    " of the input data was not a " +
-					    "MobyDataObject or a " +
-					    "MobyDataObjectSet (found " + 
-					    data[i].getClass().getName() + ")");
-		}
-                
-                // Restore the old XML mode setting if not service mode
-                if(oldXmlMode != MobyDataInstance.SERVICE_XML_MODE){
-                    data[i].setXmlMode(oldXmlMode);
-                }
-	    }
-	}
+    public String convertMOBYDataToMOBYRequest(MobyContentInstance data) throws MobyException{
 
-	// Now load all of the secondary parameters if there are any
-	if(secondary != null){
-	    for(int i = 0; i < secondary.length; i++){
-		mobyRequest += secondary[i].toXML();
-	    }
+	ByteArrayOutputStream mobyRequest = new ByteArrayOutputStream();
+	try{
+	    MobyDataUtils.toXMLDocument(mobyRequest, inputData);
 	}
-	
-	// End of envelope
-	mobyRequest +=
-	    "              </moby:mobyData>\n" +
-	    "          </moby:mobyContent>\n" +
-	    "       </moby:MOBY>\n";
+	catch(MobyException me){
+	    throw me;
+	}
+	catch(Exception e){
+	    throw new MobyException("Could not create MOBY payload XML from input data: " +e);
+	}
+
 	if(debug){
 	    debugPS.println("Input to MOBY Service is:");
-	    debugPS.print(mobyRequest);
+	    debugPS.print(mobyRequest.toString());
 	}
 	
-	return mobyRequest;
+	return mobyRequest.toString();
     }
 
     /**




More information about the MOBY-guts mailing list