*
* @return
*/
- public abstract boolean useGetRequest();
+ protected abstract boolean useGetRequest();
/**
* Return the desired value for the Content-Type request header
*
+ * @param multipleIds
+ *
* @return
* @see https://github.com/Ensembl/ensembl-rest/wiki/HTTP-Headers
*/
- public abstract String getRequestMimeType();
+ protected abstract String getRequestMimeType(boolean multipleIds);
/**
* Return the desired value for the Accept request header
* @return
* @see https://github.com/Ensembl/ensembl-rest/wiki/HTTP-Headers
*/
- public abstract String getResponseMimeType();
+ protected abstract String getResponseMimeType();
/**
* Tries to connect to Ensembl's REST 'ping' endpoint, and returns true if
* @return
* @throws IOException
*/
- public FileParse getSequenceReader(List<String> ids)
+ protected FileParse getSequenceReader(List<String> ids)
throws IOException
{
URL url = getUrl(ids);
* POST method allows multiple queries in one request; it is supported for
* sequence queries, but not for overlap
*/
- connection.setRequestMethod(useGetRequest() ? HttpMethod.GET
- : HttpMethod.POST);
- connection.setRequestProperty("Content-Type", getRequestMimeType());
+ boolean multipleIds = ids.size() > 1;// useGetRequest();
+ connection.setRequestMethod(multipleIds ? HttpMethod.POST
+ : HttpMethod.GET);
+ connection.setRequestProperty("Content-Type",
+ getRequestMimeType(multipleIds));
connection.setRequestProperty("Accept", getResponseMimeType());
connection.setUseCaches(false);
connection.setDoInput(true);
- connection.setDoOutput(true);
+ connection.setDoOutput(multipleIds);
- if (!useGetRequest())
+ if (multipleIds)
{
writePostBody(connection, ids);
}
if (responseCode != 200)
{
+ /*
+ * note: a GET request for an invalid id returns an error code e.g. 415
+ * but POST request returns 200 and an empty Fasta response
+ */
throw new RuntimeException(
"Response code was not 200. Detected response was "
+ responseCode);
*
* @return
*/
- public boolean isEnsemblAvailable()
+ protected boolean isEnsemblAvailable()
{
long now = System.currentTimeMillis();
boolean retest = now - lastCheck > RETEST_INTERVAL;