Example usage for java.lang NumberFormatException getMessage

List of usage examples for java.lang NumberFormatException getMessage

Introduction

In this page you can find the example usage for java.lang NumberFormatException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.boxupp.dao.ProjectDAOManager.java

public String getProviderForProject(String projectID) {
    String provider = null;/* ww  w.  j a v a 2 s.c om*/
    try {
        Integer providerId = projectProviderMappingDao.queryForEq("projectID", Integer.parseInt(projectID))
                .get(0).getProviderID();
        provider = ProviderDAOManager.getInstance().providerDao.queryForId(providerId).getName();
    } catch (NumberFormatException e) {
        logger.error("Error in finding provider for project :" + e.getMessage());
    } catch (SQLException e) {
        logger.error("Error in sql to finding provider for project :" + e.getMessage());
    }
    return provider;
}

From source file:com.lyncode.xoai.serviceprovider.iterators.SetIterator.java

private void harvest() throws InternalHarvestException, NoRecordsMatchException, BadResumptionTokenException,
        NoSetHierarchyException {// w ww .  ja va  2  s . c  om
    HttpClient httpclient = new DefaultHttpClient();
    String url = makeUrl();
    log.info("Harvesting: " + url);
    HttpGet httpget = new HttpGet(url);
    httpget.addHeader("User-Agent", HarvesterManager.USERAGENT);
    httpget.addHeader("From", HarvesterManager.FROM);

    HttpResponse response = null;

    if (this.proxyIp != null && this.proxyPort > -1) {
        HttpHost proxy = new HttpHost(this.proxyIp, this.proxyPort);
        httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }

    try {
        response = httpclient.execute(httpget);
        StatusLine status = response.getStatusLine();

        log.debug(response.getStatusLine());

        if (status.getStatusCode() == 503) // 503 Status (must wait)
        {
            org.apache.http.Header[] headers = response.getAllHeaders();
            for (org.apache.http.Header h : headers) {
                if (h.getName().equals("Retry-After")) {
                    String retry_time = h.getValue();
                    try {
                        Thread.sleep(Integer.parseInt(retry_time) * 1000);
                    } catch (NumberFormatException e) {
                        log.warn("Cannot parse " + retry_time + " to Integer", e);
                    } catch (InterruptedException e) {
                        log.debug(e.getMessage(), e);
                    }
                    httpclient.getConnectionManager().shutdown();
                    httpclient = new DefaultHttpClient();
                    response = httpclient.execute(httpget);
                }
            }
        }

        HttpEntity entity = response.getEntity();
        InputStream instream = entity.getContent();

        Document doc = XMLUtils.parseDocument(instream);

        XMLUtils.checkListSets(doc);

        NodeList listSets = doc.getElementsByTagName("set");
        for (int i = 0; i < listSets.getLength(); i++)
            _queue.add(XMLUtils.getSet(listSets.item(i)));

        resumption = XMLUtils.getText(doc.getElementsByTagName("resumptionToken"));
        log.debug("RESUMPTION: " + resumption);
    } catch (IOException e) {
        throw new InternalHarvestException(e);
    } catch (ParserConfigurationException e) {
        throw new InternalHarvestException(e);
    } catch (SAXException e) {
        throw new InternalHarvestException(e);
    }

}

From source file:com.lyncode.xoai.serviceprovider.iterators.RecordIterator.java

private void harvest() throws NoRecordsMatchException, BadResumptionTokenException,
        CannotDisseminateFormatException, NoSetHierarchyException, InternalHarvestException {
    HttpClient httpclient = new DefaultHttpClient();
    String url = makeUrl();//from   w ww.j  a  va  2s  .  co  m
    log.info("Harvesting: " + url);
    HttpGet httpget = new HttpGet(url);
    httpget.addHeader("User-Agent", HarvesterManager.USERAGENT);
    httpget.addHeader("From", HarvesterManager.FROM);

    HttpResponse response = null;

    if (this.proxyIp != null && this.proxyPort > -1) {
        HttpHost proxy = new HttpHost(this.proxyIp, this.proxyPort);
        httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }

    try {
        response = httpclient.execute(httpget);
        StatusLine status = response.getStatusLine();

        log.debug(response.getStatusLine());

        if (status.getStatusCode() == 503) // 503 Status (must wait)
        {
            org.apache.http.Header[] headers = response.getAllHeaders();
            for (org.apache.http.Header h : headers) {
                if (h.getName().equals("Retry-After")) {
                    String retry_time = h.getValue();
                    try {
                        Thread.sleep(Integer.parseInt(retry_time) * 1000);
                    } catch (NumberFormatException e) {
                        log.warn("Cannot parse " + retry_time + " to Integer", e);
                    } catch (InterruptedException e) {
                        log.debug(e.getMessage(), e);
                    }
                    httpclient.getConnectionManager().shutdown();
                    httpclient = new DefaultHttpClient();
                    response = httpclient.execute(httpget);
                }
            }
        }

        HttpEntity entity = response.getEntity();
        InputStream instream = entity.getContent();

        Document doc = XMLUtils.parseDocument(instream);

        XMLUtils.checkListRecords(doc);

        NodeList listRecords = doc.getElementsByTagName("record");
        for (int i = 0; i < listRecords.getLength(); i++)
            _queue.add(XMLUtils.getRecord(listRecords.item(i)));

        resumption = XMLUtils.getText(doc.getElementsByTagName("resumptionToken"));
        log.debug("RESUMPTION: " + resumption);
    } catch (IOException e) {
        throw new InternalHarvestException(e);
    } catch (ParserConfigurationException e) {
        throw new InternalHarvestException(e);
    } catch (SAXException e) {
        throw new InternalHarvestException(e);
    }

}

From source file:net.orpiske.ssps.common.resource.HttpResourceExchange.java

/**
 * Gets the content length value from the header
 * @param response the HTTP response/* www  .ja  v a 2 s  .c o m*/
 * @return The content length
 */
private long getContentLength(HttpResponse response) {
    Header header = response.getFirstHeader(HttpHeaders.CONTENT_LENGTH);

    String tmp = header.getValue();
    try {
        return Long.parseLong(tmp);
    } catch (NumberFormatException e) {
        logger.warn("The server provided an invalid content length value");

        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
    }

    return 0;
}

From source file:com.lyncode.xoai.serviceprovider.iterators.IdentifierIterator.java

private void harvest() throws InternalHarvestException, NoRecordsMatchException, BadResumptionTokenException,
        CannotDisseminateFormatException, NoSetHierarchyException {
    HttpClient httpclient = new DefaultHttpClient();
    String url = makeUrl();// ww w . java  2s .co  m
    log.info("Harvesting: " + url);
    HttpGet httpget = new HttpGet(url);
    httpget.addHeader("User-Agent", HarvesterManager.USERAGENT);
    httpget.addHeader("From", HarvesterManager.FROM);

    HttpResponse response = null;

    if (this.proxyIp != null && this.proxyPort > -1) {
        HttpHost proxy = new HttpHost(this.proxyIp, this.proxyPort);
        httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }

    try {
        response = httpclient.execute(httpget);
        StatusLine status = response.getStatusLine();

        log.debug(response.getStatusLine());

        if (status.getStatusCode() == 503) // 503 Status (must wait)
        {
            org.apache.http.Header[] headers = response.getAllHeaders();
            for (org.apache.http.Header h : headers) {
                if (h.getName().equals("Retry-After")) {
                    String retry_time = h.getValue();
                    try {
                        Thread.sleep(Integer.parseInt(retry_time) * 1000);
                    } catch (NumberFormatException e) {
                        log.warn("Cannot parse " + retry_time + " to Integer", e);
                    } catch (InterruptedException e) {
                        log.debug(e.getMessage(), e);
                    }
                    httpclient.getConnectionManager().shutdown();
                    httpclient = new DefaultHttpClient();
                    response = httpclient.execute(httpget);
                }
            }
        }

        HttpEntity entity = response.getEntity();
        InputStream instream = entity.getContent();

        Document doc = XMLUtils.parseDocument(instream);

        XMLUtils.checkListIdentifiers(doc);

        NodeList listRecords = doc.getElementsByTagName("header");
        for (int i = 0; i < listRecords.getLength(); i++)
            _queue.add(XMLUtils.getIdentifier(listRecords.item(i)));

        resumption = XMLUtils.getText(doc.getElementsByTagName("resumptionToken"));
        log.debug("RESUMPTION: " + resumption);
    } catch (IOException e) {
        throw new InternalHarvestException(e);
    } catch (ParserConfigurationException e) {
        throw new InternalHarvestException(e);
    } catch (SAXException e) {
        throw new InternalHarvestException(e);
    }

}

From source file:org.openremote.controller.protocol.http.HttpGetCommand.java

private int resolveResultAsInteger(String rawResult) throws ConversionException {
    try {//from   w w w .  j  a  v  a2s  . c  o  m
        BigInteger min = new BigInteger(Integer.toString(Integer.MIN_VALUE));
        BigInteger max = new BigInteger(Integer.toString(Integer.MAX_VALUE));

        BigInteger result = new BigInteger(rawResult);

        if (result.compareTo(min) < 0) {
            return Integer.MIN_VALUE;
        }

        else if (result.compareTo(max) > 0) {
            return Integer.MAX_VALUE;
        }

        else {
            return result.intValue();
        }
    }

    catch (NumberFormatException e) {
        throw new ConversionException("Cannot parse device return value to Java integer: " + e.getMessage(), e);
    }
}

From source file:org.yamj.core.service.plugin.TheTVDbScanner.java

@Override
public ScanResult scan(Series series) {
    String id = getSeriesId(series);

    if (StringUtils.isBlank(id)) {
        return ScanResult.MISSING_ID;
    }/*from  w w w  .j ava2 s.c o  m*/

    com.omertron.thetvdbapi.model.Series tvdbSeries = tvdbApiWrapper.getSeries(id);

    series.setSourceDbId(SCANNER_ID, tvdbSeries.getId());
    series.setSourceDbId(ImdbScanner.SCANNER_ID, tvdbSeries.getImdbId());

    if (OverrideTools.checkOverwriteTitle(series, SCANNER_ID)) {
        series.setTitle(StringUtils.trim(tvdbSeries.getSeriesName()), SCANNER_ID);
    }

    if (OverrideTools.checkOverwritePlot(series, SCANNER_ID)) {
        series.setPlot(StringUtils.trim(tvdbSeries.getOverview()), SCANNER_ID);
    }

    if (OverrideTools.checkOverwriteOutline(series, SCANNER_ID)) {
        series.setOutline(StringUtils.trim(tvdbSeries.getOverview()), SCANNER_ID);
    }

    // Add the genres
    series.setGenreNames(new HashSet<String>(tvdbSeries.getGenres()), SCANNER_ID);

    // TODO more values
    if (StringUtils.isNumeric(tvdbSeries.getRating())) {
        try {
            series.addRating(SCANNER_ID, (int) (Float.parseFloat(tvdbSeries.getRating()) * 10));
        } catch (NumberFormatException nfe) {
            LOG.warn("Failed to convert TVDB rating '{}' to an integer, error: {}", tvdbSeries.getRating(),
                    nfe.getMessage());
        }
    }

    String faDate = tvdbSeries.getFirstAired();
    if (StringUtils.isNotBlank(faDate) && (faDate.length() >= 4)) {
        series.setStartYear(Integer.parseInt(faDate.substring(0, 4)));
    }

    // CAST & CREW
    Set<CreditDTO> actors = new LinkedHashSet<CreditDTO>();
    for (Actor actor : tvdbApiWrapper.getActors(id)) {
        actors.add(new CreditDTO(JobType.ACTOR, actor.getName(), actor.getRole()));
    }

    // SCAN SEASONS
    this.scanSeasons(series, tvdbSeries, actors);

    return ScanResult.OK;
}

From source file:com.collabnet.ccf.core.ga.GenericArtifactHelper.java

public static int getIntMandatoryGAField(String fieldName, GenericArtifact ga) {
    try {//from   w  w  w  .  j  a  v a  2s  . co m
        int fieldValue = 0;
        GenericArtifactField gaField = getMandatoryGAField(fieldName, ga);
        if (gaField != null) {
            Object fieldValueObj = gaField.getFieldValue();
            if (fieldValueObj instanceof String) {
                String fieldValueString = (String) fieldValueObj;
                fieldValue = Integer.parseInt(fieldValueString);
            } else if (fieldValueObj instanceof Integer) {
                fieldValue = ((Integer) fieldValueObj).intValue();
            }
        }
        return fieldValue;
    } catch (NumberFormatException e) {
        // throw new CCFRuntimeException(
        // "Number format exception for mandatory field " + fieldName
        // + ": " + e.getMessage(), e);
        log.warn("No meaningful value set for mandatory field " + fieldName + " assuming default value 0: "
                + e.getMessage());
        return 0;
    }
}

From source file:gov.nih.nci.system.web.struts.action.CreateAction.java

public Object convertValue(Class klass, Object value) throws NumberFormatException, Exception {

    String fieldType = klass.getName();
    if (value == null)
        return null;

    Object convertedValue = null;
    try {/*ww w .j av  a 2 s.c  o  m*/
        if (fieldType.equals("java.lang.Long")) {
            convertedValue = new Long((String) value);
        } else if (fieldType.equals("java.lang.Integer")) {
            convertedValue = new Integer((String) value);
        } else if (fieldType.equals("java.lang.String")) {
            convertedValue = value;
        } else if (fieldType.equals("java.lang.Float")) {
            convertedValue = new Float((String) value);
        } else if (fieldType.equals("java.lang.Double")) {
            convertedValue = new Double((String) value);
        } else if (fieldType.equals("java.lang.Boolean")) {
            convertedValue = new Boolean((String) value);
        } else if (fieldType.equals("java.util.Date")) {
            SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy");
            convertedValue = format.parse((String) value);
        } else if (fieldType.equals("java.net.URI")) {
            convertedValue = new URI((String) value);
        } else if (fieldType.equals("java.lang.Character")) {
            convertedValue = new Character(((String) value).charAt(0));
        } else if (klass.isEnum()) {
            Class enumKlass = Class.forName(fieldType);
            convertedValue = Enum.valueOf(enumKlass, (String) value);
        } else {
            throw new Exception("type mismatch - " + fieldType);
        }

    } catch (NumberFormatException e) {
        e.printStackTrace();
        log.error("ERROR : " + e.getMessage());
        throw e;
    } catch (Exception ex) {
        ex.printStackTrace();
        log.error("ERROR : " + ex.getMessage());
        throw ex;
    }
    return convertedValue;
}

From source file:edu.cornell.mannlib.vitro.webapp.visualization.coauthorship.CoAuthorshipVisCodeGenerator.java

/**
 * This method is used to setup parameters for the sparkline value object. These parameters
 * will be used in the template to construct the actual html/javascript code.
 * @param visMode/* www .j  a  v a 2 s  . com*/
 * @param visContainer
 */
private SparklineData setupSparklineParameters(String visMode, String providedVisContainerID) {

    SparklineData sparklineData = new SparklineData();

    int numOfYearsToBeRendered = 0;

    /*
     * It was decided that to prevent downward curve that happens if there are no publications 
     * in the current year seems a bit harsh, so we consider only publications from the last 10
     * complete years. 
     * */
    int currentYear = Calendar.getInstance().get(Calendar.YEAR) - 1;
    int shortSparkMinYear = currentYear - VisConstants.MINIMUM_YEARS_CONSIDERED_FOR_SPARKLINE + 1;

    /*
     * This is required because when deciding the range of years over which the vis
     * was rendered we dont want to be influenced by the "DEFAULT_PUBLICATION_YEAR".
     * */
    Set<String> publishedYears = new HashSet<String>(yearToUniqueCoauthors.keySet());
    publishedYears.remove(VOConstants.DEFAULT_PUBLICATION_YEAR);

    /*
     * We are setting the default value of minPublishedYear to be 10 years before 
     * the current year (which is suitably represented by the shortSparkMinYear),
     * this in case we run into invalid set of published years.
     * */
    int minPublishedYear = shortSparkMinYear;

    String visContainerID = null;

    if (yearToUniqueCoauthors.size() > 0) {
        try {
            minPublishedYear = Integer.parseInt(Collections.min(publishedYears));
        } catch (NoSuchElementException e1) {
            log.debug("vis: " + e1.getMessage() + " error occurred for " + yearToUniqueCoauthors.toString());
        } catch (NumberFormatException e2) {
            log.debug("vis: " + e2.getMessage() + " error occurred for " + yearToUniqueCoauthors.toString());
        }
    }

    int minPubYearConsidered = 0;

    /*
     * There might be a case that the author has made his first publication within the 
     * last 10 years but we want to make sure that the sparkline is representative of 
     * at least the last 10 years, so we will set the minPubYearConsidered to 
     * "currentYear - 10" which is also given by "shortSparkMinYear".
     * */
    if (minPublishedYear > shortSparkMinYear) {
        minPubYearConsidered = shortSparkMinYear;
    } else {
        minPubYearConsidered = minPublishedYear;
    }

    numOfYearsToBeRendered = currentYear - minPubYearConsidered + 1;

    sparklineData.setNumOfYearsToBeRendered(numOfYearsToBeRendered);

    int uniqueCoAuthorCounter = 0;
    Set<Collaborator> allCoAuthorsWithKnownAuthorshipYears = new HashSet<Collaborator>();
    List<YearToEntityCountDataElement> yearToUniqueCoauthorsCountDataTable = new ArrayList<YearToEntityCountDataElement>();

    for (int publicationYear = minPubYearConsidered; publicationYear <= currentYear; publicationYear++) {

        String publicationYearAsString = String.valueOf(publicationYear);
        Set<Collaborator> currentCoAuthors = yearToUniqueCoauthors.get(publicationYearAsString);

        Integer currentUniqueCoAuthors = null;

        if (currentCoAuthors != null) {
            currentUniqueCoAuthors = currentCoAuthors.size();
            allCoAuthorsWithKnownAuthorshipYears.addAll(currentCoAuthors);
        } else {
            currentUniqueCoAuthors = 0;
        }

        yearToUniqueCoauthorsCountDataTable.add(new YearToEntityCountDataElement(uniqueCoAuthorCounter,
                publicationYearAsString, currentUniqueCoAuthors));
        uniqueCoAuthorCounter++;
    }

    /*
     * For the purpose of this visualization I have come up with a term "Sparks" which 
     * essentially means data points. 
     * Sparks that will be rendered in full mode will always be the one's which have any year
     * associated with it. Hence.
     * */
    sparklineData.setRenderedSparks(allCoAuthorsWithKnownAuthorshipYears.size());

    sparklineData.setYearToEntityCountDataTable(yearToUniqueCoauthorsCountDataTable);

    /*
     * This is required only for the sparklines which convey collaborationships like 
     * coinvestigatorships and coauthorship. There are edge cases where a collaborator can be 
     * present for in a collaboration with known & unknown year. We do not want to repeat the 
     * count for this collaborator when we present it in the front-end. 
     * */
    Set<Collaborator> totalUniqueCoInvestigators = new HashSet<Collaborator>(
            allCoAuthorsWithKnownAuthorshipYears);

    /*
     * Total publications will also consider publications that have no year associated with
     * them. Hence.
     * */
    Integer unknownYearCoauthors = 0;
    if (yearToUniqueCoauthors.get(VOConstants.DEFAULT_PUBLICATION_YEAR) != null) {
        unknownYearCoauthors = yearToUniqueCoauthors.get(VOConstants.DEFAULT_PUBLICATION_YEAR).size();

        totalUniqueCoInvestigators.addAll(yearToUniqueCoauthors.get(VOConstants.DEFAULT_GRANT_YEAR));
    }

    sparklineData.setUnknownYearPublications(unknownYearCoauthors);

    sparklineData.setTotalCollaborationshipCount(totalUniqueCoInvestigators.size());

    if (providedVisContainerID != null) {
        visContainerID = providedVisContainerID;
    } else {
        visContainerID = DEFAULT_VISCONTAINER_DIV_ID;
    }

    sparklineData.setVisContainerDivID(visContainerID);

    /*
     * By default these represents the range of the rendered sparks. Only in case of
     * "short" sparkline mode we will set the Earliest RenderedPublication year to
     * "currentYear - 10". 
     * */
    sparklineData.setEarliestYearConsidered(minPubYearConsidered);
    sparklineData.setEarliestRenderedPublicationYear(minPublishedYear);
    sparklineData.setLatestRenderedPublicationYear(currentYear);

    /*
     * The Full Sparkline will be rendered by default. Only if the url has specific mention of
     * SHORT_SPARKLINE_MODE_KEY then we render the short sparkline and not otherwise.
     * */
    if (VisualizationFrameworkConstants.SHORT_SPARKLINE_VIS_MODE.equalsIgnoreCase(visMode)) {

        sparklineData.setEarliestRenderedPublicationYear(shortSparkMinYear);
        sparklineData.setShortVisMode(true);

    } else {
        sparklineData.setShortVisMode(false);
    }

    if (yearToUniqueCoauthors.size() > 0) {

        sparklineData.setFullTimelineNetworkLink(UtilityFunctions.getCollaboratorshipNetworkLink(individualURI,
                VisualizationFrameworkConstants.PERSON_LEVEL_VIS,
                VisualizationFrameworkConstants.COAUTHOR_VIS_MODE));

        sparklineData.setDownloadDataLink(UtilityFunctions.getCSVDownloadURL(individualURI,
                VisualizationFrameworkConstants.COAUTHORSHIP_VIS,
                VisualizationFrameworkConstants.COAUTHORS_COUNT_PER_YEAR_VIS_MODE));

        Map<String, Integer> yearToUniqueCoauthorsCount = new HashMap<String, Integer>();

        for (Map.Entry<String, Set<Collaborator>> currentYearToCoAuthors : yearToUniqueCoauthors.entrySet()) {
            yearToUniqueCoauthorsCount.put(currentYearToCoAuthors.getKey(),
                    currentYearToCoAuthors.getValue().size());
        }

        sparklineData.setYearToActivityCount(yearToUniqueCoauthorsCount);
    }

    return sparklineData;
}