aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2016-03-24 10:42:38 +0100
committerSimon Brandhof <simon.brandhof@sonarsource.com>2016-03-24 21:14:17 +0100
commit80d64d20e5fe3980b0057030a35368fc83ba0984 (patch)
treeda565be616e25f684263e1da33845fdfd114d386
parent637706156ca70cba5ae550f105bff4cfba92685e (diff)
downloadsonarqube-80d64d20e5fe3980b0057030a35368fc83ba0984.tar.gz
sonarqube-80d64d20e5fe3980b0057030a35368fc83ba0984.zip
Correctly stop server when an error is raised during startup
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/RubyRailsContextListener.java13
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/RubyRailsContextListenerTest.java15
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/web.xml8
3 files changed, 28 insertions, 8 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/RubyRailsContextListener.java b/server/sonar-server/src/main/java/org/sonar/server/platform/RubyRailsContextListener.java
index 3f66d39afbe..3f8fb0cd0e9 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/RubyRailsContextListener.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/RubyRailsContextListener.java
@@ -19,8 +19,11 @@
*/
package org.sonar.server.platform;
+import com.google.common.base.Throwables;
import javax.servlet.ServletContextEvent;
+import org.jruby.rack.RackApplicationFactory;
import org.jruby.rack.rails.RailsServletContextListener;
+import org.jruby.rack.servlet.ServletRackContext;
/**
* Overriding {@link RailsServletContextListener} allows to disable initialization of Ruby on Rails
@@ -35,4 +38,14 @@ public class RubyRailsContextListener extends RailsServletContextListener {
super.contextInitialized(event);
}
}
+
+ // Always stop server when an error is raised during startup.
+ // By default Rack only logs an error (see org.jruby.rack.RackServletContextListener#handleInitializationException()).
+ // Rack propagates exceptions if the properties jruby.rack.exception or jruby.rack.error are set to true.
+ // Unfortunately we didn't succeed in defining these properties, so the method is overridden here.
+ // Initial need: SONAR-6171
+ @Override
+ protected void handleInitializationException(Exception e, RackApplicationFactory factory, ServletRackContext rackContext) {
+ throw Throwables.propagate(e);
+ }
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/RubyRailsContextListenerTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/RubyRailsContextListenerTest.java
index 4e2cb8cb9db..976d7c73aac 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/RubyRailsContextListenerTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/RubyRailsContextListenerTest.java
@@ -19,8 +19,13 @@
*/
package org.sonar.server.platform;
+import java.io.IOException;
import javax.servlet.ServletContextEvent;
+import org.jruby.rack.RackApplicationFactory;
+import org.jruby.rack.servlet.ServletRackContext;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
import static java.lang.Boolean.TRUE;
@@ -34,6 +39,9 @@ import static org.mockito.Mockito.when;
public class RubyRailsContextListenerTest {
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
ServletContextEvent event = mock(ServletContextEvent.class, Mockito.RETURNS_DEEP_STUBS);
RubyRailsContextListener underTest = new RubyRailsContextListener();
@@ -54,4 +62,11 @@ public class RubyRailsContextListenerTest {
// See RailsServletContextListener -> RackServletContextListener
verify(event.getServletContext()).setAttribute(eq("rack.factory"), anyObject());
}
+
+ @Test
+ public void always_propagates_initialization_errors() {
+ expectedException.expect(RuntimeException.class);
+
+ underTest.handleInitializationException(new IOException(), mock(RackApplicationFactory.class), mock(ServletRackContext.class));
+ }
}
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/web.xml b/server/sonar-web/src/main/webapp/WEB-INF/web.xml
index 5810000c72a..4bcacb4effd 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/web.xml
+++ b/server/sonar-web/src/main/webapp/WEB-INF/web.xml
@@ -30,14 +30,6 @@
<param-name>jruby.rack.logging</param-name>
<param-value>slf4j</param-value>
</context-param>
- <context-param>
- <param-name>jruby.rack.error</param-name>
- <param-value>true</param-value>
- </context-param>
- <context-param>
- <param-name>jruby.rack.exception</param-name>
- <param-value>true</param-value>
- </context-param>
<filter>
<filter-name>ServletFilters</filter-name>