changeset 1296:32eb36e6c9d2

fix problem that getRealPath of Tomcat 8 needs paths to start with '/'.
author robcast
date Mon, 21 Jul 2014 15:32:19 +0200
parents 09424acc2216
children aa09153a2b13
files servlet/src/main/java/digilib/conf/DigilibServletConfiguration.java servlet/src/main/java/digilib/servlet/ServletOps.java webapp/src/main/webapp/server/dlConfig.jsp webapp/src/main/webapp/server/dlRequest.jsp
diffstat 4 files changed, 14 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/servlet/src/main/java/digilib/conf/DigilibServletConfiguration.java	Thu Jul 17 15:17:32 2014 +0200
+++ b/servlet/src/main/java/digilib/conf/DigilibServletConfiguration.java	Mon Jul 21 15:32:19 2014 +0200
@@ -183,7 +183,8 @@
         String fn = c.getInitParameter("config-file");
         if (fn == null) {
             logger.debug("readConfig: no param config-file");
-            fn = ServletOps.getConfigFile("digilib-config.xml", c);
+            fn = ServletOps.getConfigFileName("digilib-config.xml", c);
+            if (fn == null) fn = "";
         }
         File f = new File(fn);
         if (f.canRead()) {
@@ -314,7 +315,7 @@
          */
         // set up the logger
         File logConf = ServletOps.getConfigFile((File) config.getValue("log-config-file"), context);
-        if (logConf.canRead()) {
+        if (logConf != null && logConf.canRead()) {
             DOMConfigurator.configure(logConf.getAbsolutePath());
             config.setValue("log-config-file", logConf);
         }
--- a/servlet/src/main/java/digilib/servlet/ServletOps.java	Thu Jul 17 15:17:32 2014 +0200
+++ b/servlet/src/main/java/digilib/servlet/ServletOps.java	Mon Jul 21 15:32:19 2014 +0200
@@ -87,7 +87,7 @@
         // is the filename absolute?
         if (!f.isAbsolute()) {
             // relative path -> use getRealPath to resolve in WEB-INF
-            String fn = sc.getRealPath(f.getPath());
+            String fn = sc.getRealPath("/" + f.getPath());
             if (fn == null) {
                 // TODO: use getResourceAsStream?
                 return null;
@@ -112,7 +112,7 @@
         // is the filename absolute?
         if (!f.isAbsolute()) {
             // relative path -> use getRealPath to resolve in WEB-INF
-            filename = sc.getRealPath(filename);
+            filename = sc.getRealPath("/" + filename);
         }
         return filename;
     }
@@ -141,8 +141,8 @@
             }
         }
         // relative path -> use getRealPath to resolve in WEB-INF
-        String newfn = sc.getRealPath("WEB-INF/" + fn);
-        if (fn == null) {
+        String newfn = sc.getRealPath("/WEB-INF/" + fn);
+        if (newfn == null) {
             // TODO: use getResourceAsStream?
             return null;
         }
@@ -160,12 +160,12 @@
      * @param sc
      * @return
      */
-    public static String getConfigFile(String filename, ServletContext sc) {
+    public static String getConfigFileName(String filename, ServletContext sc) {
         File f = new File(filename);
         // is the filename absolute?
         if (!f.isAbsolute()) {
             // relative path -> use getRealPath to resolve in WEB-INF
-            filename = sc.getRealPath("WEB-INF/" + filename);
+            filename = sc.getRealPath("/WEB-INF/" + filename);
         }
         return filename;
     }
--- a/webapp/src/main/webapp/server/dlConfig.jsp	Thu Jul 17 15:17:32 2014 +0200
+++ b/webapp/src/main/webapp/server/dlConfig.jsp	Mon Jul 21 15:32:19 2014 +0200
@@ -90,7 +90,9 @@
             } else {
                 if (!f.isAbsolute()) {
                     // relative path -> use getRealPath to resolve
-                    f = new File(pageContext.getServletContext().getRealPath(f.getPath()));
+                    String fn = pageContext.getServletContext().getRealPath("/" + f.getPath());
+                    if (fn == null) fn = "";
+                    f = new File(fn);
                 }
                 if (f.canRead()) {
                     val = f.toString();
--- a/webapp/src/main/webapp/server/dlRequest.jsp	Thu Jul 17 15:17:32 2014 +0200
+++ b/webapp/src/main/webapp/server/dlRequest.jsp	Mon Jul 21 15:32:19 2014 +0200
@@ -72,7 +72,7 @@
     <td><i>url of the page/document</i></td>
   </tr>
   <tr>
-    <td>Fn</td><td><b><b><%= dlRequest.getAsString("fn") %></b></td><td><i>url of the page/document</i></td>
+    <td>Fn</td><td><b><%= dlRequest.getAsString("fn") %></b></td><td><i>url of the page/document</i></td>
   </tr>
   <tr>
     <td>FilePath</td><td><b><%= dlRequest.getFilePath() %></b></td><td><i>effective path of the page/document</i></td>
@@ -115,7 +115,7 @@
   </tr>
 </table>
 
-<h2>All parameters<h2>
+<h2>All parameters</h2>
 
 <table>
 <%