From 86755b62bc5d4180b11e1f90d76c27093cf8af8f Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Fri, 24 Aug 2018 15:23:06 -0700 Subject: [PATCH] NOJIRA: Support both absolute paths and relative paths (relative to tomcat dir) values for the blobUri query param of Media and Blob servies. --- .../collectionspace/services/common/ServiceMain.java | 11 +++++++++++ .../services/common/blob/BlobInput.java | 12 +++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java b/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java index 901113619..84269b432 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java +++ b/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java @@ -101,6 +101,7 @@ public class ServiceMain { private static final String DROP_USER_SQL_CMD = "DROP USER"; private static final String DROP_USER_IF_EXISTS_SQL_CMD = DROP_USER_SQL_CMD + " IF EXISTS %s;"; private static final String DROP_OBJECTS_SQL_COMMENT = "-- drop all the objects before dropping roles"; + private static final String CSPACE_JEESERVER_HOME = "CSPACE_JEESERVER_HOME"; private ServiceMain() { // Intentionally blank @@ -1438,4 +1439,14 @@ public class ServiceMain { } } + + public static String getJeeContainPath() throws Exception { + String result = System.getenv(CSPACE_JEESERVER_HOME); + + if (result == null) { + throw new Exception(); + } + + return result; + } } diff --git a/services/common/src/main/java/org/collectionspace/services/common/blob/BlobInput.java b/services/common/src/main/java/org/collectionspace/services/common/blob/BlobInput.java index 2d81e3cd8..6a7d3e8be 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/blob/BlobInput.java +++ b/services/common/src/main/java/org/collectionspace/services/common/blob/BlobInput.java @@ -4,6 +4,8 @@ import java.io.File; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; +import java.nio.file.Path; +import java.nio.file.Paths; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -12,6 +14,7 @@ import javax.servlet.http.HttpServletRequest; import org.collectionspace.services.nuxeo.client.java.CommonList; import org.collectionspace.services.common.Download; +import org.collectionspace.services.common.ServiceMain; import org.collectionspace.services.common.document.DocumentException; import org.collectionspace.services.common.imaging.nuxeo.NuxeoBlobUtils; @@ -218,7 +221,14 @@ public class BlobInput { throw new DocumentException(msg); } } else if (blobUrl.getProtocol().equalsIgnoreCase("file")) { - theBlobFile = FileUtils.toFile(blobUrl); + if (blobUrl.getPath().startsWith("/")) { + // full path + theBlobFile = FileUtils.toFile(blobUrl); + } else { + // relative to JEE container (e.g. Apache Tomcat) path + Path theBlobFilePath = Paths.get(ServiceMain.getJeeContainPath(), blobUrl.getPath()); + theBlobFile = new File(theBlobFilePath.toAbsolutePath().toString()); + } if (theBlobFile.exists() == false || theBlobFile.canRead() == false) { String msg = FILE_ACCESS_ERROR + theBlobFile.getAbsolutePath(); logger.error(msg); -- 2.47.3