]> source.dussan.org Git - sonarqube.git/commitdiff
Fix HTTP failure during server startup
authorSimon Brandhof <simon.brandhof@gmail.com>
Fri, 20 Dec 2013 17:06:51 +0000 (18:06 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Fri, 20 Dec 2013 17:07:54 +0000 (18:07 +0100)
sonar-server/src/main/java/org/sonar/server/platform/Platform.java
sonar-server/src/main/java/org/sonar/server/platform/ProfilingFilter.java
sonar-server/src/main/java/org/sonar/server/ui/DatabaseSessionFilter.java
sonar-server/src/main/webapp/WEB-INF/web.xml

index 2201d7f10c5add6427e7b3b6b9b1a137a6dfb6de..b49b0df97edf3b624cbdf17474012152f92ff644 100644 (file)
@@ -105,6 +105,7 @@ import org.sonar.server.ui.*;
 import org.sonar.server.user.DefaultUserService;
 import org.sonar.server.user.NewUserNotifier;
 
+import javax.annotation.Nullable;
 import javax.servlet.ServletContext;
 
 /**
@@ -139,8 +140,12 @@ public final class Platform {
   /**
    * Used by ruby code
    */
+  @Nullable
   public static <T> T component(Class<T> type) {
-    return getInstance().getContainer().getComponentByType(type);
+    if (INSTANCE.started) {
+      return INSTANCE.getContainer().getComponentByType(type);
+    }
+    return null;
   }
 
   public void init(ServletContext servletContext) {
index 2d91f7ed3503b88ed99ee7e017a3311ea91fdf9d..a46a0751bddaf1cd86d1ff6fb8b984a2c4592df1 100644 (file)
@@ -113,11 +113,10 @@ public class ProfilingFilter implements Filter {
 
   @VisibleForTesting
   Profiling getProfiling() {
-    try {
-      return (Profiling) Platform.component(Profiling.class);
-    } catch(Exception initException) {
-      LOG.error("Could not initialize platform profiling", initException);
-      return new Profiling(new Settings());
+    Profiling profiling = Platform.component(Profiling.class);
+    if (profiling != null) {
+      return profiling;
     }
+    return new Profiling(new Settings());
   }
 }
index d05bbeb6d02ce9672a4f0e111e2abcb70a9d2128..f6f0893834f754c2f92e131f8ab3aad30b270470 100644 (file)
@@ -35,7 +35,7 @@ public class DatabaseSessionFilter implements Filter {
   public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
     chain.doFilter(request, response);
 
-    DatabaseSessionFactory sessionFactory = Platform.getInstance().getContainer().getComponentByType(DatabaseSessionFactory.class);
+    DatabaseSessionFactory sessionFactory = Platform.component(DatabaseSessionFactory.class);
     if (sessionFactory != null) {
       sessionFactory.clear();
     }
index eede7da7d4e2573261e866d17b525ee8fc1899b5..6f130d298c4e6731a330f2f83f60016e97067332 100644 (file)
@@ -56,6 +56,7 @@
     </init-param>
   </filter>
 
+  <!-- order of execution is important -->
   <filter-mapping>
     <filter-name>ProfilingFilter</filter-name>
     <url-pattern>/*</url-pattern>