From: Jim Procter Date: Wed, 29 Sep 2021 14:50:09 +0000 (+0100) Subject: JAL-3884 squish alarming but harmless errors when uniprot doesn’t have a record X-Git-Tag: Release_2_11_2_0~30^2~4 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=d80fbc33dfc7ece325c896b33c3296a075e48a30;hp=ab61239b20e51f02341b658a0f74a8c8acd904ec;p=jalview.git JAL-3884 squish alarming but harmless errors when uniprot doesn’t have a record --- 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;