Skip to content
Snippets Groups Projects
Commit 0e4cbf8f authored by Piotr Gawron's avatar Piotr Gawron
Browse files

error handling for xml serialization improved to catch all library errors

parent b3d216aa
No related branches found
No related tags found
1 merge request!75Resolve "MiRNA - Show all - duplicated entries"
......@@ -448,12 +448,14 @@ public class PermanentDatabaseLevelCache extends XmlParser implements PermanentD
try {
Document document = getXmlDocumentFromString(entry.getValue());
Calendar currentDate = Calendar.getInstance();
if (currentDate.before(entry.getExpires())) {
return document.getFirstChild();
} else {
if (currentDate.after(entry.getExpires())) {
cacheRefreshService.submit(new RefreshTask(query, type));
return document.getFirstChild();
}
Node result = null;
if (document != null) {
result = document.getFirstChild();
}
return result;
} catch (InvalidXmlSchemaException e) {
logger.warn("Invalid xml for query: " + query);
logger.warn("xml: " + entry.getValue());
......
......@@ -8,6 +8,7 @@ import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import org.apache.commons.lang3.SerializationException;
import org.apache.log4j.Logger;
import org.w3c.dom.Node;
/**
......@@ -20,7 +21,8 @@ import org.w3c.dom.Node;
* type of the object to serialize
*/
public class XmlSerializer<T> {
private final Logger logger = Logger.getLogger(XmlSerializer.class);
/**
* Class of the object that DAO works on.
*/
......@@ -74,7 +76,8 @@ public class XmlSerializer<T> {
} catch (JAXBException e) {
throw new SerializationException(e);
} catch (Exception e) {
throw new SerializationException(e);
logger.error(e, e);
return null;
}
return sw.toString();
}
......@@ -95,8 +98,9 @@ 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);
} catch (Exception e) { // the library can throw NPE sometimes...
logger.error(e, e);
return null;
}
}
......
......@@ -4,10 +4,25 @@ import java.util.Collection;
import lcsb.mapviewer.model.map.MiriamData;
/**
* Interface for all externall objects that interact with elements on the map.
*
* @author Piotr Gawron
*
*/
public interface TargettingStructure {
/**
*
* @return list of {@link MiriamData annotations} that describe source of this
* object
*/
Collection<MiriamData> getSources();
/**
*
* @return list of {@link Target targets} with which object is interacting
*/
Collection<Target> getTargets();
}
......@@ -183,7 +183,11 @@ public class PubmedParser extends CachableInterface implements IExternalService
result.setId(id + "");
if (result.getTitle() != null && !result.getTitle().trim().isEmpty()) {
setCacheValue(queryString, articleSerializer.objectToString(result));
try {
setCacheValue(queryString, articleSerializer.objectToString(result));
} catch (SerializationException e) {
logger.warn("Problem with serialization of the string: " + queryString);
}
} else {
result = null;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment