X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fdbsources%2FUniprot.java;h=077587009be133e9c84b928121a47184a1e26110;hb=49db0dff1da16c3355b43a41498c1fc93ef47e91;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..0775870 100644 --- a/src/jalview/ws/dbsources/Uniprot.java +++ b/src/jalview/ws/dbsources/Uniprot.java @@ -20,6 +20,7 @@ */ package jalview.ws.dbsources; +import java.util.Locale; import jalview.bin.Cache; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; @@ -32,7 +33,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 +41,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; @@ -70,6 +70,7 @@ public class Uniprot extends DbSourceProxyImpl private static final String DEFAULT_UNIPROT_DOMAIN = "https://www.uniprot.org"; private static final String BAR_DELIMITER = "|"; + private static Regex ACCESSION_REGEX; /** * Constructor @@ -103,7 +104,12 @@ public class Uniprot extends DbSourceProxyImpl @Override public Regex getAccessionValidator() { - return new Regex("([A-Z]+[0-9]+[A-Z0-9]+|[A-Z0-9]+_[A-Z0-9]+)"); + if (ACCESSION_REGEX == null) + { + ACCESSION_REGEX = Platform + .newRegex("([A-Z]+[0-9]+[A-Z0-9]+|[A-Z0-9]+_[A-Z0-9]+)"); + } + return ACCESSION_REGEX; } /* @@ -139,7 +145,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,10 +153,11 @@ 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) @@ -162,6 +169,7 @@ public class Uniprot extends DbSourceProxyImpl stopQuery(); return al; + } catch (Exception e) { throw (e); @@ -516,6 +524,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;