[MOBY-guts] biomoby commit
Paul Gordon
gordonp at dev.open-bio.org
Tue Jun 9 19:05:35 UTC 2009
gordonp
Tue Jun 9 15:05:35 EDT 2009
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/service
In directory dev.open-bio.org:/tmp/cvs-serv20041/src/main/org/biomoby/service
Modified Files:
MobyServlet.java
Log Message:
Switched out Axis usage for SOAP message creation for hand-rolled version, due to Google App Engine bug. May revert latter
moby-live/Java/src/main/org/biomoby/service MobyServlet.java,1.16,1.17
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/MobyServlet.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/MobyServlet.java 2008/10/30 02:33:25 1.16
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/service/MobyServlet.java 2009/06/09 19:05:34 1.17
@@ -7,7 +7,7 @@
import org.biomoby.shared.*;
import org.biomoby.shared.data.*;
import org.biomoby.shared.parser.*;
-import org.biomoby.client.CentralCachedCallsImpl;
+import org.biomoby.client.CentralImpl;
import org.biomoby.client.MobyRequest;
import org.biomoby.client.rdf.builder.*;
@@ -161,8 +161,8 @@
}
}
- protected void doPost(HttpServletRequest request,
- HttpServletResponse response)
+ public void doPost(HttpServletRequest request,
+ HttpServletResponse response)
throws ServletException, java.io.IOException{
if(thisService == null){
@@ -242,10 +242,17 @@
log(errMsg);
// The SOAP envelope (headerless) consists of a body with one string element inside it
- SOAPMessage message = soapMessageFactory.createMessage();
- SOAPBodyElement bodyElement = message.getSOAPBody().addFault(bodyName, errMsg);
+ //PG SOAPMessage message = soapMessageFactory.createMessage();
+ //PG SOAPBodyElement bodyElement = message.getSOAPBody().addFault(bodyName, errMsg);
+ //PG message.writeTo(out);
+ out.write(("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
+ "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
+ "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
+ "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
+ "<soapenv:Body><soapenv:Fault><soapenv:faultcode>Client</soapenv:faultcode>" +
+ "<soapenv:faultstring>"+errMsg+"<soapenv:faultactor/><soapenv:detail/>"+
+ "</soapenv:faultstring></soapenv:Fault></soapenv:Body></soapenv:Envelope>").getBytes());
- message.writeTo(out);
return false;
} catch(Exception e){
@@ -557,6 +564,8 @@
private void writeResponse(HttpServletResponse response, MobyContentInstance mobyResults){
+ response.setContentType("text/xml");
+
java.io.OutputStream out = null;
try{
out = response.getOutputStream();
@@ -566,45 +575,54 @@
return;
}
- response.setContentType("text/xml");
-
try{
- if(bodyContentsName == null){ //first call
- SOAPFactory soapFactory = SOAPFactory.newInstance();
- bodyContentsName = soapFactory.createName(getServiceName()+"Return",
- MobyPrefixResolver.MOBY_TRANSPORT_PREFIX,
- MobyPrefixResolver.MOBY_TRANSPORT_NAMESPACE);
- bodyName = soapFactory.createName(getServiceName()+"Response",
- MobyPrefixResolver.MOBY_TRANSPORT_PREFIX,
- MobyPrefixResolver.MOBY_TRANSPORT_NAMESPACE);
- stringEncAttrName = soapFactory.createName("type",
- MobyPrefixResolver.XSI2001_PREFIX,
- MobyPrefixResolver.XSI_NAMESPACE2001);
- faultName = soapFactory.createName("Client",
- "",
- SOAPConstants.URI_NS_SOAP_ENVELOPE);
- }
+//PG if(bodyContentsName == null){ //first call
+//PG SOAPFactory soapFactory = SOAPFactory.newInstance();
+//PG bodyContentsName = soapFactory.createName(getServiceName()+"Return",
+//PG MobyPrefixResolver.MOBY_TRANSPORT_PREFIX,
+//PG MobyPrefixResolver.MOBY_TRANSPORT_NAMESPACE);
+//PG bodyName = soapFactory.createName(getServiceName()+"Response",
+//PG MobyPrefixResolver.MOBY_TRANSPORT_PREFIX,
+//PG MobyPrefixResolver.MOBY_TRANSPORT_NAMESPACE);
+//PG stringEncAttrName = soapFactory.createName("type",
+//PG MobyPrefixResolver.XSI2001_PREFIX,
+//PG MobyPrefixResolver.XSI_NAMESPACE2001);
+//PG faultName = soapFactory.createName("Client",
+//PG "",
+//PG SOAPConstants.URI_NS_SOAP_ENVELOPE);
+//PG }
java.io.ByteArrayOutputStream bytesOut = new java.io.ByteArrayOutputStream(INIT_OUTPUT_BUFFER_SIZE);
MobyDataUtils.toXMLDocument(bytesOut, mobyResults);
// The SOAP envelope (headerless) consists of a body with one string element inside it
- if(soapMessageFactory == null){
- soapMessageFactory = MessageFactory.newInstance();
- }
- SOAPMessage message = soapMessageFactory.createMessage();
- message.getSOAPHeader().detachNode();
-
- SOAPBodyElement bodyElement = message.getSOAPBody().addBodyElement(bodyName);
- SOAPElement bodyContentsElement = bodyElement.addChildElement(bodyContentsName);
- bodyContentsElement.addAttribute(stringEncAttrName, stringEncAttrValue);
- bodyContentsElement.addTextNode(bytesOut.toString());
-
- //message.writeTo(out);
- java.io.ByteArrayOutputStream outBuffer = new java.io.ByteArrayOutputStream(INIT_OUTPUT_BUFFER_SIZE);
- message.writeTo(outBuffer);
- //System.err.println(outBuffer.toString());
- out.write(outBuffer.toByteArray());
+//PG if(soapMessageFactory == null){
+//PG soapMessageFactory = MessageFactory.newInstance();
+//PG }
+//PG SOAPMessage message = soapMessageFactory.createMessage();
+//PG message.getSOAPHeader().detachNode();
+
+//PG SOAPBodyElement bodyElement = message.getSOAPBody().addBodyElement(bodyName);
+//PG SOAPElement bodyContentsElement = bodyElement.addChildElement(bodyContentsName);
+//PG bodyContentsElement.addAttribute(stringEncAttrName, stringEncAttrValue);
+//PG bodyContentsElement.addTextNode(bytesOut.toString());
+
+ response.setStatus(HttpServletResponse.SC_OK);
+// message.writeTo(out);
+ out.write(("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
+ "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
+ "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
+ "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><soapenv:Body>"+
+ "<ns1:"+getServiceName()+"Response"+
+ " soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"" +
+ " xmlns:ns1=\""+MobyPrefixResolver.MOBY_TRANSPORT_NAMESPACE+"\">"+
+ "<ns1:"+getServiceName()+"Return xsi:type=\""+stringEncAttrValue+"\">"+
+ bytesOut.toString().replaceAll("&","&").replaceAll("<","<").replaceAll(">",">")+
+ "</ns1:"+getServiceName()+"Return>"+
+ "</ns1:"+getServiceName()+"Response>"+
+ "</soapenv:Body></soapenv:Envelope>").getBytes());
+ out.flush();
+ out.close();
} catch(Exception e){
log("While writing SOAP response to client for " + getServiceName(), e);
@@ -613,6 +631,19 @@
}
+ public void log(java.lang.String msg){log(msg, null);}
+ public void log(java.lang.String msg,
+ Exception ex){
+ String fullMsg = msg+"\n";
+ if(ex != null){
+ fullMsg += ex.getClass().getName()+": "+ex.getMessage()+"\n";
+ for(StackTraceElement ste: ex.getStackTrace()){
+ fullMsg += ste.toString()+"\n";
+ }
+ }
+ System.err.println(fullMsg);
+ }
+
/**
* Writes the error to the servlet log, and adds a MobyException block to the response
*/
@@ -648,7 +679,7 @@
else{
response.addException(new ServiceException(ServiceException.ERROR,
ServiceException.INTERNAL_PROCESSING_ERROR,
- ex.toString()));
+ ex.toString().replaceAll("<","<")));
}
if(isInitialized){
log("While executing Moby Service (initialized) " + getServiceName(), ex);
@@ -672,7 +703,7 @@
ServiceException.INTERNAL_PROCESSING_ERROR,
job.getID(),
null,
- ex.toString()));
+ ex.toString().replaceAll("<","<")));
}
if(isInitialized){
log("While executing Moby Service (initialized) " + getServiceName() + ", job '" + job.getID()+"'", ex);
@@ -706,7 +737,7 @@
System.setProperty("javax.xml.soap.SOAPFactory",
"org.apache.axis.soap.SOAPFactoryImpl");
}
- soapMessageFactory = MessageFactory.newInstance();
+ //PG soapMessageFactory = MessageFactory.newInstance();
// Maps storing invocation-specific context variable
templatedServicesMap = new HashMap<Thread,MobyService>();
@@ -724,10 +755,12 @@
}
if(centralURL != null && centralURL.length() > 0){
- mobyRequest = new MobyRequest(new CentralCachedCallsImpl(centralURL));
+ mobyRequest = new MobyRequest(CentralImpl.getDefaultCentral(new Registry("any_synonym",
+ centralURL,
+ "any_ns")));
}
else{
- mobyRequest = new MobyRequest(new CentralCachedCallsImpl());
+ mobyRequest = new MobyRequest(CentralImpl.getDefaultCentral());
}
registry = new Registry("any_synonym",
mobyRequest.getCentralImpl().getRegistryEndpoint(),
@@ -822,7 +855,9 @@
Map<String,MobyDataTypeTemplate> templateDataTypeMap = new HashMap<String,MobyDataTypeTemplate>();
for(int i = 0; i < ins.length; i++){
// non-void param
- inputTypes.add(stringToPrimaryDataTemplate(ins[i], templateDataTypeMap));
+ if(ins[i] != null && ins[i].length() > 0){
+ inputTypes.add(stringToPrimaryDataTemplate(ins[i], templateDataTypeMap));
+ }
}
String[] outs = ann.out();
@@ -881,9 +916,9 @@
String[] desc = ann.description();
// Did we override the service type in the web.xml?
- if(getCoCInitParameter(MOBY_SERVICETYPE_PARAM) != null){
+ if(getCoCInitParameter(MOBY_SERVICE_DESC_PARAM) != null){
desc = new String[1];
- desc[0] = getCoCInitParameter(MOBY_SERVICETYPE_PARAM);
+ desc[0] = getCoCInitParameter(MOBY_SERVICE_DESC_PARAM);
}
if(desc == null){
throw new Exception("Could not find required " + MOBY_SERVICE_DESC_PARAM +
@@ -1218,8 +1253,9 @@
}
if(type == null){
throw new Exception("The parameter specification (" +
- spec + ") has a data type not found in the " +
- "MOBY registry, aborting! (Either correct the type," +
+ spec + ") has a data type (" + objectType + ") not found in the " +
+ "MOBY registry (" + registry.getEndpoint() +
+ "), aborting! Either correct the type," +
" or register it as a new type in MOBY Central");
}
// Defining a template data type, MobyDataTypeTemplate will
@@ -1238,17 +1274,20 @@
// namespace is optional
if(st.hasMoreTokens()){
- String namespaceValue = st.nextToken();
- MobyNamespace nsObject = MobyNamespace.getNamespace(namespaceValue, registry);
- if(nsObject == null){
- System.err.println("WARNING: The parameter specification (" +
- spec + ") has a namespace not found in the " +
- "MOBY registry! I'm proceeding anyway, but please " +
- "either correct the value, " +
- "or register it as a new namespace in MOBY Central");
- nsObject = new MobyNamespace(namespaceValue);
+ String namespaceValues = st.nextToken();
+ // There may actually be multiple namespaces, separated by commas
+ for(String namespaceValue: namespaceValues.split(",")){
+ MobyNamespace nsObject = MobyNamespace.getNamespace(namespaceValue, registry);
+ if(nsObject == null){
+ System.err.println("WARNING: The parameter specification (" +
+ spec + ") has a namespace not found in the " +
+ "MOBY registry! I'm proceeding anyway, but please " +
+ "either correct the value, " +
+ "or register it as a new namespace in MOBY Central");
+ nsObject = new MobyNamespace(namespaceValue);
+ }
+ dataTemplate.addNamespace(nsObject);
}
- dataTemplate.addNamespace(nsObject);
}
if(st.hasMoreTokens()){
More information about the MOBY-guts
mailing list