You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2019/01/23 19:01:20 UTC
[isis] branch 2033-IoC updated: ISIS-2033: adds some early sanity
check, whether critical services are managed by CDI
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch 2033-IoC
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/2033-IoC by this push:
new 627447f ISIS-2033: adds some early sanity check, whether critical services are managed by CDI
627447f is described below
commit 627447f322900ef0baf0c954528040a6f3be5389
Author: Andi Huber <ah...@apache.org>
AuthorDate: Wed Jan 23 20:01:13 2019 +0100
ISIS-2033: adds some early sanity check, whether critical services are
managed by CDI
Task-Url: https://issues.apache.org/jira/browse/ISIS-2033
---
.../org/apache/isis/config/AppConfigLocator.java | 49 +++++++++++++++++++++-
.../core/webapp/IsisWebAppContextListener.java | 9 ++--
2 files changed, 53 insertions(+), 5 deletions(-)
diff --git a/core/config/src/main/java/org/apache/isis/config/AppConfigLocator.java b/core/config/src/main/java/org/apache/isis/config/AppConfigLocator.java
index bf378f9..d96e913 100644
--- a/core/config/src/main/java/org/apache/isis/config/AppConfigLocator.java
+++ b/core/config/src/main/java/org/apache/isis/config/AppConfigLocator.java
@@ -18,10 +18,16 @@
*/
package org.apache.isis.config;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+
import org.apache.isis.commons.internal.cdi._CDI;
+import org.apache.isis.commons.internal.collections._Sets;
import org.apache.isis.commons.internal.context._Context;
import org.apache.isis.commons.internal.context._Plugin;
import org.apache.isis.commons.internal.debug._Probe;
+import org.apache.isis.commons.internal.exceptions._Exceptions;
import org.apache.isis.core.commons.exceptions.IsisException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,6 +46,19 @@ public final class AppConfigLocator {
// -- HELPER
+ // for sanity check
+ private final static Set<String> criticalServices() {
+ return _Sets.newHashSet(_Sets.of(
+ "org.apache.isis.applib.services.registry.ServiceRegistry",
+ "org.apache.isis.config.IsisConfiguration",
+ "org.apache.isis.core.runtime.system.session.IsisSessionFactory",
+ "org.apache.isis.core.security.authentication.manager.AuthenticationManager",
+ "org.apache.isis.core.security.authorization.manager.AuthorizationManager",
+ "org.apache.isis.core.metamodel.specloader.SpecificationLoader",
+ "org.apache.isis.core.runtime.system.persistence.PersistenceSessionFactory"
+ ));
+ }
+
private final static _Probe probe =
_Probe.unlimited().label("AppConfigLocator");
@@ -56,7 +75,35 @@ public final class AppConfigLocator {
}
});
- // TODO ensure critical services are managed by CDI
+
+ // ensure critical services are managed by CDI
+ final Set<String> managedTypes = new HashSet<>();
+ for(String serviceClassName : criticalServices()) {
+ try {
+ val type = _Context.loadClassAndInitialize(serviceClassName);
+
+ _CDI.getSingleton(type);
+
+ probe.println("SANITY-CHECK Critical service managed by CDI %s", type.getSimpleName());
+ managedTypes.add(serviceClassName);
+
+ } catch (Exception e) {
+ probe.println("failed to resolve bean %s cause: %s", serviceClassName, e.getMessage());
+ }
+ }
+
+
+ val criticalServicesNotManaged = criticalServices();
+ criticalServicesNotManaged.removeAll(managedTypes);
+ if(criticalServicesNotManaged.size()>0) {
+
+ val servicesLiteral = criticalServicesNotManaged.stream()
+ .collect(Collectors.joining(", "));
+
+ throw _Exceptions.unrecoverable(
+ String.format("Some critical services are not managed by CDI: {%s}", servicesLiteral));
+ }
+
return appConfig;
}
diff --git a/core/runtime/src/main/java/org/apache/isis/core/webapp/IsisWebAppContextListener.java b/core/runtime/src/main/java/org/apache/isis/core/webapp/IsisWebAppContextListener.java
index fe01c21..ad8159e 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/webapp/IsisWebAppContextListener.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/webapp/IsisWebAppContextListener.java
@@ -31,12 +31,14 @@ import javax.servlet.ServletContextListener;
import javax.servlet.ServletException;
import org.apache.isis.applib.services.registry.ServiceRegistry;
+import org.apache.isis.commons.internal.base._Blackhole;
import org.apache.isis.commons.internal.base._With;
import org.apache.isis.commons.internal.cdi._CDI;
import org.apache.isis.commons.internal.context._Context;
import org.apache.isis.config.AppConfigLocator;
import org.apache.isis.config.IsisConfiguration;
import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.runtime.system.session.IsisSessionFactory;
import org.apache.isis.core.security.authentication.manager.AuthenticationManager;
import org.apache.isis.core.security.authorization.manager.AuthorizationManager;
import org.apache.isis.core.webapp.modules.WebModule;
@@ -73,6 +75,8 @@ public class IsisWebAppContextListener implements ServletContextListener {
_With.requires(_CDI.getSingleton(ServiceRegistry.class), "ServiceRegistry");
_With.requires(_CDI.getSingleton(AuthenticationManager.class), "AuthenticationManager");
_With.requires(_CDI.getSingleton(AuthorizationManager.class), "AuthorizationManager");
+ _With.requires(_CDI.getSingleton(IsisSessionFactory.class), "IsisSessionFactory");
+
// TODO list registered beans
@@ -95,10 +99,7 @@ public class IsisWebAppContextListener implements ServletContextListener {
// finalize the config (build and regard immutable)
// as a side-effect bootstrap CDI, if the environment we are running on does not already have its own
- AppConfigLocator.getAppConfig();
-
- verifyCDISetup();
-
+ _Blackhole.consume(AppConfigLocator.getAppConfig());
LOG.info("=== PHASE 2 === Preparing the ServletContext");