[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Mon Aug 17 21:16:01 UTC 2009


gordonp
Mon Aug 17 17:16:01 EDT 2009
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services
In directory dev.open-bio.org:/tmp/cvs-serv25717/src/main/ca/ucalgary/services

Modified Files:
	SoapServlet.java 
Log Message:
Refactoring and corrections to allow proper functioning when no data recorder is provided (just a vanilla WSDL proxy, not a PBE system)
moby-live/Java/src/main/ca/ucalgary/services SoapServlet.java,1.2,1.3
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/SoapServlet.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/SoapServlet.java	2009/08/06 14:36:32	1.2
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/services/SoapServlet.java	2009/08/17 21:16:01	1.3
@@ -48,7 +48,7 @@
 
     private static Logger logger = Logger.getLogger("ca.ucalgary.services.SoapServlet");
 
-    private PBERecorder recorder = null;
+    private DataRecorder recorder = null;
 
     static{
 	DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
@@ -84,14 +84,14 @@
 	}
     }
 
-    public void setRecorder(PBERecorder r){
+    public void setRecorder(DataRecorder r){
 	recorder = r;
 	if(indentationTransformer != null){
 	    recorder.setTransformer(indentationTransformer);
 	}
     }
 
-    public PBERecorder getRecorder(){
+    public DataRecorder getRecorder(){
 	return recorder;
     }
 
@@ -106,7 +106,7 @@
 	    recorder.startRecording(request); //should set up a session
 	}
 
-	String action = request.getParameter("seahawkAction");
+	String action = request.getParameter(DataRecorder.PASSTHROUGH_ACTION);
 	if(action != null && action.trim().length() > 0){
 	    // Delegate to the seahawk action recorder for wrapping
 	    recorder.doGet(request, response);
@@ -114,22 +114,8 @@
 	}
 
 	String endpoint = request.getParameter(WSDL_HTTP_PARAM);
-	String xpath = request.getParameter(PBERecorder.RETURN_XPATH_PARAM);
-	String autocompleteRequest = request.getParameter(PBERecorder.AUTOCOMPLETE_PARAM);
-	String resource = request.getParameter(PBERecorder.RESOURCE_FILE_PARAM);
-	String raw = request.getParameter(PBERecorder.RAW_XPATH_PARAM);
-	if(raw != null && raw.trim().length() != 0 && recorder != null){
-	    recorder.getRawXml(request, response);
-	}
-	else if(resource != null && resource.trim().length() != 0 && recorder != null){
-	    recorder.getResource(request, response);
-	}
-	else if(xpath != null && xpath.trim().length() != 0){
-	    writeWrapperForm(request, response);
-	}
-	//AJAX call for autocomplete
-	else if(autocompleteRequest != null && autocompleteRequest.trim().length() != 0){
-	    writeAutocompleteReply(request, response, autocompleteRequest);
+	if(recorder != null && recorder.shouldIntercept(request)){
+	    recorder.interceptRequest(request, response);
 	}
 	else if(endpoint == null || endpoint.trim().length() == 0){  // Normal web-browser form fill-in
 	    writeInputForm(request, response);
@@ -155,19 +141,20 @@
 	}
 
 	// Find out the info needed to build the JAX-WS client
+	if(recorder != null && recorder.shouldIntercept(request)){
+	//if(wsdlLoc == null || wsdlLoc.trim().length() == 0){
+	//    if(recorder != null){
+	    recorder.interceptRequest(request, response);
+	    return;
+	}
 	String wsdlLoc = request.getParameter(WSDL_HTTP_PARAM);
 	if(wsdlLoc == null || wsdlLoc.trim().length() == 0){
-	    if(recorder != null){
-		writeWrapperForm(request, response);
-	    }
-	    else{
-		response.setContentType("text/html");
-		out.print("<html><head><title>Error</title><head><body>No '"+WSDL_HTTP_PARAM+"' parameter (the location of the WSDL document)" +
-			  "was specified in the POST request, and no PBE recorder " +
-			  "is associated with this servlet</body></html>");
-		
-	    }
-	    return;
+	    response.setContentType("text/html");
+	    out.print("<html><head><title>Error</title><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>");
+	    
 	}
 	URL url = null;
 	try{
@@ -189,7 +176,7 @@
 	String[] serviceSpecs = serviceSpec.split(" ");
 	if(serviceSpecs.length != 10){
 	    out.print("<html><head><title>Error</title><head><body>The '"+SERVICE_SPEC_PARAM+"' parameter (specifying " +
-		      "the service/port/operation/action/use) did not contain 8 space-separated values as expected</body></html>");
+		      "the service/port/operation/action/use) did not contain 10 space-separated values as expected</body></html>");
 	    return;
 	}
 	
@@ -225,8 +212,8 @@
 	String messageNSURI = serviceSpecs[4];
 	String messageName = serviceSpecs[5];
 	String soapAction = serviceSpecs[6];
-	String opName = serviceSpecs[7];  // literal or encoded
-	String style = serviceSpecs[8];  // literal or encoded
+	String opName = serviceSpecs[7];
+	String style = serviceSpecs[8];  // doc or rpc
 	String use = serviceSpecs[9];  // literal or encoded
 
 	QName qName = "rpc".equals(style) ? 
@@ -380,82 +367,12 @@
 	    }
 	    // Now, we don't want to show the output directly, instead escape all markup
 	    // so the end-user sees it 
-	    answer = "<pre>"+answer.replaceAll("<", "&lt;")+"</pre>";
+	    answer = "<pre>"+stringResult.toString().replaceAll("<", "&lt;")+"</pre>";
 	}
 
 	out.print("<html><head><title>Service Response</title><head><body>"+answer+"</body></html>");
     }
 
-    private void writeAutocompleteReply(HttpServletRequest request,
-					HttpServletResponse response,
-					String seed){
-	java.io.OutputStream out = null;
-	response.setContentType("text/plain");
-	try{
-	    out = response.getOutputStream();
-	}
-	catch(java.io.IOException ioe){
-	    logger.log(Level.SEVERE, "While getting servlet output stream (for HTML form response to client)", ioe);
-	    return;
-	}
-
-	String answer = "No data recorder appears to be associated with Seahawk, " +
-	    "please inform gordonp at ucalgary.ca that you got this autocomplete error.";
-	if(recorder != null){
-	    try{
-		answer = recorder.autocomplete(request, seed);
-	    } catch(Exception e){
-		//todo
-		answer = e.toString();
-	    }
-	}
-
-	try{
-	    out.write(answer.getBytes());
-	}
-	catch(java.io.IOException ioe){
-	    logger.log(Level.SEVERE, "While printing HTML form to servlet output stream", ioe);
-	    return;
-	}		
-    }
-
-    // This is called when the user has picked a part of the service response to return in the MOBY service being created
-    private void writeWrapperForm(HttpServletRequest request,
-				  HttpServletResponse response){
-	java.io.OutputStream out = null;
-	response.setContentType("text/html");
-	try{
-	    out = response.getOutputStream();
-	}
-	catch(java.io.IOException ioe){
-	    logger.log(Level.SEVERE, "While getting servlet output stream (for HTML form response to client)", ioe);
-	    return;
-	}
-	
-	String answer = "No data recorder appears to be associated with Seahawk, " +
-	    "please inform gordonp at ucalgary.ca that you got this error.";
-	if(recorder != null){
-	    try{
-		out.write(recorder.writeWrapperForm(request).getBytes());
-		return;
-	    } catch(Exception e){
-		answer = "Error in PBE system:\n" + e.toString()+"\n";
-		for(StackTraceElement ste: e.getStackTrace()){
-		    answer += ste.toString()+"\n";
-		}
-	    }
-	}
-
-	try{
-	    out.write("<html><head><title>Service Definition Error</title></head>\n".getBytes());
-	    out.write(("<body>"+answer+"</body></html>").getBytes());
-	}
-	catch(java.io.IOException ioe){
-	    logger.log(Level.SEVERE, "While printing HTML form to servlet output stream", ioe);
-	    return;
-	}	
-    }
-
     // Asks for the WSDL file
     private void writeInputForm(HttpServletRequest request,
 				HttpServletResponse response){
@@ -1025,7 +942,6 @@
 				    use = msg2Use.get(opQName);
 				}
 
-				boolean actionGiven = false;
 				for(Map.Entry<String,QName> part: partsMap.entrySet()){
 				    // doc style, should be only one part
 				    if(!isRpcStyle){ // assume document style
@@ -1038,10 +954,10 @@
 						writeDataType(out, part.getKey(), part.getValue(), element2Members, "");
 					    }
 					    out.print("Error: cannot find definition for data type " + 
-						      dataType); //"\nValid types are:");
-					    // for(QName key: element2Members.keySet()){
-// 						out.print(" "+key);
-// 					    }
+						      dataType + "\nValid types are:");
+					    for(QName key: element2Members.keySet()){
+ 						out.print(" "+key);
+ 					    }
 					    continue;
 					}
 					for(Map.Entry<String,QName> subpart: subpartsMap.entrySet()){
@@ -1050,12 +966,12 @@
 				    }
 				    else{ // rpc style
 					writeDataType(out, part.getKey(), part.getValue(), element2Members, "");
-					if(!actionGiven){
-					    actionSpec = actionSpec + opQName.getNamespaceURI() + " " + opQName.getLocalPart();
-					    actionGiven = true;
-					}
 				    }
 				}  // for parts
+				// special condition for rpc calls, still need to give the op ns & name
+				if(isRpcStyle){
+				    actionSpec = actionSpec + opQName.getNamespaceURI() + " " + opQName.getLocalPart();
+				}
 				actionSpec = actionSpec + " " + op2Action.get(opQName) + " " + 
 				    opQName.getLocalPart() + " " + style + " " + use;
 				out.print("<input type='hidden' name='"+SERVICE_SPEC_PARAM+"' value='"+actionSpec+"'/>");
@@ -1139,7 +1055,7 @@
 	    else{
 		tns = contextNode.lookupNamespaceURI(p[0]);
 	    }
-	    if(p[0].equals("tns")){  // osmetimes the tns prefix is not declared, but used anyway
+	    if(p[0].equals("tns")){  // sometimes the tns prefix is not declared, but used anyway
 		return getTargetNSQName(p[1], contextNode);
 	    }
 	    else{




More information about the MOBY-guts mailing list