Index: lams_build/conf/unix/lams/lams.dtd
===================================================================
diff -u -r015c439d1e32c78068f5b9e5121cd34b550dd0e9 -rccbdf974fc22210cfc065234b274be6ca86447db
--- lams_build/conf/unix/lams/lams.dtd (.../lams.dtd) (revision 015c439d1e32c78068f5b9e5121cd34b550dd0e9)
+++ lams_build/conf/unix/lams/lams.dtd (.../lams.dtd) (revision ccbdf974fc22210cfc065234b274be6ca86447db)
@@ -1,7 +1,8 @@
-
+
+
@@ -16,15 +17,3 @@
-
-
-
-
-
-
-
-
-
-
-
-
Index: lams_build/conf/unix/lams/lams.xml
===================================================================
diff -u -rafca38b8b1943e99e6debd875b13973752cfe5da -rccbdf974fc22210cfc065234b274be6ca86447db
--- lams_build/conf/unix/lams/lams.xml (.../lams.xml) (revision afca38b8b1943e99e6debd875b13973752cfe5da)
+++ lams_build/conf/unix/lams/lams.xml (.../lams.xml) (revision ccbdf974fc22210cfc065234b274be6ca86447db)
@@ -4,6 +4,7 @@
/var/opt/lams
/var/opt/lams/temp
+ /var/opt/lams/dump
mail.lib.mq.edu.au
lams_support@melcoe.mq.edu.au
/var/opt/lams/repository
Index: lams_build/conf/windows/lams/lams.dtd
===================================================================
diff -u -r015c439d1e32c78068f5b9e5121cd34b550dd0e9 -rccbdf974fc22210cfc065234b274be6ca86447db
--- lams_build/conf/windows/lams/lams.dtd (.../lams.dtd) (revision 015c439d1e32c78068f5b9e5121cd34b550dd0e9)
+++ lams_build/conf/windows/lams/lams.dtd (.../lams.dtd) (revision ccbdf974fc22210cfc065234b274be6ca86447db)
@@ -1,7 +1,8 @@
-
+
+
@@ -16,14 +17,3 @@
-
-
-
-
-
-
-
-
-
-
-
Index: lams_build/conf/windows/lams/lams.xml
===================================================================
diff -u -rafca38b8b1943e99e6debd875b13973752cfe5da -rccbdf974fc22210cfc065234b274be6ca86447db
--- lams_build/conf/windows/lams/lams.xml (.../lams.xml) (revision afca38b8b1943e99e6debd875b13973752cfe5da)
+++ lams_build/conf/windows/lams/lams.xml (.../lams.xml) (revision ccbdf974fc22210cfc065234b274be6ca86447db)
@@ -2,11 +2,12 @@
http://localhost:8080/lams/
- C:/lams
- C:/lams/temp
+ C:\lams
+ C:\lams\temp
+ C:\lams\dump
mail.lib.mq.edu.au
lams_support@melcoe.mq.edu.au
- C:/lams/repository
+ C:\lams\repository
1048576
10485760
4096
Index: lams_central/src/java/org/lamsfoundation/lams/web/FlashCrashDumpServlet.java
===================================================================
diff -u
--- lams_central/src/java/org/lamsfoundation/lams/web/FlashCrashDumpServlet.java (revision 0)
+++ lams_central/src/java/org/lamsfoundation/lams/web/FlashCrashDumpServlet.java (revision ccbdf974fc22210cfc065234b274be6ca86447db)
@@ -0,0 +1,44 @@
+package org.lamsfoundation.lams.web;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import org.lamsfoundation.lams.usermanagement.dto.UserDTO;
+import org.lamsfoundation.lams.util.FileUtil;
+import org.lamsfoundation.lams.util.wddx.FlashMessage;
+import org.lamsfoundation.lams.web.servlet.AbstractStoreWDDXPacketServlet;
+import org.lamsfoundation.lams.web.session.SessionManager;
+import org.lamsfoundation.lams.web.util.AttributeNames;
+
+
+/**
+ * Write a WDDX packet out to a log file for bug reporting / troubleshooting.
+ *
+ * @author Fiona Malikoff
+ *
+ * @web:servlet name="flashCrashDump"
+ * @web:servlet-mapping url-pattern="/flashCrashDump"
+
+ */
+public class FlashCrashDumpServlet extends AbstractStoreWDDXPacketServlet {
+
+ private static final String MESSAGE_KEY = "flashCrashDump";
+ private static final String PREFIX = "Flash_";
+
+ protected String process(String wddxPacket, HttpServletRequest request)
+ throws Exception
+ {
+ HttpSession ss = SessionManager.getSession();
+ UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
+ String id = PREFIX + ( user != null ? user.getLastName() : "unknown") + "_";
+
+ String filename = FileUtil.createDumpFile(wddxPacket.getBytes(), id);
+ FlashMessage flashMessage = new FlashMessage(MESSAGE_KEY,filename);
+ return flashMessage.serializeMessage();
+ }
+
+ protected String getMessageKey(String designDetails, HttpServletRequest request) {
+ return MESSAGE_KEY;
+ }
+
+}
\ No newline at end of file
Index: lams_common/src/java/org/lamsfoundation/lams/util/ConfigurationKeys.java
===================================================================
diff -u -r042cf32f8e1db66560e21736e8e2d579cdfb43d5 -rccbdf974fc22210cfc065234b274be6ca86447db
--- lams_common/src/java/org/lamsfoundation/lams/util/ConfigurationKeys.java (.../ConfigurationKeys.java) (revision 042cf32f8e1db66560e21736e8e2d579cdfb43d5)
+++ lams_common/src/java/org/lamsfoundation/lams/util/ConfigurationKeys.java (.../ConfigurationKeys.java) (revision ccbdf974fc22210cfc065234b274be6ca86447db)
@@ -14,6 +14,9 @@
public static String SMTP_SERVER="SMTPServer";
public static String LAMS_ADMIN_EMAIL="LamsSupportEmail";
+ /** Flash crash dump files (see FlashCrashDump servlet) are written to the Dump directory */
+ public static String LAMS_DUMP_DIR="DumpDir";
+
public static String CONTENT_REPOSITORY_PATH = "ContentRepositoryPath";
public static String UPLOAD_FILE_MAX_SIZE="UploadFileMaxSize";
public static String UPLOAD_FILE_LARGE_MAX_SIZE="UploadLargeFileMaxSize";
Index: lams_common/src/java/org/lamsfoundation/lams/util/FileUtil.java
===================================================================
diff -u -r36640b233815152b9d67b3c4963894e9e850a426 -rccbdf974fc22210cfc065234b274be6ca86447db
--- lams_common/src/java/org/lamsfoundation/lams/util/FileUtil.java (.../FileUtil.java) (revision 36640b233815152b9d67b3c4963894e9e850a426)
+++ lams_common/src/java/org/lamsfoundation/lams/util/FileUtil.java (.../FileUtil.java) (revision ccbdf974fc22210cfc065234b274be6ca86447db)
@@ -21,9 +21,12 @@
package org.lamsfoundation.lams.util;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.OutputStream;
import org.apache.log4j.Logger;
-import org.lamsfoundation.lams.util.FileUtilException;
import org.lamsfoundation.lams.util.zipfile.ZipFileUtilException;
/**
@@ -106,7 +109,6 @@
String tempDirName = tempSysDirName+File.separator
+prefix+System.currentTimeMillis()+"_"+suffix;
- // Set up the directory. Check it doesn't exist and if it does
// try 100 slightly different variations. If I can't find a unique
// one in ten tries, then give up.
File tempDir = new File(tempDirName);
@@ -217,4 +219,67 @@
File dir = new File(directoryToCheck);
return dir.exists();
}
+
+ private static String generateDumpFilename(String id) throws FileUtilException {
+ // get dump directory name and make sure directory exists
+ String dumpDirectory = Configuration.get(ConfigurationKeys.LAMS_DUMP_DIR);
+ if ( dumpDirectory == null ) {
+ dumpDirectory = TEMP_DIR;
+ }
+ createDirectory(dumpDirectory);
+
+ String dumpFilename = dumpDirectory+File.separator
+ +id+System.currentTimeMillis();
+
+ File dumpFile = new File(dumpFilename);
+ int i = 0;
+ while ( dumpFile.exists() && i < 100 ) {
+ dumpFilename = dumpDirectory+File.separator
+ +id+System.currentTimeMillis()+"_"+i;
+ dumpFile = new File(dumpFilename);
+ }
+ if ( dumpFile.exists() ) {
+ throw new FileUtilException("Unable to create dump file. The filename that we would use already exists: "
+ +dumpFile);
+ }
+
+ return dumpFilename;
+ }
+ /**
+ * Dump some data to a file in the Dump Directory. The directory is set in the LAMS
+ * configuration file. These dumps are primarily for support/debugging/problem reporting
+ * uses.
+ *
+ * If the dump directory is not set, it will revert to the system temp directory.
+ *
+ * Used by the FlashCrashDump servlet initially, may be used by other dump methods in future.
+ *
+ * @param data data to dump
+ * @param id some identification name for the string. Does not need to be unique. e.g. FLASH_jsmith
+ *
+ * @author Fiona Malikoff
+ * @throws FileUtilException
+ */
+ public static String createDumpFile(byte[] data, String id) throws FileUtilException {
+ String dumpFilename = generateDumpFilename(id);
+ OutputStream dumpFile = null;
+ try {
+ dumpFile = new FileOutputStream(dumpFilename);
+ dumpFile.write(data);
+ } catch (IOException e) {
+ log.error("Unable to write dump out byte array to dump file. ID: "+id
+ +" Dump: "+data+" Exception "+e.getMessage(), e);
+ throw new FileUtilException(e);
+ } finally {
+ try {
+ if ( dumpFile != null )
+ dumpFile.close();
+ } catch (IOException e) {
+ log.error("Unable to close dump file. ID: "+id
+ +" Dump: "+data+" Exception "+e.getMessage(), e);
+ throw new FileUtilException(e);
+ }
+ }
+ return dumpFilename;
+ }
}
Index: lams_common/test/java/org/lamsfoundation/lams/util/TestFileUtil.java
===================================================================
diff -u -rc09822a88b909fd83b10ebc89d667dfaedd5c21b -rccbdf974fc22210cfc065234b274be6ca86447db
--- lams_common/test/java/org/lamsfoundation/lams/util/TestFileUtil.java (.../TestFileUtil.java) (revision c09822a88b909fd83b10ebc89d667dfaedd5c21b)
+++ lams_common/test/java/org/lamsfoundation/lams/util/TestFileUtil.java (.../TestFileUtil.java) (revision ccbdf974fc22210cfc065234b274be6ca86447db)
@@ -22,12 +22,12 @@
package org.lamsfoundation.lams.util;
-import junit.framework.TestCase;
-import org.lamsfoundation.lams.util.FileUtil;
-import org.lamsfoundation.lams.util.FileUtilException;
import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
+import junit.framework.TestCase;
+
/**
* @author mtruong
*/
@@ -227,7 +227,32 @@
}
+ public void testCreateDumpFile() throws FileUtilException, IOException
+ {
+ byte[] testData = "This is my test string.".getBytes();
+ String indexString = "xyzzy_";
+ String filename = FileUtil.createDumpFile(testData, indexString);
+
+ assertNotNull("Filename of dump file is not null", filename);
+ assertTrue("Filename includes id string ", filename.indexOf(indexString)!=-1);
+
+ File filenameFile = new File(filename);
+ assertTrue("File "+filename+" exists.", filenameFile.exists());
+
+
+ FileInputStream is = new FileInputStream(filename);
+ byte[] inputData = new byte[testData.length];
+ int readBytes = is.read(inputData);
+ assertTrue("File contains at least the test data length of data", readBytes == testData.length );
+ for ( int i=0; i