From: <hs...@us...> - 2011-11-28 15:43:26
|
Revision: 989 http://treebase.svn.sourceforge.net/treebase/?rev=989&view=rev Author: hshyket Date: 2011-11-28 15:43:15 +0000 (Mon, 28 Nov 2011) Log Message: ----------- Adding a read timeout when uBio takes too long to respond Modified Paths: -------------- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/taxon/TaxonLabelService.java trunk/treebase-core/src/main/java/org/cipres/treebase/service/taxon/TaxonLabelServiceImpl.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/ListTaxaController.java Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/taxon/TaxonLabelService.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/taxon/TaxonLabelService.java 2011-11-23 21:43:54 UTC (rev 988) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/taxon/TaxonLabelService.java 2011-11-28 15:43:15 UTC (rev 989) @@ -372,4 +372,6 @@ */ Set<TaxonVariant> findTaxonVariantByName(String s); + boolean getuBioTimeOutError(); + } Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/service/taxon/TaxonLabelServiceImpl.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/service/taxon/TaxonLabelServiceImpl.java 2011-11-23 21:43:54 UTC (rev 988) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/service/taxon/TaxonLabelServiceImpl.java 2011-11-28 15:43:15 UTC (rev 989) @@ -6,6 +6,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.InterruptedIOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; @@ -52,18 +53,22 @@ private static final String NMBKID = "namebankID"; private static final String NAMESTR = "nameString"; private static final int TIMEOUT = 10000; + private static final int READTIMEOUT = 30000; private static final String VALUETAG = "value"; private static final String DETAILSSERVICEURLPART = "http://www.ubio.org/browser/details.php?namebankID="; private TaxonLabelHome mTaxonLabelHome; private PhyloTreeHome mPhyloTreeHome; private TaxonHome mTaxonHome; + + private boolean muBioTimeOutError; /** * constructor. */ public TaxonLabelServiceImpl() { super(); + setuBioTimeOutError(false); } /** @@ -459,7 +464,7 @@ booleanplaceholder bph = new booleanplaceholder(); longplaceholder lph = new longplaceholder(); TaxonVariant firstVariant = null; - + // XXX 1. Turn label into tri- or binomial, no var./ex./etc. testString = normalizeLabelString(pTaxonLabel.getTaxonLabel()); @@ -468,6 +473,9 @@ String result = getStringFromURL(taxonFinderFullURL, null, null); // XXX 3. Process TaxonFinder result + if (getuBioTimeOutError()) { + return null; + } if (result == null || result.indexOf(NMBKID) < 0 || result.indexOf(testString) < 0 || result.indexOf(NAMESTR) < 0) { LOGGER.warn("Problem: uBio result is garbled or doesn't contain our testString"); return null; @@ -755,6 +763,7 @@ URL url = new URL(urlString); URLConnection urlconn = url.openConnection(); urlconn.setConnectTimeout(TIMEOUT); + urlconn.setReadTimeout(READTIMEOUT); BufferedReader in = new BufferedReader(new InputStreamReader(urlconn.getInputStream())); StringBuilder results = new StringBuilder(); String str; @@ -780,7 +789,11 @@ return results.toString(); } catch (MalformedURLException mfe) { mfe.printStackTrace(); - } catch (IOException ioe) { + } catch (InterruptedIOException iioe) { + iioe.printStackTrace(); + setuBioTimeOutError(true); + } + catch (IOException ioe) { ioe.printStackTrace(); } return null; @@ -808,6 +821,14 @@ } return result.substring(start + 1, end); } + + public boolean getuBioTimeOutError() { + return muBioTimeOutError; + } + + public void setuBioTimeOutError(Boolean pTimeOutError) { + muBioTimeOutError = pTimeOutError; + } /** * @return the taxonHome @@ -1019,5 +1040,5 @@ @Override public Class defaultResultClass() { return TaxonLabel.class; - } + } } Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/ListTaxaController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/ListTaxaController.java 2011-11-23 21:43:54 UTC (rev 988) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/ListTaxaController.java 2011-11-28 15:43:15 UTC (rev 989) @@ -148,11 +148,20 @@ // no variants were found by uBio if ( variant == null ) { - ubioResultMessages.add(taxonlabel.getTaxonLabel() + " is **UNRECOGNIZED**."); - ubioResultErrors.add(taxonlabel.getTaxonLabel() - + " is **UNRECOGNIZED** try <a href=" + UBIOSEARCHTAXONLABEL - + taxonlabel.getTaxonLabel().replace(EMPTYSPACE, "%20") - + " target=_blank>UBIO</a> site."); + if (getTaxonLabelService().getuBioTimeOutError()) { + ubioResultMessages.add("uBio service was unavailable when checking " + taxonlabel.getTaxonLabel() + "."); + ubioResultErrors.add("uBio service was unavailable when checking " + taxonlabel.getTaxonLabel() + + " try <a href=" + UBIOSEARCHTAXONLABEL + + taxonlabel.getTaxonLabel().replace(EMPTYSPACE, "%20") + + " target=_blank>UBIO</a> site."); + } + else { + ubioResultMessages.add(taxonlabel.getTaxonLabel() + " is **UNRECOGNIZED**."); + ubioResultErrors.add(taxonlabel.getTaxonLabel() + + " is **UNRECOGNIZED** try <a href=" + UBIOSEARCHTAXONLABEL + + taxonlabel.getTaxonLabel().replace(EMPTYSPACE, "%20") + + " target=_blank>UBIO</a> site."); + } } // variants stored by uBio,TODO now check for homonyms This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |