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 2018/09/04 18:05:20 UTC

[isis] 01/02: ISIS-1895: fix class-loader initialization for skinny-war scenario

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 682091b20cb67aee4c56c014506cdb86afe61359
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue Sep 4 20:01:57 2018 +0200

    ISIS-1895: fix class-loader initialization for skinny-war scenario
    
    also removes the @WebListener annotation, to not force the underlying
    WebContextListener upon users
    
    Task-Url: https://issues.apache.org/jira/browse/ISIS-1895
---
 .../apache/isis/core/webapp/IsisWebAppContextListener.java  | 13 ++++++++-----
 .../isis/viewer/wicket/viewer/IsisWicketApplication.java    | 10 ++++++++--
 2 files changed, 16 insertions(+), 7 deletions(-)

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 a0bc0ee..b882ce9 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
@@ -19,7 +19,6 @@
 package org.apache.isis.core.webapp;
 
 import static org.apache.isis.commons.internal.base._With.acceptIfPresent;
-import static org.apache.isis.commons.internal.context._Context.setDefaultClassLoader;
 import static org.apache.isis.commons.internal.resources._Resource.putContextPathIfPresent;
 
 import java.util.ArrayList;
@@ -30,11 +29,11 @@ import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
 import javax.servlet.ServletException;
-import javax.servlet.annotation.WebListener;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import org.apache.isis.commons.internal.context._Context;
 import org.apache.isis.core.webapp.modules.WebModule;
 
 /**
@@ -47,10 +46,11 @@ import org.apache.isis.core.webapp.modules.WebModule;
  * Installs {@link WebModule}s on the ServletContext. 
  * </p>   
  *  
- * @since 2.0.0
+ * @since 2.0.0-M2
  *
  */
-@WebListener
+//@WebListener //[ahuber] to support Servlet 3.0 annotations @WebFilter, @WebListener or others 
+//with skinny war deployment requires additional configuration, so for now we disable this annotation
 public class IsisWebAppContextListener implements ServletContextListener {
     
     private static final Logger LOG = LoggerFactory.getLogger(IsisWebAppContextListener.class);
@@ -65,8 +65,11 @@ public class IsisWebAppContextListener implements ServletContextListener {
         final ServletContext servletContext = event.getServletContext();
         
         LOG.info("=== PHASE 1 === Setting up ServletContext parameters");
+  
+        //[ahuber] set the ServletContext initializing thread as preliminary default until overridden by
+        // IsisWicketApplication#init() or others that better know what ClassLoader to use as application default.
+        _Context.setDefaultClassLoader(Thread.currentThread().getContextClassLoader(), false);
         
-        setDefaultClassLoader(this.getClass().getClassLoader(), true);
         putContextPathIfPresent(servletContext.getContextPath());
         
         final IsisWebAppConfigProvider configProvider = new IsisWebAppConfigProvider();
diff --git a/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/IsisWicketApplication.java b/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/IsisWicketApplication.java
index 66de39a..7f64bcc 100644
--- a/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/IsisWicketApplication.java
+++ b/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/IsisWicketApplication.java
@@ -75,6 +75,7 @@ import org.slf4j.LoggerFactory;
 import org.wicketstuff.select2.ApplicationSettings;
 
 import org.apache.isis.commons.internal.collections._Lists;
+import org.apache.isis.commons.internal.context._Context;
 import org.apache.isis.core.commons.authentication.AuthenticationSession;
 import org.apache.isis.core.commons.config.IsisConfiguration;
 import org.apache.isis.core.commons.config.IsisConfigurationDefault;
@@ -133,7 +134,7 @@ import net.ftlines.wicketsource.WicketSource;
  *
  * <p>
  * Its main responsibility is to allow the set of {@link ComponentFactory}s used
- * to render the domain objects to be registered. This type of customisation is
+ * to render the domain objects to be registered. This type of customization is
  * common place. At a more fundamental level, also allows the {@link Page}
  * implementation for each {@link PageType page type} to be overridden. This is
  * probably less common, because CSS can also be used for this purpose.
@@ -147,7 +148,7 @@ import net.ftlines.wicketsource.WicketSource;
  * make the {@link ComponentFactory} defined within it available.
  *
  * <p>
- * Alternatively, {@link ComponentFactory}s can be specified by overridding {@link #newIsisWicketModule()}.
+ * Alternatively, {@link ComponentFactory}s can be specified by overriding {@link #newIsisWicketModule()}.
  * This mechanism allows a number of other aspects to be customized.
  */
 public class IsisWicketApplication
@@ -302,6 +303,11 @@ implements ComponentFactoryRegistryAccessor, PageClassRegistryAccessor, WicketVi
      */
     @Override
     protected void init() {
+        
+        //[ahuber] the implementing class is assumed to be loaded be a class-loader
+        // that's suitable for the entire web-application to use as default.
+        _Context.setDefaultClassLoader(this.getClass().getClassLoader(), true);
+        
         List<Future<Object>> futures = null;
         try {
             super.init();