*/
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
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);
+ }
}
*/
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;
public class RubyRailsContextListenerTest {
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
ServletContextEvent event = mock(ServletContextEvent.class, Mockito.RETURNS_DEEP_STUBS);
RubyRailsContextListener underTest = new RubyRailsContextListener();
// 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));
+ }
}
<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>