From c519ed2312e3127e926d15bc6e9ae6be8e24294d Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Tue, 14 May 2013 14:41:41 -0700 Subject: [PATCH] CSPACE-5766: Reports service now dumps basic info about the existence of, and write access to, the Java / Tomcat temporary directory prior to calling JasperReports fillReport() method. This may help us debug one category of errors seen when CSPACE-5766-style problem occur. --- .../services/common/api/FileTools.java | 59 ++++++++++++++++++- .../nuxeo/ReportDocumentModelHandler.java | 8 ++- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/services/common-api/src/main/java/org/collectionspace/services/common/api/FileTools.java b/services/common-api/src/main/java/org/collectionspace/services/common/api/FileTools.java index 6b6eacab1..7490cd039 100644 --- a/services/common-api/src/main/java/org/collectionspace/services/common/api/FileTools.java +++ b/services/common-api/src/main/java/org/collectionspace/services/common/api/FileTools.java @@ -44,6 +44,7 @@ public class FileTools { public static String DEFAULT_ENCODING = ""; public static String UTF8_ENCODING = "UTF-8"; public static boolean FORCE_CREATE_PARENT_DIRS = true; + private static String JAVA_TEMP_DIR_PROPERTY = "java.io.tmpdir"; /** * getObjectFromStream get object of given class from given inputstream @@ -192,9 +193,65 @@ public class FileTools { return result; } + // FIXME: Java 7 now offers an integral method for this purpose, + // java.nio.file.Files.createTempDirectory() public static File createTmpDir(String filePrefix){ - String tmpDir = System.getProperty("java.io.tmpdir"); + String tmpDir = System.getProperty(JAVA_TEMP_DIR_PROPERTY); File result = new File(tmpDir, filePrefix + UUID.randomUUID().toString()); return result; } + + /** + * Returns information about the Java temporary directory, + * including its path and selected access rights of the + * current code to that directory. + * + * This can potentially be helpful when troubleshooting issues + * related to code that uses that temporary directory, as per CSPACE-5766. + * + * @return information about the Java temporary directory. + */ + public static String getJavaTmpDirInfo() { + StringBuffer strBuf = new StringBuffer(""); + String tmpDirProperty = System.getProperty(JAVA_TEMP_DIR_PROPERTY); + strBuf.append("\n"); + if (Tools.notBlank(tmpDirProperty)) { + strBuf.append("Java temporary directory property="); + strBuf.append(tmpDirProperty); + strBuf.append("\n"); + } else { + strBuf.append("Could not get Java temporary directory property"); + strBuf.append("\n"); + return strBuf.toString(); + } + File tmpDir = new File(tmpDirProperty); // Throws only NPE, if tmpDirProperty is null + boolean tmpDirExists = false; + boolean tmpDirIsDirectory = false; + try { + tmpDirExists = tmpDir.exists(); + strBuf.append("Temporary directory exists="); + strBuf.append(tmpDirExists); + strBuf.append("\n"); + tmpDirIsDirectory = tmpDir.isDirectory(); + strBuf.append("Temporary directory is actually a directory="); + strBuf.append(tmpDirIsDirectory); + strBuf.append("\n"); + } catch (SecurityException se) { + strBuf.append("Security manager settings prohibit reading temporary directory: "); + strBuf.append(se.getMessage()); + strBuf.append("\n"); + return strBuf.toString(); + } + if (tmpDirExists && tmpDirIsDirectory) { + try { + boolean tmpDirIsWriteable = tmpDir.canWrite(); + strBuf.append("Temporary directory is writeable by application="); + strBuf.append(tmpDirIsWriteable); + } catch (SecurityException se) { + strBuf.append("Security manager settings prohibit writing to temporary directory: "); + strBuf.append(se.getMessage()); + } + } + return strBuf.toString(); + } } diff --git a/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java b/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java index c0bb1cac9..dc2b5b3f8 100644 --- a/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java +++ b/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java @@ -65,6 +65,7 @@ import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.ReportClient; import org.collectionspace.services.common.ServiceMain; +import org.collectionspace.services.common.api.FileTools; import org.collectionspace.services.common.api.Tools; import org.collectionspace.services.common.config.ConfigReader; import org.collectionspace.services.common.context.ServiceContext; @@ -326,7 +327,12 @@ public class ReportDocumentModelHandler extends DocHandlerBase { outputFilename = outputFilename+"-default-to.pdf"; } outReportFileName.append(outputFilename); // Set the out going param to the report's final file name - // fill the report + // FIXME: Logging temporarily set to INFO level for CSPACE-5766; + // can change to TRACE or DEBUG level as warranted thereafter + if (logger.isInfoEnabled()) { + logger.info(FileTools.getJavaTmpDirInfo()); + } + // fill the report JasperPrint jasperPrint = JasperFillManager.fillReport(fileStream, params,conn); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); -- 2.47.3