safeguard against loss of Connection to FM and NPEs Project: http://git-wip-us.apache.org/repos/asf/oodt/repo Commit: http://git-wip-us.apache.org/repos/asf/oodt/commit/f415976d Tree: http://git-wip-us.apache.org/repos/asf/oodt/tree/f415976d Diff: http://git-wip-us.apache.org/repos/asf/oodt/diff/f415976d
Branch: refs/heads/feature/zookeeper-config Commit: f415976da06334dce5500d8ac77355a5d90b9344 Parents: 4af396f Author: Chris Mattmann <mattm...@apache.org> Authored: Fri Jul 28 22:04:15 2017 -0700 Committer: Chris Mattmann <mattm...@apache.org> Committed: Fri Jul 28 22:04:15 2017 -0700 ---------------------------------------------------------------------- .../webcomponents/filemgr/FileManagerConn.java | 42 +++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/oodt/blob/f415976d/webapp/components/src/main/java/org/apache/oodt/cas/webcomponents/filemgr/FileManagerConn.java ---------------------------------------------------------------------- diff --git a/webapp/components/src/main/java/org/apache/oodt/cas/webcomponents/filemgr/FileManagerConn.java b/webapp/components/src/main/java/org/apache/oodt/cas/webcomponents/filemgr/FileManagerConn.java index cdcf4c7..41c757a 100644 --- a/webapp/components/src/main/java/org/apache/oodt/cas/webcomponents/filemgr/FileManagerConn.java +++ b/webapp/components/src/main/java/org/apache/oodt/cas/webcomponents/filemgr/FileManagerConn.java @@ -28,6 +28,7 @@ import org.apache.oodt.cas.filemgr.system.XmlRpcFileManagerClient; import org.apache.oodt.cas.metadata.Metadata; import java.net.URL; +import java.util.Collections; import java.util.List; import java.util.Vector; import java.util.logging.Level; @@ -45,8 +46,8 @@ public class FileManagerConn { private XmlRpcFileManagerClient fm; - private static final Logger LOG = Logger.getLogger(FileManagerConn.class - .getName()); + private static final Logger LOG = Logger + .getLogger(FileManagerConn.class.getName()); public FileManagerConn(String fmUrlStr) { this.initFm(fmUrlStr); @@ -54,13 +55,15 @@ public class FileManagerConn { public String getProdReceivedTime(Product p) { Metadata met = getMetadata(p); - String prodReceivedTime = met.getMetadata("CAS." - + CoreMetKeys.PRODUCT_RECEVIED_TIME); - return prodReceivedTime != null && !prodReceivedTime.equals("") ? prodReceivedTime - : "UNKNOWN"; + String prodReceivedTime = met + .getMetadata("CAS." + CoreMetKeys.PRODUCT_RECEVIED_TIME); + return prodReceivedTime != null && !prodReceivedTime.equals("") + ? prodReceivedTime : "UNKNOWN"; } public List<Reference> getProductReferences(Product p) { + if (!isConnected()) + return Collections.EMPTY_LIST; List<Reference> refs = new Vector<Reference>(); try { refs = fm.getProductReferences(p); @@ -73,6 +76,8 @@ public class FileManagerConn { } public ProductType safeGetProductTypeByName(String name) { + if (!isConnected()) + return ProductType.blankProductType(); try { return fm.getProductTypeByName(name); } catch (Exception e) { @@ -83,6 +88,8 @@ public class FileManagerConn { } public Product safeGetProductById(String id) { + if (!isConnected()) + return Product.getDefaultFlatProduct("", ""); try { return fm.getProductById(id); } catch (Exception e) { @@ -93,6 +100,8 @@ public class FileManagerConn { } public Metadata getMetadata(Product p) { + if (!isConnected()) + return new Metadata(); Metadata met = null; try { met = fm.getMetadata(p); @@ -106,6 +115,8 @@ public class FileManagerConn { } public List<Element> safeGetElementsForProductType(ProductType type) { + if (!isConnected()) + return Collections.EMPTY_LIST; try { return fm.getElementsByProductType(type); } catch (Exception e) { @@ -116,13 +127,15 @@ public class FileManagerConn { } public List<ProductType> safeGetProductTypes() { + if (!isConnected()) + return Collections.EMPTY_LIST; List<ProductType> types = new Vector<ProductType>(); try { types = this.fm.getProductTypes(); } catch (RepositoryManagerException e) { LOG.log(Level.SEVERE, e.getMessage()); - LOG.log(Level.WARNING, "Unable to obtain product types: Reason: [" - + e.getMessage() + "]"); + LOG.log(Level.WARNING, + "Unable to obtain product types: Reason: [" + e.getMessage() + "]"); } return types; } @@ -135,10 +148,19 @@ public class FileManagerConn { try { this.fm = new XmlRpcFileManagerClient(new URL(urlStr)); } catch (Exception e) { - LOG.log(Level.WARNING, "Unable to connect to the file manager at: [" - + urlStr + "]"); + LOG.log(Level.WARNING, + "Unable to connect to the file manager at: [" + urlStr + "]"); this.fm = null; } } + private boolean isConnected() { + if (this.fm == null) { + LOG.warning( + "File Manager Connection is null: Default objects for Products, Product Types, References, etc., will be returned."); + return false; + } else + return true; + } + }