Title: [911] trunk/rails-integration/src/main/java/org/jruby/webapp/RailsServlet.
java: Improve error handling
- Revision
- 911
- Author
- tantalon
- Date
- 2008-02-17 16:06:37 -0500 (Sun, 17 Feb 2008)
Log Message
Improve error handling
Modified Paths
Diff
Modified: trunk/rails-integration/src/main/java/org/jruby/webapp/RailsServlet.java (910 => 911)
--- trunk/rails-integration/src/main/java/org/jruby/webapp/RailsServlet.java 2008-02-17 20:45:02 UTC (rev 910)
+++ trunk/rails-integration/src/main/java/org/jruby/webapp/RailsServlet.java 2008-02-17 21:06:37 UTC (rev 911)
@@ -38,18 +38,6 @@
* Process the HTTP request.
*/
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- try {
- serviceRequest(request, response);
- } catch (ServletException e) {
- throw e;
- } catch (IOException e) {
- throw e;
- } catch (Exception e) {
- throw new ServletException(e);
- }
- }
-
- protected void serviceRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
ObjectPool runtimePool = getRuntimePool();
Ruby runtime = null;
// long startTime = System.currentTimeMillis();
@@ -65,8 +53,24 @@
log("Warning: All JRuby processes in the pool are in use");
response.setHeader("Retry-After", Integer.toString(retryAfterOverloading));
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "The server is currently overloaded, please try again later");
+ } catch (ServletException e) {
+ // handled by the container, but log it here just to be safe
+ log(e.getMessage());
+ throw e;
+ } catch (IOException e) {
+ // handled by the container
+ throw e;
+ } catch (Exception e) {
+ // unexpected failure
+ String action = "" == null) ? "initialise runtime" : "invoke rails";
+ log("Failure to " + action + ": " + e.getMessage(), e);
+ throw new ServletException("Failure to " + action + ", please see the log for more details");
} finally {
- if (runtime != null) runtimePool.returnObject(runtime);
+ try {
+ if (runtime != null) runtimePool.returnObject(runtime);
+ } catch (Exception e) {
+ log("Warning: Failed to return JRuby process to the pool: " + e.getMessage());
+ }
}
// log("Invocation time: " + (System.currentTimeMillis() - startTime) + "ms");
}
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel