]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5766: Reports service now dumps basic info about the existence of, and write...
authorAron Roberts <aron@socrates.berkeley.edu>
Tue, 14 May 2013 21:41:41 +0000 (14:41 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Tue, 14 May 2013 21:41:41 +0000 (14:41 -0700)
services/common-api/src/main/java/org/collectionspace/services/common/api/FileTools.java
services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java

index 6b6eacab12d0e9e7913dd5b91aba6d0b0f30db30..7490cd039ccb1fcd33096e53043a604cf5f6cf7b 100644 (file)
@@ -44,6 +44,7 @@ public class FileTools {
     public static String DEFAULT_ENCODING = "";\r
     public static String UTF8_ENCODING = "UTF-8";\r
     public static boolean FORCE_CREATE_PARENT_DIRS = true;\r
+    private static String JAVA_TEMP_DIR_PROPERTY = "java.io.tmpdir";\r
 \r
     /**\r
      * getObjectFromStream get object of given class from given inputstream\r
@@ -192,9 +193,65 @@ public class FileTools {
         return result;\r
     }\r
 \r
+    // FIXME: Java 7 now offers an integral method for this purpose,\r
+    // java.nio.file.Files.createTempDirectory()\r
     public static File createTmpDir(String filePrefix){\r
-        String tmpDir = System.getProperty("java.io.tmpdir");\r
+        String tmpDir = System.getProperty(JAVA_TEMP_DIR_PROPERTY);\r
                File result = new File(tmpDir, filePrefix + UUID.randomUUID().toString());\r
                return result;\r
     }\r
+    \r
+    /**\r
+     * Returns information about the Java temporary directory,\r
+     * including its path and selected access rights of the\r
+     * current code to that directory.\r
+     * \r
+     * This can potentially be helpful when troubleshooting issues\r
+     * related to code that uses that temporary directory, as per CSPACE-5766.\r
+     * \r
+     * @return information about the Java temporary directory.\r
+     */\r
+    public static String getJavaTmpDirInfo() {\r
+        StringBuffer strBuf = new StringBuffer("");\r
+        String tmpDirProperty = System.getProperty(JAVA_TEMP_DIR_PROPERTY);\r
+        strBuf.append("\n");\r
+        if (Tools.notBlank(tmpDirProperty)) {\r
+            strBuf.append("Java temporary directory property=");\r
+            strBuf.append(tmpDirProperty);\r
+            strBuf.append("\n");\r
+        } else {\r
+            strBuf.append("Could not get Java temporary directory property");\r
+            strBuf.append("\n");\r
+            return strBuf.toString();\r
+        }\r
+        File tmpDir = new File(tmpDirProperty); // Throws only NPE, if tmpDirProperty is null\r
+        boolean tmpDirExists = false;\r
+        boolean tmpDirIsDirectory = false;\r
+        try {\r
+            tmpDirExists = tmpDir.exists();\r
+            strBuf.append("Temporary directory exists=");\r
+            strBuf.append(tmpDirExists);\r
+            strBuf.append("\n");\r
+            tmpDirIsDirectory = tmpDir.isDirectory();\r
+            strBuf.append("Temporary directory is actually a directory=");\r
+            strBuf.append(tmpDirIsDirectory);\r
+            strBuf.append("\n");           \r
+        } catch (SecurityException se) {\r
+            strBuf.append("Security manager settings prohibit reading temporary directory: ");\r
+            strBuf.append(se.getMessage());\r
+            strBuf.append("\n");\r
+            return strBuf.toString();\r
+        }\r
+        if (tmpDirExists && tmpDirIsDirectory) {\r
+            try {\r
+                boolean tmpDirIsWriteable = tmpDir.canWrite();\r
+                strBuf.append("Temporary directory is writeable by application=");\r
+                strBuf.append(tmpDirIsWriteable);\r
+            } catch (SecurityException se) {\r
+                strBuf.append("Security manager settings prohibit writing to temporary directory: ");\r
+                strBuf.append(se.getMessage());\r
+           }           \r
+        }\r
+        return strBuf.toString();\r
+    }\r
 }\r
index c0bb1cac96a4eadace1bf75e8394ac7f41011b78..dc2b5b3f8923309bb31ef149afc5ad49525545bf 100644 (file)
@@ -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<ReportsCommon> {
                                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);