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;
* @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
*/
File outFile = null;
try
{
- outFile = File.createTempFile("jalview", ext);
+ outFile = File.createTempFile("jalview", "." + ext);
outFile.deleteOnExit();
fetchData(ids, format, outFile);
if (outFile.length() == 0)
}
// 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);
}
{
URL rcall = new URL(url);
- InputStream is = new BufferedInputStream(rcall.openStream());
+ HttpURLConnection conn = (HttpURLConnection) rcall.openConnection();
+ int responseCode = conn.getResponseCode();
+ if (responseCode != 200)
+ {
+ System.out.println("Warning: response code " + responseCode
+ + " for " + url);
+ }
+ InputStream is = new BufferedInputStream(conn.getInputStream());
if (outFile != null)
{
FileOutputStream fio = new FileOutputStream(outFile);
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
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 : "");
}