import org.sonar.server.user.DefaultUserService;
import org.sonar.server.user.NewUserNotifier;
+import javax.annotation.Nullable;
import javax.servlet.ServletContext;
/**
/**
* 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) {
@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());
}
}
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();
}
</init-param>
</filter>
+ <!-- order of execution is important -->
<filter-mapping>
<filter-name>ProfilingFilter</filter-name>
<url-pattern>/*</url-pattern>