*/\r
package jalview.ws.ebi;\r
\r
-import java.io.*;\r
-import java.util.*;\r
-import javax.xml.namespace.*;\r
-import javax.xml.rpc.*;\r
-\r
-import org.apache.axis.client.Call;\r
-import org.apache.axis.client.Service;\r
-import org.apache.axis.encoding.*;\r
+import java.io.BufferedInputStream;\r
+import java.io.BufferedReader;\r
+import java.io.File;\r
+import java.io.FileOutputStream;\r
+import java.io.InputStreamReader;\r
+import java.net.URL;\r
+import java.util.ArrayList;\r
+import java.util.StringTokenizer;\r
\r
/**\r
* DOCUMENT ME!\r
*/\r
public class EBIFetchClient\r
{\r
- Call call;\r
-\r
String format = "default";\r
\r
String style = "raw";\r
*/\r
public EBIFetchClient()\r
{\r
- try\r
- {\r
- call = (Call) new Service().createCall();\r
- call.setTargetEndpointAddress(new java.net.URL(\r
- "http://www.ebi.ac.uk/ws/services/Dbfetch"));\r
- } catch (Exception ex)\r
- {\r
- }\r
}\r
\r
/**\r
*/\r
public String[] getSupportedDBs()\r
{\r
- try\r
- {\r
- call.setOperationName(new QName("urn:Dbfetch", "getSupportedDBs"));\r
- call.setReturnType(XMLType.SOAP_ARRAY);\r
-\r
- return (String[]) call.invoke(new Object[]\r
- {});\r
- } catch (Exception ex)\r
- {\r
- return null;\r
- }\r
+ // TODO - implement rest call for dbfetch getSupportedDBs\r
+ throw new Error("Not yet implemented");\r
}\r
\r
/**\r
*/\r
public String[] getSupportedFormats()\r
{\r
- try\r
- {\r
- call.setOperationName(new QName("urn:Dbfetch", "getSupportedFormats"));\r
- call.setReturnType(XMLType.SOAP_ARRAY);\r
-\r
- return (String[]) call.invoke(new Object[]\r
- {});\r
- } catch (Exception ex)\r
- {\r
- return null;\r
- }\r
+ // TODO - implement rest call for dbfetch getSupportedFormats\r
+ throw new Error("Not yet implemented");\r
}\r
\r
/**\r
*/\r
public String[] getSupportedStyles()\r
{\r
- try\r
- {\r
- call.setOperationName(new QName("urn:Dbfetch", "getSupportedStyles"));\r
- call.setReturnType(XMLType.SOAP_ARRAY);\r
-\r
- return (String[]) call.invoke(new Object[]\r
- {});\r
- } catch (Exception ex)\r
- {\r
- return null;\r
- }\r
+ // TODO - implement rest call for dbfetch getSupportedStyles\r
+ throw new Error("Not yet implemented");\r
}\r
\r
public File fetchDataAsFile(String ids, String f, String s)\r
throws OutOfMemoryError\r
{\r
- String[] data = fetchData(ids, f, s);\r
- // TODO: after JV 2.4 - test data==null and pass error(s) back up if\r
- // possible (OutOfMemoryErrors are usual problem)\r
- if (data == null)\r
- {\r
- return null;\r
- }\r
File outFile = null;\r
try\r
{\r
outFile = File.createTempFile("jalview", ".xml");\r
outFile.deleteOnExit();\r
- PrintWriter out = new PrintWriter(new FileOutputStream(outFile));\r
- int index = 0;\r
- while (index < data.length)\r
+ fetchData(ids, f, s, outFile);\r
+ if (outFile.length() == 0)\r
{\r
- out.println(data[index]);\r
- index++;\r
+ outFile.delete();\r
+ return null;\r
}\r
- out.close();\r
} catch (Exception ex)\r
{\r
}\r
public String[] fetchData(String ids, String f, String s)\r
throws OutOfMemoryError\r
{\r
+ return fetchData(ids, f, s, null);\r
+ }\r
+\r
+ public String[] fetchData(String ids, String f, String s, File outFile)\r
+ throws OutOfMemoryError\r
+ {\r
// Need to split\r
// ids of the form uniprot:25KD_SARPE;ADHR_DROPS;\r
+ String[] rslts = new String[0];\r
StringTokenizer queries = new StringTokenizer(ids, ";");\r
String db = null;\r
StringBuffer querystring = null;\r
+ int nq = 0;\r
while (queries.hasMoreTokens())\r
{\r
String query = queries.nextToken();\r
if (querystring == null)\r
{\r
querystring = new StringBuffer(query);\r
+ nq++;\r
}\r
else\r
{\r
querystring.append("," + query);\r
+ nq++;\r
}\r
}\r
if (db == null)\r
{\r
System.err.println("Invalid Query string : '" + ids\r
+ "'\nShould be of form 'dbname:q1;q2;q3;q4'");\r
+ return null;\r
}\r
- return fetchBatch(querystring.toString(), db, f, s);\r
+ String[] rslt = fetchBatch(querystring.toString(), db, f, s, outFile);\r
+ if (rslt != null)\r
+ {\r
+ String[] nrslts = new String[rslt.length + rslts.length];\r
+ System.arraycopy(rslts, 0, nrslts, 0, rslts.length);\r
+ System.arraycopy(rslt, 0, nrslts, rslts.length, rslt.length);\r
+ rslts = nrslts;\r
+ }\r
+\r
+ return (rslts.length == 0 ? null : rslts);\r
}\r
\r
- public String[] fetchBatch(String ids, String db, String f, String s)\r
- throws OutOfMemoryError\r
+ public String[] fetchBatch(String ids, String db, String f, String s,\r
+ File outFile) throws OutOfMemoryError\r
{\r
- // max 50 ids can be added at one time\r
+ long time = System.currentTimeMillis();\r
+ // max 200 ids can be added at one time\r
try\r
{\r
- // call.setOperationName(new QName("urn:Dbfetch", "fetchData"));\r
- call.setOperationName(new QName("urn:Dbfetch", "fetchBatch"));\r
- call.addParameter("ids", XMLType.XSD_STRING, ParameterMode.IN);\r
- call.addParameter("db", XMLType.XSD_STRING, ParameterMode.IN);\r
- call.addParameter("format", XMLType.XSD_STRING, ParameterMode.IN);\r
- call.addParameter("style", XMLType.XSD_STRING, ParameterMode.IN);\r
- call.setReturnType(XMLType.SOAP_ARRAY);\r
+ URL rcall = new URL("http://www.ebi.ac.uk/Tools/dbfetch/dbfetch/"\r
+ + db.toLowerCase() + "/" + ids.toLowerCase()\r
+ + (f != null ? "/" + f : ""));\r
\r
- if (f != null)\r
+ BufferedInputStream is = new BufferedInputStream(rcall.openStream());\r
+ if (outFile != null)\r
{\r
- format = f;\r
+ FileOutputStream fio = new FileOutputStream(outFile);\r
+ byte[] bb = new byte[32 * 1024];\r
+ int l;\r
+ while ((l = is.read(bb)) > 0)\r
+ {\r
+ fio.write(bb, 0, l);\r
+ }\r
+ fio.close();\r
+ is.close();\r
}\r
-\r
- if (s != null)\r
+ else\r
{\r
- style = s;\r
+ BufferedReader br = new BufferedReader(new InputStreamReader(is));\r
+ String rtn;\r
+ ArrayList<String> arl = new ArrayList<String>();\r
+ while ((rtn = br.readLine()) != null)\r
+ {\r
+ arl.add(rtn);\r
+ }\r
+ return arl.toArray(new String[arl.size()]);\r
}\r
+ } catch (OutOfMemoryError er)\r
+ {\r
\r
- try\r
- {\r
- return (String[]) call.invoke(new Object[]\r
- { ids.toLowerCase(), db.toLowerCase(), format, style });\r
- } catch (OutOfMemoryError er)\r
- {\r
-\r
- System.out.println("OUT OF MEMORY DOWNLOADING QUERY FROM " + db\r
- + ":\n" + ids);\r
- throw er;\r
- }\r
- // return null;\r
+ System.out.println("OUT OF MEMORY DOWNLOADING QUERY FROM " + db\r
+ + ":\n" + ids);\r
+ throw er;\r
} catch (Exception ex)\r
{\r
if (ex.getMessage().startsWith(\r
+ "\nQuery was : '" + ids + "'");\r
ex.printStackTrace(System.err);\r
return null;\r
+ } finally\r
+ {\r
+ //System.err.println("Took " + (System.currentTimeMillis() - time)\r
+ // / 1000 + " secs for one call.");\r
}\r
+ return null;\r
}\r
}\r