JAL-4409 Don't insist on HttpURLConnection, allows for file:/ protocol connection
authorBen Soares <b.soares@dundee.ac.uk>
Tue, 28 May 2024 12:03:31 +0000 (13:03 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Tue, 28 May 2024 12:03:31 +0000 (13:03 +0100)
src/jalview/analytics/Plausible.java
src/jalview/ext/ensembl/EnsemblRestClient.java
src/jalview/ext/pymol/PymolManager.java
src/jalview/util/HttpUtils.java
src/jalview/ws/dbsources/Uniprot.java
src/jalview/ws/ebi/EBIFetchClient.java
test/jalview/util/HttpUtilsTest.java

index 2852734..bff0448 100644 (file)
@@ -213,7 +213,8 @@ public class Plausible
     try
     {
       URL url = new URL(urlSb.toString());
-      HttpURLConnection httpURLConnection = HttpUtils.openConnection(url);
+      HttpURLConnection httpURLConnection = (HttpURLConnection) HttpUtils
+              .openConnection(url);
       httpURLConnection.setRequestMethod("POST");
       httpURLConnection.setDoOutput(true);
 
@@ -552,7 +553,8 @@ public class Plausible
     try
     {
       URL url = new URL(CONFIG_API_BASE_URL);
-      HttpURLConnection httpURLConnection = HttpUtils.openConnection(url);
+      HttpURLConnection httpURLConnection = (HttpURLConnection) HttpUtils
+              .openConnection(url);
       httpURLConnection.setRequestMethod("GET");
       httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
       httpURLConnection.setConnectTimeout(5000);
index f7651be..3cc778a 100644 (file)
@@ -343,7 +343,8 @@ abstract class EnsemblRestClient extends EnsemblSequenceFetcher
   {
     // jalview.bin.Console.outPrintln(System.currentTimeMillis() + " " + url);
 
-    HttpURLConnection connection = HttpUtils.openConnection(url);
+    HttpURLConnection connection = (HttpURLConnection) HttpUtils
+            .openConnection(url);
 
     /*
      * POST method allows multiple queries in one request; it is supported for
index 05c5053..80327b8 100644 (file)
@@ -168,7 +168,8 @@ public class PymolManager
     try
     {
       URL realUrl = new URL(rpcUrl);
-      HttpURLConnection conn = HttpUtils.openConnection(realUrl);
+      HttpURLConnection conn = (HttpURLConnection) HttpUtils
+              .openConnection(realUrl);
       conn.setRequestProperty("accept", "*/*");
       conn.setRequestProperty("content-type", "text/xml");
       conn.setDoOutput(true);
index 04a820d..d6e4c14 100644 (file)
@@ -28,6 +28,7 @@ import java.net.ProtocolException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.net.URLConnection;
 
 public class HttpUtils
 {
@@ -149,13 +150,13 @@ public class HttpUtils
    *          url
    * @return HttpUrlConnection conn
    */
-  public static HttpURLConnection openConnection(URL url) throws IOException
+  public static URLConnection openConnection(URL url) throws IOException
   {
     if (url == null)
     {
       return null;
     }
-    HttpURLConnection conn = null;
+    URLConnection conn = null;
     String protocol = url.getProtocol();
     if ("http".equals(protocol) || "https".equals(protocol))
     {
@@ -169,6 +170,10 @@ public class HttpUtils
         conn = conn0;
       }
     }
+    else
+    {
+      conn = url.openConnection();
+    }
     return conn;
   }
 
index b493611..89c92d4 100644 (file)
@@ -149,7 +149,8 @@ public class Uniprot extends DbSourceProxyImpl
               + ".xml";
 
       URL url = new URL(downloadstring);
-      HttpURLConnection urlconn = HttpUtils.openConnection(url);
+      HttpURLConnection urlconn = (HttpURLConnection) HttpUtils
+              .openConnection(url);
       // anything other than 200 means we don't have data
       // TODO: JAL-3882 reuse the EnsemblRestClient's fair
       // use/backoff logic to retry when the server tells us to go away
index 87526a1..5a5e9ae 100644 (file)
@@ -210,7 +210,8 @@ public class EBIFetchClient
     try
     {
       URL rcall = new URL(url);
-      HttpURLConnection conn = HttpUtils.openConnection(rcall);
+      HttpURLConnection conn = (HttpURLConnection) HttpUtils
+              .openConnection(rcall);
       int responseCode = conn.getResponseCode();
       if (responseCode == 200)
       {
index fbd8149..d8b757d 100644 (file)
@@ -32,7 +32,8 @@ public class HttpUtilsTest
   {
     URL tUrl = new URL(targetUrl);
     URL fUrl = new URL(finalUrl);
-    HttpURLConnection conn1 = HttpUtils.openConnection(tUrl);
+    HttpURLConnection conn1 = (HttpURLConnection) HttpUtils
+            .openConnection(tUrl);
     URL url1 = conn1.getURL();
     Assert.assertEquals(url1, fUrl, "Final URL is not the same.");
   }