changeset 821:6c752969f9e8 stream

more tries and catches...
author robcast
date Tue, 22 Feb 2011 20:08:27 +0100
parents dc8cda290f2f
children 26a3e127f45c
files servlet/src/digilib/image/ImageLoaderDocuImage.java servlet/src/digilib/io/FileOps.java servlet/src/digilib/servlet/Initialiser.java servlet/src/digilib/servlet/Scaler.java
diffstat 4 files changed, 25 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/servlet/src/digilib/image/ImageLoaderDocuImage.java	Tue Feb 22 18:33:55 2011 +0100
+++ b/servlet/src/digilib/image/ImageLoaderDocuImage.java	Tue Feb 22 20:08:27 2011 +0100
@@ -201,6 +201,9 @@
 		if (input.hasMimetype()) {
 	        // check hasMimetype first or we might get into a loop
 		    mt = input.getMimetype();
+		} else {
+		    // try file extension
+            mt = FileOps.mimeForFile(input.getFile());
 		}
 		if (mt == null) {
 			logger.debug("No mime-type. Trying automagic.");
--- a/servlet/src/digilib/io/FileOps.java	Tue Feb 22 18:33:55 2011 +0100
+++ b/servlet/src/digilib/io/FileOps.java	Tue Feb 22 20:08:27 2011 +0100
@@ -107,7 +107,10 @@
 	 * get the mime type for a file format (by extension)
 	 */
 	public static String mimeForFile(File f) {
-		return (String) fileTypes.get(extname(f.getName().toLowerCase()));
+	    if (f == null) {
+	        return null;
+	    }
+		return fileTypes.get(extname(f.getName().toLowerCase()));
 	}
 
 	/**
--- a/servlet/src/digilib/servlet/Initialiser.java	Tue Feb 22 18:33:55 2011 +0100
+++ b/servlet/src/digilib/servlet/Initialiser.java	Tue Feb 22 20:08:27 2011 +0100
@@ -162,6 +162,7 @@
      * 
      */
     public void contextDestroyed(ServletContextEvent arg0) {
+        logger.info("Initialiser shutting down.");
         if (dirCache != null) {
             // shut down dirCache?
             dirCache = null;
--- a/servlet/src/digilib/servlet/Scaler.java	Tue Feb 22 18:33:55 2011 +0100
+++ b/servlet/src/digilib/servlet/Scaler.java	Tue Feb 22 20:08:27 2011 +0100
@@ -31,7 +31,7 @@
     private static final long serialVersionUID = 5289386646192471549L;
 
     /** digilib servlet version (for all components) */
-    public static final String version = "1.9.1a7";
+    public static final String version = "1.9.1a9";
 
     /** servlet error codes */
     public static enum Error {UNKNOWN, AUTH, FILE, IMAGE};
@@ -120,7 +120,8 @@
         sendFileAllowed = dlConfig.getAsBoolean("sendfile-allowed");
     }
 
-    /** Returns modification time relevant to the request for caching.
+    /**
+     * Returns modification time relevant to the request for caching.
      * 
      * @see javax.servlet.http.HttpServlet#getLastModified(javax.servlet.http.HttpServletRequest)
      */
@@ -128,13 +129,17 @@
         accountlog.debug("GetLastModified from " + request.getRemoteAddr()
                 + " for " + request.getQueryString());
         long mtime = -1;
-        // create new request
-        DigilibRequest dlReq = new DigilibRequest(request);
-        DocuDirectory dd = dirCache.getDirectory(dlReq.getFilePath());
-        if (dd != null) {
-            mtime = dd.getDirMTime() / 1000 * 1000;
+        try {
+            // create new request
+            DigilibRequest dlReq = new DigilibRequest(request);
+            DocuDirectory dd = dirCache.getDirectory(dlReq.getFilePath());
+            if (dd != null) {
+                mtime = dd.getDirMTime() / 1000 * 1000;
+            }
+        } catch (Exception e) {
+            logger.error("error in getLastModified: " + e.getMessage());
         }
-        logger.debug("  returns "+mtime);
+        logger.debug("  returns " + mtime);
         return mtime;
     }
 
@@ -265,6 +270,10 @@
         } catch (AuthOpException e) {
             logger.error(e.getClass() + ": " + e.getMessage());
             digilibError(errMsgType, Error.AUTH, null, response);
+        } catch (Exception e) {
+            logger.error("Other Exception: ", e);
+            // TODO: should we rethrow or swallow?
+            //throw new ServletException(e);
         }
     }