[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Thu Mar 13 23:06:48 UTC 2008


gordonp
Thu Mar 13 19:06:48 EDT 2008
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services
In directory dev.open-bio.org:/tmp/cvs-serv31771/src/main/ca/ucalgary/services

Modified Files:
	CGIService.java 
Log Message:
Changes made to reflect refactoring for XHTMLForm/MobySpecWrapper
moby-live/Java/src/main/ca/ucalgary/services CGIService.java,1.6,1.7
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/CGIService.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/CGIService.java	2008/02/27 15:23:56	1.6
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/CGIService.java	2008/03/13 23:06:48	1.7
@@ -22,10 +22,9 @@
  * publishing, etc.  The service description fetching, and the command invocation
  * are overridden.
  */
-public class CGIService extends LegacyService{
+public class CGIService extends WrapperService<XHTMLForm>{
     protected URL remoteFormURL;
     // params that override annoation and servlet context/config params
-    protected Map<String,String> cgiConfig; 
     protected XHTMLForm formConfig;
     // mobyParamName -> form fields that used a transformed version of it
     protected Map<String,String[]> mobyPrimary2FormFields;
@@ -40,7 +39,6 @@
     public void init(){
 	super.init();
 
-	cgiConfig = new HashMap<String,String>();
 	mobyPrimary2FormFields = new HashMap<String,String[]>();
 	mobySecondary2FormFields = new HashMap<String,String[]>();
 
@@ -158,77 +156,18 @@
     public MobyService createServiceFromConfig(javax.servlet.http.HttpServletRequest request)
 	throws Exception{
 	
-	String remoteFormURLString = null;
-	if(getCoCInitParameter(HTML_FORM_URL_PARAM) != null){
-	    remoteFormURLString = getCoCInitParameter(HTML_FORM_URL_PARAM);
-	}
-	else{
-	    throw new Exception("No parameter called " + HTML_FORM_URL_PARAM + 
-				" was found in the servlet configuration");
-	}
-	try{
-	    remoteFormURL = new URL(remoteFormURLString);
-	} catch(Exception e){
-            // Fallback to finding it as a resource
-            remoteFormURL = getClass().getClassLoader().getResource(remoteFormURLString);
-            if(remoteFormURL == null){
-	      throw new Exception("The configuration parameter '" + remoteFormURLString +
-	    			  "' (value '" + remoteFormURLString + 
-				  "') was not parseable as a URL");
-            }
-	}
+        remoteFormURL = getSpecURL(HTML_FORM_URL_PARAM);
 
 	try{
 	    formConfig = new XHTMLForm(remoteFormURL);
 	} catch(Exception e){
             e.printStackTrace();
 	    throw new Exception("Could not determine Moby service configuration from the HTML form (" + 
-				remoteFormURLString + "): " + e);
+				remoteFormURL.toString() + "): " + e);
 	}
-	// Configure meta-data for the Moby service about to be created
-	String[] serviceNames = formConfig.getServiceNames();
-	if(serviceNames.length > 1){
-	    String targetedService = getCoCInitParameter(MOBY_SERVICENAME_PARAM);
-	    String valuesString = "";
-	    for(String value: serviceNames){
-		valuesString += value + " ";
-	    }
-	    if(targetedService == null || targetedService.trim().length() == 0){
-		throw new Exception("The HTML page to wrap contains more than one Moby-annotated " +
-				    "form/service, but no '"+MOBY_SERVICENAME_PARAM+"' parameter was " +
-				    "specified in the servlet configuration.  Please specify this " +
-				    "parameter with one of the following values: " + valuesString);
-	    }
-	    boolean foundService = false;
-	    for(String validName: serviceNames){
-		if(targetedService.equals(validName)){
-		    foundService = true; 
-		    break;
-		}
-	    }
-	    if(!foundService){
-		throw new Exception("The service to wrap (" + targetedService + 
-				    "), named in the servlet configuration parameter '" +
-				    MOBY_SERVICENAME_PARAM + "', was not one of the service names " +
-				    "available from the HTML page.  Valid values are: " + valuesString);
-	    }
-	    formConfig.setCurrentService(targetedService);
-	}
-	setCoCInitParameter(MOBY_SERVICENAME_PARAM, formConfig.getServiceName());
-	setCoCInitParameter(MOBY_SERVICETYPE_PARAM, formConfig.getServiceType());
-	setCoCInitParameter(MOBY_SERVICE_DESC_PARAM, formConfig.getServiceDesc());
-	setCoCInitParameter(MOBY_PROVIDER_URI_PARAM, formConfig.getProviderURI());
-	setCoCInitParameter(MOBY_CENTRAL_URL_PARAM, formConfig.getCentralEndpoint());
-	setCoCInitParameter(MOBY_CONTACT_PARAM, formConfig.getContactEmail());
-
-	// Determine primary I/O parameters
-	setCoCInitParameter(MOBY_INPUT_PARAM, createInputSpecString(formConfig));
-	setCoCInitParameter(MOBY_OUTPUT_PARAM, createOutputSpecString(formConfig));
-	// Determine secondary parameters
-	setCoCInitParameter(MOBY_SECONDARYINPUT_PARAM, createSecondarySpecString(formConfig));
 
-	// Set up reusable http client objects
-	return super.createServiceFromConfig(request);
+        //Call to parent, which handles spec-wrapper-to-MobyServlet-config conversion
+	return createServiceFromConfig(request, formConfig);
     }
 
     protected MultipartRequestEntity getMultipartRequest(Map<String,byte[]> dataInstances, 
@@ -270,18 +209,6 @@
 	return XHTMLForm.join("+", queryItems);
     }
 
-    protected String getCoCInitParameter(String paramName){
-	javax.servlet.ServletConfig config = getServletConfig();
-	if(cgiConfig != null && cgiConfig.containsKey(paramName)){
-	    return cgiConfig.get(paramName);
-	}
-	return super.getCoCInitParameter(paramName);
-    }
-
-    public void setCoCInitParameter(String param, String value){
-	cgiConfig.put(param, value);
-    }
-
     public String createInputSpecString(XHTMLForm form){
 	Map<String,String> ins = form.getPrimaryInputs();
 	// Create a reverse map so we can look up where a moby param 
@@ -319,10 +246,16 @@
     }
 
     public String createOutputSpecString(XHTMLForm form){
-	return XHTMLForm.join(",", form.getPrimaryOutputs());
+	Map<String,String> outs = form.getPrimaryOutputs();
+	String[] outSpec = new String[outs.size()];
+	int i = 0;
+	for(String key: outs.keySet()){
+	    outSpec[i++] = key;
+	}
+	return XHTMLForm.join(",", outSpec);
     }
 
-    protected String createSecondarySpecString(XHTMLForm form){
+    public String createSecondarySpecString(XHTMLForm form){
 	Map<String,String> secondaries = form.getSecondaryInputs();
 	// Create a reverse map so we can look up where a moby param 
 	// slots into in the form.




More information about the MOBY-guts mailing list