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;
}