X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fdbsources%2FUniprot.java;h=b9fe52f607fa5d970405292dcb40478d3821d537;hb=1724567f3dfc3b4637aac7bdeb6633628e6a8335;hp=2fc5893fffbacea828e4ca21204a144331c3ed7c;hpb=d0d660cab06c31659e7bb0a1780317b3d2231eb6;p=jalview.git diff --git a/src/jalview/ws/dbsources/Uniprot.java b/src/jalview/ws/dbsources/Uniprot.java index 2fc5893..b9fe52f 100644 --- a/src/jalview/ws/dbsources/Uniprot.java +++ b/src/jalview/ws/dbsources/Uniprot.java @@ -20,6 +20,8 @@ */ package jalview.ws.dbsources; +import java.util.Locale; + import jalview.bin.Cache; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; @@ -32,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; @@ -41,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; @@ -139,7 +140,7 @@ public class Uniprot extends DbSourceProxyImpl startQuery(); try { - queries = queries.toUpperCase().replaceAll( + queries = queries.toUpperCase(Locale.ROOT).replaceAll( "(UNIPROT\\|?|UNIPROT_|UNIREF\\d+_|UNIREF\\d+\\|?)", ""); AlignmentI al = null; @@ -147,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); @@ -516,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;