[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Thu Apr 12 00:51:45 UTC 2007


gordonp
Wed Apr 11 20:51:45 EDT 2007
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/service
In directory dev.open-bio.org:/tmp/cvs-serv30372/src/main/org/biomoby/service

Modified Files:
	MobyServlet.java 
Log Message:
Made servlet parameter fethcing more robust by always checking servlet config AND context for a non-null value
moby-live/Java/src/main/org/biomoby/service MobyServlet.java,1.6,1.7
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/MobyServlet.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/MobyServlet.java	2007/03/12 16:57:30	1.6
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/MobyServlet.java	2007/04/12 00:51:45	1.7
@@ -625,8 +625,8 @@
 	    MobyDataType.getDataType("Object");
 
 	    // Not sure we actually need MobyRequest yet...
- 	    if(getInitParameter(MOBY_CENTRAL_URL_PARAM) != null){
- 		mobyRequest = new MobyRequest(new CentralCachedCallsImpl(getInitParameter(MOBY_CENTRAL_URL_PARAM)));
+ 	    if(getCoCInitParameter(MOBY_CENTRAL_URL_PARAM) != null){
+ 		mobyRequest = new MobyRequest(new CentralCachedCallsImpl(getCoCInitParameter(MOBY_CENTRAL_URL_PARAM)));
  	    }
  	    else{
  		mobyRequest = new MobyRequest(new CentralCachedCallsImpl());
@@ -640,6 +640,22 @@
 	isInitialized = true;
     }
 
+    protected String getCoCInitParameter(String paramName){
+	javax.servlet.ServletConfig config = getServletConfig();
+	if(config != null){
+	    if(config.getInitParameter(paramName) != null){
+		return config.getInitParameter(paramName);
+	    }
+	}
+	javax.servlet.ServletContext context = getServletContext();
+	if(context != null){
+	    if(context.getInitParameter(paramName) != null){
+		return context.getInitParameter(paramName);
+	    }
+	}
+	return getInitParameter(paramName);
+    }
+
     public synchronized MobyService createServiceFromConfig(HttpServletRequest request) throws Exception{
 	MobyService service = new MobyService(getServiceName());
 
@@ -671,8 +687,8 @@
 
 	// Inputs and outputs and service type must be defined
 	String[] ins = ann.in();
-	if(config != null && config.getInitParameter(MOBY_INPUT_PARAM) != null){
-	    ins = config.getInitParameter(MOBY_INPUT_PARAM).split(",");
+	if(getCoCInitParameter(MOBY_INPUT_PARAM) != null){
+	    ins = getCoCInitParameter(MOBY_INPUT_PARAM).split(",");
 	}
 	if(ins == null){
 	    throw new Exception("Could not find required " + MOBY_INPUT_PARAM + 
@@ -684,8 +700,8 @@
 	}
 
 	String[] outs = ann.out();
-	if(config != null && config.getInitParameter(MOBY_OUTPUT_PARAM) != null){
-	    outs = config.getInitParameter(MOBY_OUTPUT_PARAM).split(",");
+	if(getCoCInitParameter(MOBY_OUTPUT_PARAM) != null){
+	    outs = getCoCInitParameter(MOBY_OUTPUT_PARAM).split(",");
 	}
 	if(outs == null){
 	    throw new Exception("Could not find required " + MOBY_OUTPUT_PARAM + 
@@ -698,8 +714,8 @@
 	}
 
 	String[] secondaries = ann.secondaryParams();
-	if(config != null && config.getInitParameter(MOBY_SECONDARYINPUT_PARAM) != null){
-	    secondaries = config.getInitParameter(MOBY_SECONDARYINPUT_PARAM).split(",");
+	if(getCoCInitParameter(MOBY_SECONDARYINPUT_PARAM) != null){
+	    secondaries = getCoCInitParameter(MOBY_SECONDARYINPUT_PARAM).split(",");
 	}
 	if(secondaries != null && secondaries.length > 0){
 	    for(String secondary: secondaries){
@@ -713,8 +729,8 @@
 	// A description and provider URI must be available too
 	String param = ann.type();
 	// Did we override the service type in the web.xml?
-	if(config != null && config.getInitParameter(MOBY_SERVICETYPE_PARAM) != null){
-	    param = config.getInitParameter(MOBY_SERVICETYPE_PARAM);
+	if(getCoCInitParameter(MOBY_SERVICETYPE_PARAM) != null){
+	    param = getCoCInitParameter(MOBY_SERVICETYPE_PARAM);
 	}
 	if(param == null){
 	    throw new Exception("Could not find required " + MOBY_SERVICETYPE_PARAM + 
@@ -733,9 +749,9 @@
 
 	String[] desc = ann.description();
 	// Did we override the service type in the web.xml?
-	if(config != null && config.getInitParameter(MOBY_SERVICETYPE_PARAM) != null){
+	if(getCoCInitParameter(MOBY_SERVICETYPE_PARAM) != null){
 	    desc = new String[1];
-	    desc[0] = config.getInitParameter(MOBY_SERVICETYPE_PARAM);
+	    desc[0] = getCoCInitParameter(MOBY_SERVICETYPE_PARAM);
 	}
 	if(desc == null){
 	    throw new Exception("Could not find required " + MOBY_SERVICE_DESC_PARAM + 
@@ -753,8 +769,8 @@
 
 	param = ann.provider();
 	// Did we override the provider info in web.xml?
-	if(config != null && config.getInitParameter(MOBY_PROVIDER_URI_PARAM) != null){
-	    param = config.getInitParameter(MOBY_PROVIDER_URI_PARAM);
+	if(getCoCInitParameter(MOBY_PROVIDER_URI_PARAM) != null){
+	    param = getCoCInitParameter(MOBY_PROVIDER_URI_PARAM);
 	}
 	if(param == null){
 	    throw new Exception("Could not find required " + MOBY_PROVIDER_URI_PARAM + 
@@ -774,8 +790,8 @@
 
 	param = ann.author();
 	// Did we override the contact info in web.xml?
-	if(config != null && config.getInitParameter(MOBY_CONTACT_PARAM) != null){
-	    param = config.getInitParameter(MOBY_CONTACT_PARAM);
+	if(getCoCInitParameter(MOBY_CONTACT_PARAM) != null){
+	    param = getCoCInitParameter(MOBY_CONTACT_PARAM);
 	}
 	if(param == null){
 	    throw new Exception("Could not find required " + MOBY_CONTACT_PARAM + 
@@ -803,7 +819,7 @@
 	service.setSignatureURL(endPointURL+"?"+MODE_HTTP_PARAM+"="+RDF_MODE);
 	// Other fields (authoritative and contact info) are highly recommended, but optional
 	if(config != null){
-	    param = config.getInitParameter(MOBY_AUTHORITATIVE_PARAM);
+	    param = getCoCInitParameter(MOBY_AUTHORITATIVE_PARAM);
 	    if(param != null){
 		if("YES".equals(param.toUpperCase()) || "Y".equals(param.toUpperCase()) || "1".equals(param)){
 		    service.setAuthoritative(true);
@@ -833,11 +849,10 @@
 	mobyService ann = 
 	    this.getClass().getAnnotation(mobyService.class);
 
-	javax.servlet.ServletConfig config = getServletConfig();
 	String param = null;
 	// Did we override the service type in the web.xml?
-	if(config != null && config.getInitParameter(MOBY_SERVICENAME_PARAM) != null){
-	    param = config.getInitParameter(MOBY_SERVICENAME_PARAM);
+	if(getCoCInitParameter(MOBY_SERVICENAME_PARAM) != null){
+	    param = getCoCInitParameter(MOBY_SERVICENAME_PARAM);
 	    if(param != null && param.length() != 0){
 		return param;
 	    }




More information about the MOBY-guts mailing list