X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Febi%2FEBIFetchClient.java;h=07a9df4b5cff7ecd6e8866fafd2b38b393ab863f;hb=bcf549d4fb4c4b6fc31a7b9e70b324578df3c666;hp=55315129a27d14fa837380abac4c715f8f4b0edb;hpb=30b2b47cbdfa35b127b0fb09e911815cddd9ed7b;p=jalview.git diff --git a/src/jalview/ws/ebi/EBIFetchClient.java b/src/jalview/ws/ebi/EBIFetchClient.java index 5531512..07a9df4 100644 --- a/src/jalview/ws/ebi/EBIFetchClient.java +++ b/src/jalview/ws/ebi/EBIFetchClient.java @@ -29,6 +29,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.io.InputStreamReader; +import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; import java.util.List; @@ -91,7 +92,7 @@ public class EBIFetchClient * @param format * the format wanted * @param extension - * for the temporary file to hold response + * for the temporary file to hold response (without separator) * @return the file holding the response * @throws OutOfMemoryError */ @@ -102,7 +103,7 @@ public class EBIFetchClient File outFile = null; try { - outFile = File.createTempFile("jalview", ext); + outFile = File.createTempFile("jalview", "." + ext); outFile.deleteOnExit(); fetchData(ids, format, outFile); if (outFile.length() == 0) @@ -139,7 +140,8 @@ public class EBIFetchClient } // note: outFile is currently always specified, so return value is null - String[] rslt = fetchBatch(querystring.toString(), database, format, outFile); + String[] rslt = fetchBatch(querystring.toString(), database, format, + outFile); return (rslt != null && rslt.length > 0 ? rslt : null); } @@ -204,11 +206,17 @@ public class EBIFetchClient { URL rcall = new URL(url); - InputStream is = new BufferedInputStream(rcall.openStream()); + HttpURLConnection conn = (HttpURLConnection) rcall.openConnection(); + int responseCode = conn.getResponseCode(); + if (responseCode != 200) + { + System.err.println("Warning: response code " + responseCode + + " for " + url); + } + InputStream is = new BufferedInputStream(conn.getInputStream()); if (outFile != null) { FileOutputStream fio = new FileOutputStream(outFile); - // fio.write("\n".getBytes()); byte[] bb = new byte[32 * 1024]; int l; while ((l = is.read(bb)) > 0) @@ -242,8 +250,7 @@ public class EBIFetchClient return null; } System.err.println("Unexpected exception when retrieving from " - + database - + "\nQuery was : '" + ids + "'"); + + database + "\nQuery was : '" + ids + "'"); ex.printStackTrace(System.err); return null; } finally @@ -268,12 +275,12 @@ public class EBIFetchClient if (database.equalsIgnoreCase(DBRefSource.EMBL) || database.equalsIgnoreCase(DBRefSource.EMBLCDS)) { - url = "http://www.ebi.ac.uk/ena/data/view/" + ids.toLowerCase() + url = "https://www.ebi.ac.uk/ena/data/view/" + ids.toLowerCase() + (format != null ? "&" + format : ""); } else { - url = "http://www.ebi.ac.uk/Tools/dbfetch/dbfetch/" + url = "https://www.ebi.ac.uk/Tools/dbfetch/dbfetch/" + database.toLowerCase() + "/" + ids.toLowerCase() + (format != null ? "/" + format : ""); }