From d80fbc33dfc7ece325c896b33c3296a075e48a30 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Wed, 29 Sep 2021 15:50:09 +0100 Subject: [PATCH] =?utf8?q?JAL-3884=20squish=20alarming=20but=20harmless=20er?= =?utf8?q?rors=20when=20uniprot=20doesn=E2=80=99t=20have=20a=20record?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/jalview/ws/dbsources/Uniprot.java | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/jalview/ws/dbsources/Uniprot.java b/src/jalview/ws/dbsources/Uniprot.java index a80a530..b9fe52f 100644 --- a/src/jalview/ws/dbsources/Uniprot.java +++ b/src/jalview/ws/dbsources/Uniprot.java @@ -34,7 +34,6 @@ import jalview.datamodel.SequenceI; import jalview.schemes.ResidueProperties; 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; @@ -43,8 +42,8 @@ import jalview.xml.binding.uniprot.PositionType; import jalview.xml.binding.uniprot.PropertyType; import java.io.InputStream; +import java.net.HttpURLConnection; import java.net.URL; -import java.net.URLConnection; import java.util.ArrayList; import java.util.List; import java.util.Vector; @@ -149,21 +148,27 @@ public class Uniprot extends DbSourceProxyImpl + ".xml"; URL url = new URL(downloadstring); - URLConnection urlconn = url.openConnection(); - InputStream istr = urlconn.getInputStream(); - List entries = getUniprotEntries(istr); - if (entries != null) + HttpURLConnection urlconn = (HttpURLConnection)url.openConnection(); + // 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 + if (urlconn.getResponseCode() == 200) { - List seqs = new ArrayList<>(); - for (Entry entry : entries) + InputStream istr = urlconn.getInputStream(); + List entries = getUniprotEntries(istr); + if (entries != null) { - seqs.add(uniprotEntryToSequence(entry)); + List seqs = new ArrayList<>(); + for (Entry entry : entries) + { + seqs.add(uniprotEntryToSequence(entry)); + } + al = new Alignment(seqs.toArray(new SequenceI[seqs.size()])); } - al = new Alignment(seqs.toArray(new SequenceI[seqs.size()])); } - stopQuery(); return al; + } catch (Exception e) { throw (e); @@ -518,6 +523,11 @@ public class Uniprot extends DbSourceProxyImpl } catch (JAXBException | XMLStreamException | FactoryConfigurationError e) { + if (e instanceof javax.xml.bind.UnmarshalException && e.getCause()!=null && e.getCause() instanceof XMLStreamException && e.getCause().getMessage().contains("[row,col]:[1,1]")) + { + // trying to parse an empty stream + return null; + } e.printStackTrace(); } return entries; -- 1.7.10.2