package jalview.ext.ensembl;
+import jalview.io.DataSourceType;
import jalview.io.FileParse;
import jalview.util.StringUtils;
* changes to Ensembl REST API
* @see https://github.com/Ensembl/ensembl-rest/wiki/Change-log
*/
- private static final String LATEST_ENSEMBLGENOMES_REST_VERSION = "4.4";
+ private static final String LATEST_ENSEMBLGENOMES_REST_VERSION = "4.6";
- private static final String LATEST_ENSEMBL_REST_VERSION = "4.5";
+ private static final String LATEST_ENSEMBL_REST_VERSION = "4.6";
+
+ private static final String REST_CHANGE_LOG = "https://github.com/Ensembl/ensembl-rest/wiki/Change-log";
private static Map<String, EnsemblInfo> domainData;
protected abstract String getResponseMimeType();
/**
- * Tries to connect to Ensembl's REST 'ping' endpoint, and returns true if
- * successful, else false
+ * Checks Ensembl's REST 'ping' endpoint, and returns true if response
+ * indicates available, else false
*
+ * @see http://rest.ensembl.org/documentation/info/ping
* @return
*/
private boolean checkEnsembl()
{
+ HttpURLConnection conn = null;
try
{
// note this format works for both ensembl and ensemblgenomes
// info/ping.json works for ensembl only (March 2016)
URL ping = new URL(getDomain()
+ "/info/ping?content-type=application/json");
- HttpURLConnection conn = (HttpURLConnection) ping.openConnection();
- int rc = conn.getResponseCode();
- conn.disconnect();
- if (rc >= 200 && rc < 300)
- {
- return true;
- }
+
+ /*
+ * expect {"ping":1} if ok
+ */
+ BufferedReader br = getHttpResponse(ping, null);
+ JSONParser jp = new JSONParser();
+ JSONObject val = (JSONObject) jp.parse(br);
+ String pingString = val.get("ping").toString();
+ return pingString != null;
} catch (Throwable t)
{
System.err.println("Error connecting to " + PING_URL + ": "
+ t.getMessage());
+ } finally
+ {
+ if (conn != null)
+ {
+ conn.disconnect();
+ }
}
return false;
}
URL url = getUrl(ids);
BufferedReader reader = getHttpResponse(url, ids);
- FileParse fp = new FileParse(reader, url.toString(), "HTTP_POST");
+ FileParse fp = new FileParse(reader, url.toString(), DataSourceType.URL);
return fp;
}
if (laterVersion)
{
System.err.println(String.format(
- "Expected %s REST version %s but found %s", getDbSource(),
- expected,
- version));
+ "Expected %s REST version %s but found %s, see %s",
+ getDbSource(), expected, version, REST_CHANGE_LOG));
}
info.restVersion = version;
} catch (Throwable t)