From 6904198bf8b6a6f1bb265b7acd9ff0d7ab4f083a Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Fri, 27 Jan 2017 11:05:08 +0100 Subject: [PATCH] error handling ehen there is an issue with mesh data --- .../annotation/cache/XmlSerializer.java | 4 +++- .../annotation/services/MeSHParser.java | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/cache/XmlSerializer.java b/annotation/src/main/java/lcsb/mapviewer/annotation/cache/XmlSerializer.java index 1a9866cae4..1f51982375 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/cache/XmlSerializer.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/cache/XmlSerializer.java @@ -20,7 +20,7 @@ import org.w3c.dom.Node; * type of the object to serialize */ public class XmlSerializer<T> { - + /** * Class of the object that DAO works on. */ @@ -93,6 +93,8 @@ public class XmlSerializer<T> { return (T) jaxbUnmarshaller.unmarshal(node); } catch (JAXBException e) { throw new SerializationException(e); + } catch (Exception e) { //the library can throw NPE sometimes... + throw new SerializationException(e); } } diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/MeSHParser.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/MeSHParser.java index dda935775b..125a040e3a 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/MeSHParser.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/MeSHParser.java @@ -2,6 +2,9 @@ package lcsb.mapviewer.annotation.services; import java.io.IOException; +import javax.sql.rowset.serial.SerialException; + +import org.apache.commons.lang3.SerializationException; import org.apache.log4j.Logger; import org.w3c.dom.Node; @@ -100,16 +103,22 @@ public class MeSHParser extends CachableInterface implements IExternalService { String id = getIdentifier(meshID); Node meshNode = super.getCacheNode(id); if (meshNode != null && meshNode.hasChildNodes()) { - mesh = meshSerializer.xmlToObject(meshNode); - } else { + try { + mesh = meshSerializer.xmlToObject(meshNode); + } catch (SerializationException e) { + logger.warn("Problem with processing cached info about mesh: " + meshID); + mesh = null; + } + } + if (mesh == null) { try { mesh = getMeSHByIdFromDB(meshID); } catch (IOException e) { throw new AnnotatorException("Problem with accessing MeSH database", e); } - if (mesh != null) { - super.setCacheValue(id, this.meshSerializer.objectToString(mesh)); - } + } + if (mesh != null) { + super.setCacheValue(id, this.meshSerializer.objectToString(mesh)); } return mesh; -- GitLab