From: Ben Soares Date: Tue, 21 May 2024 16:56:44 +0000 (+0100) Subject: JAL-1054 Change the rest of the url.openConnection() calls to use the HttpUtils.openC... X-Git-Tag: Release_2_11_4_0~28^2~11 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=15ef12b14eaff00fefc93030ae8e28a02e7a8a58;p=jalview.git JAL-1054 Change the rest of the url.openConnection() calls to use the HttpUtils.openConnection(url) wrapper --- diff --git a/src/jalview/analytics/Plausible.java b/src/jalview/analytics/Plausible.java index 544fb05..2852734 100644 --- a/src/jalview/analytics/Plausible.java +++ b/src/jalview/analytics/Plausible.java @@ -29,7 +29,6 @@ import java.lang.invoke.MethodHandles; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; -import java.net.URLConnection; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.AbstractMap; @@ -44,6 +43,7 @@ import java.util.Random; import jalview.bin.Cache; import jalview.bin.Console; import jalview.util.ChannelProperties; +import jalview.util.HttpUtils; import jalview.util.UserAgent; public class Plausible @@ -213,8 +213,7 @@ public class Plausible try { URL url = new URL(urlSb.toString()); - URLConnection urlConnection = url.openConnection(); - HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection; + HttpURLConnection httpURLConnection = HttpUtils.openConnection(url); httpURLConnection.setRequestMethod("POST"); httpURLConnection.setDoOutput(true); @@ -553,8 +552,7 @@ public class Plausible try { URL url = new URL(CONFIG_API_BASE_URL); - URLConnection urlConnection = url.openConnection(); - HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection; + HttpURLConnection httpURLConnection = HttpUtils.openConnection(url); httpURLConnection.setRequestMethod("GET"); httpURLConnection.setRequestProperty("User-Agent", USER_AGENT); httpURLConnection.setConnectTimeout(5000); diff --git a/src/jalview/ext/ensembl/EnsemblRestClient.java b/src/jalview/ext/ensembl/EnsemblRestClient.java index 709136c..f7651be 100644 --- a/src/jalview/ext/ensembl/EnsemblRestClient.java +++ b/src/jalview/ext/ensembl/EnsemblRestClient.java @@ -36,6 +36,7 @@ import javax.ws.rs.HttpMethod; import org.json.simple.parser.ParseException; +import jalview.util.HttpUtils; import jalview.util.Platform; import jalview.util.StringUtils; @@ -342,7 +343,7 @@ abstract class EnsemblRestClient extends EnsemblSequenceFetcher { // jalview.bin.Console.outPrintln(System.currentTimeMillis() + " " + url); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + HttpURLConnection connection = HttpUtils.openConnection(url); /* * POST method allows multiple queries in one request; it is supported for diff --git a/src/jalview/ext/pymol/PymolManager.java b/src/jalview/ext/pymol/PymolManager.java index ddc8d84..05c5053 100644 --- a/src/jalview/ext/pymol/PymolManager.java +++ b/src/jalview/ext/pymol/PymolManager.java @@ -38,6 +38,7 @@ import jalview.bin.Cache; import jalview.bin.Console; import jalview.gui.Preferences; import jalview.structure.StructureCommandI; +import jalview.util.HttpUtils; import jalview.util.Platform; public class PymolManager @@ -167,7 +168,7 @@ public class PymolManager try { URL realUrl = new URL(rpcUrl); - HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection(); + HttpURLConnection conn = HttpUtils.openConnection(realUrl); conn.setRequestProperty("accept", "*/*"); conn.setRequestProperty("content-type", "text/xml"); conn.setDoOutput(true); diff --git a/src/jalview/io/FileParse.java b/src/jalview/io/FileParse.java index fd12dc6..57b2ce5 100755 --- a/src/jalview/io/FileParse.java +++ b/src/jalview/io/FileParse.java @@ -316,7 +316,7 @@ public class FileParse { errormessage = "URL NOT FOUND"; URL url = new URL(urlStr); - URLConnection _conn = url.openConnection(); + URLConnection _conn = HttpUtils.openConnection(url); if (_conn instanceof HttpURLConnection) { HttpURLConnection conn = HttpUtils diff --git a/src/jalview/ws/dbsources/TDBeacons.java b/src/jalview/ws/dbsources/TDBeacons.java index 7326c6e..8a27ad9 100644 --- a/src/jalview/ws/dbsources/TDBeacons.java +++ b/src/jalview/ws/dbsources/TDBeacons.java @@ -20,7 +20,23 @@ */ package jalview.ws.dbsources; +import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.List; import java.util.Locale; +import java.util.Vector; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.stream.FactoryConfigurationError; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import com.stevesoft.pat.Regex; import jalview.bin.Cache; import jalview.datamodel.Alignment; @@ -32,9 +48,9 @@ import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.schemes.ResidueProperties; +import jalview.util.HttpUtils; import jalview.util.StringUtils; import jalview.ws.seqfetcher.DbSourceProxyImpl; -import jalview.xml.binding.embl.ROOT; import jalview.xml.binding.uniprot.DbReferenceType; import jalview.xml.binding.uniprot.Entry; import jalview.xml.binding.uniprot.FeatureType; @@ -42,23 +58,6 @@ import jalview.xml.binding.uniprot.LocationType; import jalview.xml.binding.uniprot.PositionType; import jalview.xml.binding.uniprot.PropertyType; -import java.io.InputStream; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; -import java.util.List; -import java.util.Vector; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBElement; -import javax.xml.bind.JAXBException; -import javax.xml.stream.FactoryConfigurationError; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import com.stevesoft.pat.Regex; - /** * This class queries the Uniprot database for sequence data, unmarshals the * returned XML, and converts it to Jalview Sequence records (including attached @@ -152,7 +151,7 @@ public class TDBeacons extends DbSourceProxyImpl // String downloadstring = getDomain() + queries + ".json"; URL url = new URL(downloadstring); - URLConnection urlconn = url.openConnection(); + URLConnection urlconn = HttpUtils.openConnection(url); InputStream istr = urlconn.getInputStream(); List entries = getUniprotEntries(istr); if (entries != null) diff --git a/src/jalview/ws/dbsources/Uniprot.java b/src/jalview/ws/dbsources/Uniprot.java index 299224d..b493611 100644 --- a/src/jalview/ws/dbsources/Uniprot.java +++ b/src/jalview/ws/dbsources/Uniprot.java @@ -49,6 +49,7 @@ import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.schemes.ResidueProperties; +import jalview.util.HttpUtils; import jalview.util.StringUtils; import jalview.ws.seqfetcher.DbSourceProxyImpl; import jalview.xml.binding.uniprot.DbReferenceType; @@ -144,10 +145,11 @@ public class Uniprot extends DbSourceProxyImpl "(UNIPROT\\|?|UNIPROT_|UNIREF\\d+_|UNIREF\\d+\\|?)", ""); AlignmentI al = null; - String downloadstring = getDomain() + "/uniprotkb/" + queries + ".xml"; + String downloadstring = getDomain() + "/uniprotkb/" + queries + + ".xml"; URL url = new URL(downloadstring); - HttpURLConnection urlconn = (HttpURLConnection) url.openConnection(); + HttpURLConnection urlconn = 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 diff --git a/src/jalview/ws/ebi/EBIFetchClient.java b/src/jalview/ws/ebi/EBIFetchClient.java index 8aca9a2..87526a1 100644 --- a/src/jalview/ws/ebi/EBIFetchClient.java +++ b/src/jalview/ws/ebi/EBIFetchClient.java @@ -20,12 +20,6 @@ */ package jalview.ws.ebi; -import java.util.Locale; - -import jalview.datamodel.DBRefSource; -import jalview.util.MessageManager; -import jalview.util.Platform; - import java.io.BufferedReader; import java.io.File; import java.io.IOException; @@ -35,8 +29,14 @@ import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.StringTokenizer; +import jalview.datamodel.DBRefSource; +import jalview.util.HttpUtils; +import jalview.util.MessageManager; +import jalview.util.Platform; + /** * DOCUMENT ME! * @@ -210,7 +210,7 @@ public class EBIFetchClient try { URL rcall = new URL(url); - HttpURLConnection conn = (HttpURLConnection) rcall.openConnection(); + HttpURLConnection conn = HttpUtils.openConnection(rcall); int responseCode = conn.getResponseCode(); if (responseCode == 200) { diff --git a/src/jalview/ws/sifts/SiftsClient.java b/src/jalview/ws/sifts/SiftsClient.java index 58e0b29..cb61ca1 100644 --- a/src/jalview/ws/sifts/SiftsClient.java +++ b/src/jalview/ws/sifts/SiftsClient.java @@ -20,8 +20,6 @@ */ package jalview.ws.sifts; -import java.util.Locale; - import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -41,6 +39,7 @@ import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.TreeMap; @@ -68,6 +67,7 @@ import jalview.structure.StructureMapping; import jalview.util.Comparison; import jalview.util.DBRefUtils; import jalview.util.Format; +import jalview.util.HttpUtils; import jalview.util.Platform; import jalview.xml.binding.sifts.Entry; import jalview.xml.binding.sifts.Entry.Entity; @@ -335,7 +335,7 @@ public class SiftsClient implements SiftsClientI // siftsFileFTPURL); // long now = System.currentTimeMillis(); URL url = new URL(siftsFileFTPURL); - URLConnection conn = url.openConnection(); + URLConnection conn = HttpUtils.openConnection(url); InputStream inputStream = conn.getInputStream(); FileOutputStream outputStream = new FileOutputStream(downloadTo); byte[] buffer = new byte[BUFFER_SIZE];