+ * @param url
+ * @param ids
+ * @param readTimeout
+ * @return
+ * @throws IOException
+ * @throws ProtocolException
+ */
+ protected HttpURLConnection tryConnection(URL url, List<String> ids,
+ int readTimeout) throws IOException, ProtocolException
+ {
+ // System.out.println(System.currentTimeMillis() + " " + url);
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+
+ /*
+ * POST method allows multiple queries in one request; it is supported for
+ * sequence queries, but not for overlap
+ */
+ boolean multipleIds = ids != null && ids.size() > 1;
+ connection.setRequestMethod(
+ multipleIds ? HttpMethod.POST : HttpMethod.GET);
+ connection.setRequestProperty("Content-Type", getRequestMimeType());
+ connection.setRequestProperty("Accept", getResponseMimeType());
+
+ connection.setUseCaches(false);
+ connection.setDoInput(true);
+ connection.setDoOutput(multipleIds);
+
+ connection.setConnectTimeout(CONNECT_TIMEOUT_MS);
+ connection.setReadTimeout(readTimeout);
+
+ if (multipleIds)
+ {
+ writePostBody(connection, ids);
+ }
+ return connection;
+ }
+
+ /**
+ * Inspects response headers for a 'retry-after' directive, and waits for the
+ * directed period (if less than 10 seconds)