[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Thu Aug 20 16:59:36 UTC 2009


gordonp
Thu Aug 20 12:59:36 EDT 2009
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services
In directory dev.open-bio.org:/tmp/cvs-serv9603/src/main/ca/ucalgary/services

Modified Files:
	SoapServlet.java 
Log Message:
Added SoapServlet customization capabilities with DataRecorder and CSS
moby-live/Java/src/main/ca/ucalgary/services SoapServlet.java,1.3,1.4
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/SoapServlet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/SoapServlet.java	2009/08/17 21:16:01	1.3
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/SoapServlet.java	2009/08/20 16:59:36	1.4
@@ -23,6 +23,8 @@
 
 public class SoapServlet extends HttpServlet{
 
+    public static final String DATARECORDER_CONTEXTPARAM = "dataRecorder"; // how users spec a DataRecorder in the web.xml
+
     public static final String SERVICE_SPEC_PARAM = "service";
     public static final String WSDL_HTTP_PARAM = "wsdl";
     public static final String ID_PARAM = "seahawkId";
@@ -82,6 +84,41 @@
 		       "Could not create an XSLT transformer: " + e,
 		       e);
 	}
+
+	// See if the user has specified a DataRecorder to be used (customization and/or recording of
+	// user interaction and Web Service response).
+	String dataRecorderClassName = getInitParameter(DATARECORDER_CONTEXTPARAM);
+	javax.servlet.ServletContext context = getServletContext();
+	if(context != null){
+	    if(context.getInitParameter(DATARECORDER_CONTEXTPARAM) != null){
+		dataRecorderClassName = context.getInitParameter(DATARECORDER_CONTEXTPARAM);
+	    }
+	}
+	javax.servlet.ServletConfig config = getServletConfig();
+	if(config != null){
+	    if(config.getInitParameter(DATARECORDER_CONTEXTPARAM) != null){
+		dataRecorderClassName = config.getInitParameter(DATARECORDER_CONTEXTPARAM);
+	    }
+	}
+	if(dataRecorderClassName != null){
+	    DataRecorder dataRecorder = null;
+
+	    try{
+		// This line can throw many different exception if you didn't get the class right! 
+		Class drClass = getClass().getClassLoader().loadClass(dataRecorderClassName);
+		if(drClass == null){
+		    throw new ClassNotFoundException("The DataRecorder class to run (" + 
+						     dataRecorderClassName +
+						     ") was not found, please ensure that the web.xml is up-to-date.");
+		}
+		dataRecorder = (DataRecorder) drClass.newInstance();
+	    } catch(Exception e){
+		System.err.println("The DataRecorder implementing class was not specified properly in the web.xml file:");
+		e.printStackTrace();
+		throw new ServletException("Invalid web.xml, the parameter 'dataRecorder' was not useable");
+	    }
+	    setRecorder(dataRecorder);
+	}
     }
 
     public void setRecorder(DataRecorder r){
@@ -150,7 +187,9 @@
 	String wsdlLoc = request.getParameter(WSDL_HTTP_PARAM);
 	if(wsdlLoc == null || wsdlLoc.trim().length() == 0){
 	    response.setContentType("text/html");
-	    out.print("<html><head><title>Error</title><head><body>No '"+WSDL_HTTP_PARAM+"' parameter (the location of the WSDL document)" +
+	    out.print("<html><head><title>Error</title>"+
+		      "<link type=\"text/css\" rel=\"stylesheet\" href=\"stylesheets/input_ask.css\" />\n"+
+		      "</head><body>No '"+WSDL_HTTP_PARAM+"' parameter (the location of the WSDL document)" +
 		      "was specified in the POST request, and " +
 		      (recorder == null ? "no data recorder is associated with this servlet" : 
 		       "the data recorder did not want to intercept the POST") +"</body></html>");
@@ -160,7 +199,9 @@
 	try{
 	    url = new URL(wsdlLoc);
 	} catch(Exception e){
-	    out.print("<html><head><title>Error</title></head><body><h2>The URL specified (" + 
+	    out.print("<html><head><title>Error</title>\n"+
+		      "<link type=\"text/css\" rel=\"stylesheet\" href=\"stylesheets/input_ask.css\" />\n"+
+		      "</head><body><h2>The URL specified (" + 
 		      wsdlLoc + ") could not be parsed</h2><br><pre>");
 	    e.printStackTrace(out);
 	    out.print("</pre></body></html>\n");
@@ -169,13 +210,17 @@
 
 	String serviceSpec = request.getParameter(SERVICE_SPEC_PARAM);
 	if(wsdlLoc == null || wsdlLoc.trim().length() == 0){
-	    out.print("<html><head><title>Error</title><head><body>No '"+SERVICE_SPEC_PARAM+"' parameter (specifying " +
+	    out.print("<html><head><title>Error</title>\n"+
+		      "<link type=\"text/css\" rel=\"stylesheet\" href=\"stylesheets/input_ask.css\" />\n"+
+		      "</head><body>No '"+SERVICE_SPEC_PARAM+"' parameter (specifying " +
 		      "the service/port/operation/action/use) was specified in the POST request</body></html>");
 	    return;
 	}
 	String[] serviceSpecs = serviceSpec.split(" ");
 	if(serviceSpecs.length != 10){
-	    out.print("<html><head><title>Error</title><head><body>The '"+SERVICE_SPEC_PARAM+"' parameter (specifying " +
+	    out.print("<html><head><title>Error</title>\n"+
+		      "<link type=\"text/css\" rel=\"stylesheet\" href=\"stylesheets/input_ask.css\" />\n"+
+		      "</head><body>The '"+SERVICE_SPEC_PARAM+"' parameter (specifying " +
 		      "the service/port/operation/action/use) did not contain 10 space-separated values as expected</body></html>");
 	    return;
 	}
@@ -185,7 +230,9 @@
 	try{
 	    service = Service.create(url, serviceQName);
 	} catch(Exception e){
-	    out.print(e.getClass().getName() + " while using JAX-WS to create a handle for " +
+	    out.print("<html><head><title>Error</title>\n"+
+		      "<link type=\"text/css\" rel=\"stylesheet\" href=\"stylesheets/input_ask.css\" />\n"+
+		      "</head><body>" + e.getClass().getName() + " while using JAX-WS to create a handle for " +
 		      "the service " + serviceQName + 
 		      ", either the WSDL or the expected service name is wrong<br/><pre>");
 	    e.printStackTrace(out);
@@ -200,7 +247,9 @@
 					      Source.class,
 					      Service.Mode.PAYLOAD);
 	} catch(Exception e){
-	    out.print("<html><head><title>Error</title><head><body>" +
+	    out.print("<html><head><title>Error</title>\n"+
+		      "<link type=\"text/css\" rel=\"stylesheet\" href=\"stylesheets/input_ask.css\" />\n"+
+		      "</head><body>" +
 		      e.getClass().getName() + " while using JAX-WS to create a dispatch for a port on " +
 		      "the service " + serviceQName + ", either the WSDL or the WSDLConfig's " +
 		      "portQName parsed (" + portQName + ") is wrong:<pre>");	    
@@ -250,22 +299,30 @@
 		if(delimiter.equals(DQUOTE_OPTION) || delimiter.equals(SQUOTE_OPTION)){
 		    value = value.trim();
 		    if(delimiter.equals(DQUOTE_OPTION) && !value.startsWith("\"")){
-			out.print("<html><head><title>Error</title><head><body>" +
+			out.print("<html><head><title>Error</title>\n"+
+				  "<link type=\"text/css\" rel=\"stylesheet\" href=\"stylesheets/input_ask.css\" />\n"+
+				  "</head><body>" +
 				  "The delimiter for field " + paramName + " was double quotes" +
 				  " but the value does not start with a double quote</body></html>");
 		    }
 		    if(delimiter.equals(SQUOTE_OPTION) && !value.startsWith("'")){
-			out.print("<html><head><title>Error</title><head><body>" +
+			out.print("<html><head><title>Error</title>\n"+
+				  "<link type=\"text/css\" rel=\"stylesheet\" href=\"stylesheets/input_ask.css\" />\n"+
+				  "</head><body>" +
 				  "The delimiter for field " + paramName + " was single quotes" +
 				  " but the value does not start with a single quote</body></html>");
 		    }
 		    if(delimiter.equals(DQUOTE_OPTION) && !value.endsWith("\"")){
-			out.print("<html><head><title>Error</title><head><body>" +
+			out.print("<html><head><title>Error</title>\n"+
+				  "<link type=\"text/css\" rel=\"stylesheet\" href=\"stylesheets/input_ask.css\" />\n"+
+				  "</head><body>" +
 				  "The delimiter for field " + paramName + " was double quotes" +
 				  " but the value does not end with a double quote</body></html>");
 		    }
 		    if(delimiter.equals(SQUOTE_OPTION) && !value.endsWith("'")){
-			out.print("<html><head><title>Error</title><head><body>" +
+			out.print("<html><head><title>Error</title>\n"+
+				  "<link type=\"text/css\" rel=\"stylesheet\" href=\"stylesheets/input_ask.css\" />\n"+
+				  "</head><body>" +
 				  "The delimiter for field " + paramName + " was single quotes" +
 				  " but the value does not end with a single quote</body></html>");
 		    }		    
@@ -358,7 +415,9 @@
 						     new javax.xml.transform.stream.StreamResult(stringResult));
 		}
 	    } catch(Exception e){
-		out.print("<html><head><title>Error</title><head><body>" +
+		out.print("<html><head><title>Error</title>\n"+
+			  "<link type=\"text/css\" rel=\"stylesheet\" href=\"stylesheets/input_ask.css\" />\n"+
+			  "</head><body>" +
 			  e.getClass().getName() + " while transforming response from " +
 			  "the service " + serviceQName + " (probably an internal error):<pre>");	    
 		e.printStackTrace(out);
@@ -370,7 +429,9 @@
 	    answer = "<pre>"+stringResult.toString().replaceAll("<", "&lt;")+"</pre>";
 	}
 
-	out.print("<html><head><title>Service Response</title><head><body>"+answer+"</body></html>");
+	out.print("<html><head><title>Service Response</title>\n"+
+		  "<link type=\"text/css\" rel=\"stylesheet\" href=\"stylesheets/wsdl_result.css\" /></head>\n" +
+		  "<body>"+answer+"</body></html>");
     }
 
     // Asks for the WSDL file
@@ -387,7 +448,7 @@
 	}
 
 	try{
-	    out.write("<html><head><title>Generic SOAP Client</title></head>\n".getBytes());
+	    out.write("<html><head><title>Generic SOAP Client</title><link type=\"text/css\" rel=\"stylesheet\" href=\"stylesheets/wsdl_ask.css\" /></head>\n".getBytes());
 	    out.write("<body>Enter the URL of the WSDL file below: <form action=''><input name='".getBytes());
 	    out.write((WSDL_HTTP_PARAM+"' type='text' size='50'/>").getBytes());
 	    out.write("</form></body></html>".getBytes());
@@ -416,7 +477,9 @@
 	try{
 	    url = new URL(endpoint);
 	} catch(Exception e){
-	    out.print("<html><body><h2>The URL specified (" + endpoint + ") could not be parsed</h2><br><pre>");
+	    out.print("<html><head><title>Parsing Error</title>\n"+
+		      "<link type=\"text/css\" rel=\"stylesheet\" href=\"stylesheets/wsdl_ask.css\" />\n" +
+		      "</head><body><h2>The URL specified (" + endpoint + ") could not be parsed</h2><br><pre>");
 	    e.printStackTrace(out);
 	    out.print("</pre></body></html>\n");
 	    return;
@@ -424,7 +487,7 @@
 
 	try{
 	    out.print("<html><head><title>Input interface for WSDL Services at " + url + 
-		      "</title>");
+		      "</title><link type=\"text/css\" rel=\"stylesheet\" href=\"stylesheets/input_ask.css\" />\n");
 	    if(recorder != null){
 		out.print(recorder.getHead(request));
 	    }




More information about the MOBY-guts mailing list