Title: [527] trunk/rails-integration/src/main/java/org/jruby/webapp: Added configuration changes from Jon Tirsen
Revision
527
Author
olabini
Date
2007-05-01 07:55:41 -0400 (Tue, 01 May 2007)

Log Message

Added configuration changes from Jon Tirsen

Modified Paths


Diff

Modified: trunk/rails-integration/src/main/java/org/jruby/webapp/AbstractRailsServlet.java (526 => 527)


--- trunk/rails-integration/src/main/java/org/jruby/webapp/AbstractRailsServlet.java	2007-05-01 06:33:11 UTC (rev 526)
+++ trunk/rails-integration/src/main/java/org/jruby/webapp/AbstractRailsServlet.java	2007-05-01 11:55:41 UTC (rev 527)
@@ -1,17 +1,18 @@
 package org.jruby.webapp;
 import org.apache.commons.pool.ObjectPool;
+import org.jruby.Ruby;
 import org.jruby.RubyException;
-import org.jruby.Ruby;
+import org.jruby.exceptions.RaiseException;
 import org.jruby.webapp.util.CustomObjectPool;
-import org.jruby.exceptions.RaiseException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.PrintStream;
-import java.io.ByteArrayOutputStream;
 import java.util.NoSuchElementException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.ServletException;
 
 /**
  * This servlet dispatches to a Ruby on Rails application, using JRuby as the interpreter.
@@ -123,7 +124,11 @@
 	}
 
 	protected String getDeploymentEnvironment() {
-		return getServletContext().getInitParameter("rails.env");
+        String railsEnv = getServletConfig().getInitParameter("rails.env");
+        if (railsEnv == null) {
+            railsEnv = getServletContext().getInitParameter("rails.env");
+        }
+        return railsEnv;
 	}
 
 	/**
@@ -150,7 +155,7 @@
 			// log("Invocation time: " + (System.currentTimeMillis() - startTime) + "ms");
 		} catch (RaiseException e) {
 			String action = "" == null) ? "initialise runtime" : "invoke rails";
-			log("Failed to " + action + "\n" + getBacktrace(e.getException()));
+			log("Failed to " + action + ": " + e.getMessage() + "\n" + getBacktrace(e.getException()));
 			throw new ServletException("Failed to " + action + ", please see the log for more details");
 		} catch (NoSuchElementException e) {
 			// all objects in the pool have been used up

Modified: trunk/rails-integration/src/main/java/org/jruby/webapp/FileServlet.java (526 => 527)


--- trunk/rails-integration/src/main/java/org/jruby/webapp/FileServlet.java	2007-05-01 06:33:11 UTC (rev 526)
+++ trunk/rails-integration/src/main/java/org/jruby/webapp/FileServlet.java	2007-05-01 11:55:41 UTC (rev 527)
@@ -1,19 +1,15 @@
 package org.jruby.webapp;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.channels.FileChannel;
-import java.nio.ByteBuffer;
 import javax.activation.FileTypeMap;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import javax.servlet.ServletException;
-import javax.servlet.ServletContext;
-import javax.servlet.RequestDispatcher;
+import java.io.*;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
 
 /**
  * This servlet returns a static file.
@@ -30,7 +26,7 @@
 
 	private String rootPath;
 
-	private String prefix = File.separator + "public";
+	private String directory;
 
 	private RequestDispatcher defaultServletDispatcher;
 
@@ -48,9 +44,17 @@
 			rootPath = rootPath.substring(0, rootPath.length() - 1);
 		}
 
-		// check for default fallback servlet
-		String defaultServletName = context.getInitParameter(FileServlet.FALLBACK_SERVLET_PROPERTY);
-		if (defaultServletName != null && defaultServletName.length() != 0) {
+        directory = getServletConfig().getInitParameter("directory");
+        if (directory == null) {
+            directory = "public";
+        }
+
+        // check for default fallback servlet
+		String defaultServletName = getServletConfig().getInitParameter("defaultServlet");
+        if (defaultServletName == null) {
+            defaultServletName = context.getInitParameter(FileServlet.FALLBACK_SERVLET_PROPERTY);
+        }
+        if (defaultServletName != null && defaultServletName.length() != 0) {
 			defaultServletDispatcher = context.getNamedDispatcher(defaultServletName);
 		}
 	}
@@ -73,8 +77,14 @@
 			String contextPath = request.getContextPath();
 			String relativePath = request.getRequestURI().substring(contextPath.length());
 
-			String realPath = rootPath + prefix + relativePath;
-			realPath = realPath.replaceAll("\\\\", "/");
+            String realPath;
+            // if it's relative prepend the web apps root, otherwise just use this path
+            if (directory.startsWith(File.separator)) {
+                realPath = rootPath + File.separator + directory + relativePath;
+            } else {
+                realPath = directory;
+            }
+            realPath = realPath.replaceAll("\\\\", "/");
 
 			// check the file and open it
 			File file = new File(realPath);
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel

Reply via email to