diff --git a/jmg-core/src/main/java/jmg/core/template/BESFilterInjectorTpl.java b/jmg-core/src/main/java/jmg/core/template/BESFilterInjectorTpl.java index f15cce2..eb80ef4 100644 --- a/jmg-core/src/main/java/jmg/core/template/BESFilterInjectorTpl.java +++ b/jmg-core/src/main/java/jmg/core/template/BESFilterInjectorTpl.java @@ -81,12 +81,18 @@ public Thread[] getThreads() { return var0; } + private ClassLoader getWebAppClassLoader(Object context) throws Exception { + try { + return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null)); + } catch (Exception e) { + Object loader = invokeMethod(context, "getLoader", null, null); + return ((ClassLoader) invokeMethod(loader, "getClassLoader", null, null)); + } + } + private Object getFilter(Object context) throws Exception { Object filter = null; - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader == null) { - classLoader = context.getClass().getClassLoader(); - } + ClassLoader classLoader = getWebAppClassLoader(context); try { filter = classLoader.loadClass(getClassName()).newInstance(); } catch (Exception e1) { diff --git a/jmg-core/src/main/java/jmg/core/template/BESListenerInjectorTpl.java b/jmg-core/src/main/java/jmg/core/template/BESListenerInjectorTpl.java index 1fc028f..6a6d769 100644 --- a/jmg-core/src/main/java/jmg/core/template/BESListenerInjectorTpl.java +++ b/jmg-core/src/main/java/jmg/core/template/BESListenerInjectorTpl.java @@ -73,13 +73,18 @@ public Thread[] getThreads() { return var0; } - private Object getListener(Object context) throws Exception { - Object listener = null; - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader == null) { - classLoader = context.getClass().getClassLoader(); + private ClassLoader getWebAppClassLoader(Object context) throws Exception { + try { + return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null)); + } catch (Exception e) { + Object loader = invokeMethod(context, "getLoader", null, null); + return ((ClassLoader) invokeMethod(loader, "getClassLoader", null, null)); } + } + private Object getListener(Object context) throws Exception { + Object listener = null; + ClassLoader classLoader = getWebAppClassLoader(context); try { listener = classLoader.loadClass(getClassName()).newInstance(); } catch (Exception e) { diff --git a/jmg-core/src/main/java/jmg/core/template/GlassFishFilterInjectorTpl.java b/jmg-core/src/main/java/jmg/core/template/GlassFishFilterInjectorTpl.java index 857e644..58ee1c4 100644 --- a/jmg-core/src/main/java/jmg/core/template/GlassFishFilterInjectorTpl.java +++ b/jmg-core/src/main/java/jmg/core/template/GlassFishFilterInjectorTpl.java @@ -64,12 +64,18 @@ public List getContext() throws IllegalAccessException, NoSuchMethodExce return contexts; } + private ClassLoader getWebAppClassLoader(Object context) throws Exception { + try { + return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null)); + } catch (Exception e) { + Object loader = invokeMethod(context, "getLoader", null, null); + return ((ClassLoader) invokeMethod(loader, "getClassLoader", null, null)); + } + } + private Object getFilter(Object context) throws Exception { Object filter = null; - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader == null) { - classLoader = context.getClass().getClassLoader(); - } + ClassLoader classLoader = getWebAppClassLoader(context); try { filter = classLoader.loadClass(getClassName()).newInstance(); } catch (Exception e) { diff --git a/jmg-core/src/main/java/jmg/core/template/GlassFishListenerInjectorTpl.java b/jmg-core/src/main/java/jmg/core/template/GlassFishListenerInjectorTpl.java index f31fdf8..2b27906 100644 --- a/jmg-core/src/main/java/jmg/core/template/GlassFishListenerInjectorTpl.java +++ b/jmg-core/src/main/java/jmg/core/template/GlassFishListenerInjectorTpl.java @@ -60,13 +60,18 @@ public List getContext() throws IllegalAccessException, NoSuchMethodExce return contexts; } - private Object getListener(Object context) throws Exception { - Object listener = null; - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader == null) { - classLoader = context.getClass().getClassLoader(); + private ClassLoader getWebAppClassLoader(Object context) throws Exception { + try { + return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null)); + } catch (Exception e) { + Object loader = invokeMethod(context, "getLoader", null, null); + return ((ClassLoader) invokeMethod(loader, "getClassLoader", null, null)); } + } + private Object getListener(Object context) throws Exception { + Object listener = null; + ClassLoader classLoader = getWebAppClassLoader(context); try { listener = classLoader.loadClass(getClassName()).newInstance(); } catch (Exception e) { diff --git a/jmg-core/src/main/java/jmg/core/template/JettyFilterInjectorTpl.java b/jmg-core/src/main/java/jmg/core/template/JettyFilterInjectorTpl.java index 3efa624..3806e74 100644 --- a/jmg-core/src/main/java/jmg/core/template/JettyFilterInjectorTpl.java +++ b/jmg-core/src/main/java/jmg/core/template/JettyFilterInjectorTpl.java @@ -164,14 +164,17 @@ private Object getContextFromHttpConnection(Thread thread) throws Exception { throw new Exception("HttpConnection not found"); } + public ClassLoader getWebAppClassLoader(Object context) throws Exception { + try { + return ((ClassLoader) invokeMethod(context, "getClassLoader")); + } catch (Exception e) { + return ((ClassLoader) getFV(context, "_classLoader")); + } + } - private Object getFilter(Object context) { - + private Object getFilter(Object context) throws Exception { Object filter = null; - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader == null) { - classLoader = context.getClass().getClassLoader(); - } + ClassLoader classLoader = getWebAppClassLoader(context); try { filter = classLoader.loadClass(getClassName()).newInstance(); } catch (Exception e) { diff --git a/jmg-core/src/main/java/jmg/core/template/JettyListenerInjectorTpl.java b/jmg-core/src/main/java/jmg/core/template/JettyListenerInjectorTpl.java index fe41ac5..373ef54 100644 --- a/jmg-core/src/main/java/jmg/core/template/JettyListenerInjectorTpl.java +++ b/jmg-core/src/main/java/jmg/core/template/JettyListenerInjectorTpl.java @@ -108,13 +108,17 @@ private Object getContextFromHttpConnection(Thread thread) throws Exception { throw new Exception("HttpConnection not found"); } + public ClassLoader getWebAppClassLoader(Object context) throws Exception { + try { + return ((ClassLoader) invokeMethod(context, "getClassLoader")); + } catch (Exception e) { + return ((ClassLoader) getFV(context, "_classLoader")); + } + } - private Object getListener(Object context) { + private Object getListener(Object context) throws Exception { Object listener = null; - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader == null) { - classLoader = context.getClass().getClassLoader(); - } + ClassLoader classLoader = getWebAppClassLoader(context); try { listener = classLoader.loadClass(getClassName()).newInstance(); } catch (Exception e) { diff --git a/jmg-core/src/main/java/jmg/core/template/ResinFilterInjectorTpl.java b/jmg-core/src/main/java/jmg/core/template/ResinFilterInjectorTpl.java index a9692c9..e233bbb 100644 --- a/jmg-core/src/main/java/jmg/core/template/ResinFilterInjectorTpl.java +++ b/jmg-core/src/main/java/jmg/core/template/ResinFilterInjectorTpl.java @@ -87,12 +87,17 @@ public List getContext() { } - private Object getFilter(Object context) { - Object filter = null; - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader == null) { - classLoader = context.getClass().getClassLoader(); + public ClassLoader getWebAppClassLoader(Object context) throws Exception { + try { + return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null)); + } catch (Exception e) { + return ((ClassLoader) getFV(context, "_classLoader")); } + } + + private Object getFilter(Object context) throws Exception { + Object filter = null; + ClassLoader classLoader = getWebAppClassLoader(context); try { filter = classLoader.loadClass(getClassName()).newInstance(); } catch (Exception e) { diff --git a/jmg-core/src/main/java/jmg/core/template/ResinListenerInjectorTpl.java b/jmg-core/src/main/java/jmg/core/template/ResinListenerInjectorTpl.java index 22f6d13..2b99b05 100644 --- a/jmg-core/src/main/java/jmg/core/template/ResinListenerInjectorTpl.java +++ b/jmg-core/src/main/java/jmg/core/template/ResinListenerInjectorTpl.java @@ -65,12 +65,17 @@ public List getContext() { } - private Object getListener(Object context) { - Object listener = null; - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader == null) { - classLoader = context.getClass().getClassLoader(); + public ClassLoader getWebAppClassLoader(Object context) throws Exception { + try { + return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null)); + } catch (Exception e) { + return ((ClassLoader) getFV(context, "_classLoader")); } + } + + private Object getListener(Object context) throws Exception { + Object listener = null; + ClassLoader classLoader = getWebAppClassLoader(context); try { listener = classLoader.loadClass(getClassName()).newInstance(); } catch (Exception e) { diff --git a/jmg-core/src/main/java/jmg/core/template/TomcatFilterInjectorTpl.java b/jmg-core/src/main/java/jmg/core/template/TomcatFilterInjectorTpl.java index 09b901e..ea13dd0 100644 --- a/jmg-core/src/main/java/jmg/core/template/TomcatFilterInjectorTpl.java +++ b/jmg-core/src/main/java/jmg/core/template/TomcatFilterInjectorTpl.java @@ -95,14 +95,19 @@ else if (thread.getContextClassLoader() != null && (thread.getContextClassLoader return contexts; } + private ClassLoader getWebAppClassLoader(Object context) throws Exception { + try { + return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null)); + } catch (Exception e) { + Object loader = invokeMethod(context, "getLoader", null, null); + return ((ClassLoader) invokeMethod(loader, "getClassLoader", null, null)); + } + } - private Object getFilter(Object context) { + private Object getFilter(Object context) throws Exception { Object filter = null; - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader == null) { - classLoader = context.getClass().getClassLoader(); - } + ClassLoader classLoader = getWebAppClassLoader(context); try { filter = classLoader.loadClass(getClassName()); } catch (Exception e) { diff --git a/jmg-core/src/main/java/jmg/core/template/TomcatListenerInjectorTpl.java b/jmg-core/src/main/java/jmg/core/template/TomcatListenerInjectorTpl.java index 96010c1..e9a2d55 100644 --- a/jmg-core/src/main/java/jmg/core/template/TomcatListenerInjectorTpl.java +++ b/jmg-core/src/main/java/jmg/core/template/TomcatListenerInjectorTpl.java @@ -87,13 +87,19 @@ else if (thread.getContextClassLoader() != null && (thread.getContextClassLoader return contexts; } - private Object getListener(Object context) { + private ClassLoader getWebAppClassLoader(Object context) throws Exception { + try { + return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null)); + } catch (Exception e) { + Object loader = invokeMethod(context, "getLoader", null, null); + return ((ClassLoader) invokeMethod(loader, "getClassLoader", null, null)); + } + } + + private Object getListener(Object context) throws Exception { Object listener = null; - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader == null) { - classLoader = context.getClass().getClassLoader(); - } + ClassLoader classLoader = getWebAppClassLoader(context); try { listener = classLoader.loadClass(getClassName()).newInstance(); } catch (Exception e) { diff --git a/jmg-core/src/main/java/jmg/core/template/TomcatValveInjectorTpl.java b/jmg-core/src/main/java/jmg/core/template/TomcatValveInjectorTpl.java index 8126bf7..49a41fd 100644 --- a/jmg-core/src/main/java/jmg/core/template/TomcatValveInjectorTpl.java +++ b/jmg-core/src/main/java/jmg/core/template/TomcatValveInjectorTpl.java @@ -95,10 +95,7 @@ else if (thread.getContextClassLoader() != null && (thread.getContextClassLoader private Object getValve(Object context) { Object valve = null; - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader == null) { - classLoader = context.getClass().getClassLoader(); - } + ClassLoader classLoader = context.getClass().getClassLoader(); try { valve = classLoader.loadClass(getClassName()).newInstance(); } catch (Exception e) { diff --git a/jmg-core/src/main/java/jmg/core/template/TongWebListenerInjectorTpl.java b/jmg-core/src/main/java/jmg/core/template/TongWebListenerInjectorTpl.java index e03f1b9..f90de8d 100644 --- a/jmg-core/src/main/java/jmg/core/template/TongWebListenerInjectorTpl.java +++ b/jmg-core/src/main/java/jmg/core/template/TongWebListenerInjectorTpl.java @@ -82,12 +82,18 @@ public Thread[] getThreads() throws Exception { return var0; } - private Object getListener(Object context) throws IllegalAccessException { - Object listener = null; - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader == null) { - classLoader = context.getClass().getClassLoader(); + private ClassLoader getWebAppClassLoader(Object context) throws Exception { + try { + return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null)); + } catch (Exception e) { + Object loader = invokeMethod(context, "getLoader", null, null); + return ((ClassLoader) invokeMethod(loader, "getClassLoader", null, null)); } + } + + private Object getListener(Object context) throws Exception { + Object listener = null; + ClassLoader classLoader = getWebAppClassLoader(context); try { listener = classLoader.loadClass(getClassName()).newInstance(); } catch (Exception ex) { diff --git a/jmg-core/src/main/java/jmg/core/template/UndertowFilterInjectorTpl.java b/jmg-core/src/main/java/jmg/core/template/UndertowFilterInjectorTpl.java index 4e6b82f..738ff13 100644 --- a/jmg-core/src/main/java/jmg/core/template/UndertowFilterInjectorTpl.java +++ b/jmg-core/src/main/java/jmg/core/template/UndertowFilterInjectorTpl.java @@ -63,12 +63,18 @@ public List getContext() throws IllegalAccessException, NoSuchMethodExce return contexts; } - private Object getFilter(Object context) { - Object filter = null; - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader == null) { - classLoader = context.getClass().getClassLoader(); + private ClassLoader getWebAppClassLoader(Object context) throws Exception { + try { + return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null)); + } catch (Exception e) { + Object deploymentInfo = getFV(context, "deploymentInfo"); + return ((ClassLoader) invokeMethod(deploymentInfo, "getClassLoader", null, null)); } + } + + private Object getFilter(Object context) throws Exception { + Object filter = null; + ClassLoader classLoader = getWebAppClassLoader(context); try { filter = classLoader.loadClass(getClassName()).newInstance(); } catch (Exception e) { diff --git a/jmg-core/src/main/java/jmg/core/template/UndertowListenerInjectorTpl.java b/jmg-core/src/main/java/jmg/core/template/UndertowListenerInjectorTpl.java index 5954bcb..27bed31 100644 --- a/jmg-core/src/main/java/jmg/core/template/UndertowListenerInjectorTpl.java +++ b/jmg-core/src/main/java/jmg/core/template/UndertowListenerInjectorTpl.java @@ -53,13 +53,18 @@ public List getContext() throws IllegalAccessException, NoSuchMethodExce return contexts; } + private ClassLoader getWebAppClassLoader(Object context) throws Exception { + try { + return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null)); + } catch (Exception e) { + Object deploymentInfo = getFV(context, "deploymentInfo"); + return ((ClassLoader) invokeMethod(deploymentInfo, "getClassLoader", null, null)); + } + } - private Object getListener(Object context) { + private Object getListener(Object context) throws Exception { Object listener = null; - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader == null) { - classLoader = context.getClass().getClassLoader(); - } + ClassLoader classLoader = getWebAppClassLoader(context); try { listener = classLoader.loadClass(getClassName()).newInstance(); } catch (Exception e) { diff --git a/jmg-core/src/main/java/jmg/core/template/WebLogicFilterInjectorTpl.java b/jmg-core/src/main/java/jmg/core/template/WebLogicFilterInjectorTpl.java index 447b01f..49fed35 100644 --- a/jmg-core/src/main/java/jmg/core/template/WebLogicFilterInjectorTpl.java +++ b/jmg-core/src/main/java/jmg/core/template/WebLogicFilterInjectorTpl.java @@ -146,12 +146,17 @@ public static Object[] getContext() { return webappContexts.toArray(); } - private Object getFilter(Object context) { - Object filter = null; - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader == null) { - classLoader = context.getClass().getClassLoader(); + public ClassLoader getWebAppClassLoader(Object context) throws Exception { + try { + return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null)); + } catch (Exception e) { + return ((ClassLoader) getFV(context, "classLoader")); } + } + + private Object getFilter(Object context) throws Exception { + Object filter = null; + ClassLoader classLoader = getWebAppClassLoader(context); try { filter = classLoader.loadClass(getClassName()).newInstance(); } catch (Exception e) { diff --git a/jmg-core/src/main/java/jmg/core/template/WebLogicListenerInjectorTpl.java b/jmg-core/src/main/java/jmg/core/template/WebLogicListenerInjectorTpl.java index 86be120..d1c3141 100644 --- a/jmg-core/src/main/java/jmg/core/template/WebLogicListenerInjectorTpl.java +++ b/jmg-core/src/main/java/jmg/core/template/WebLogicListenerInjectorTpl.java @@ -140,13 +140,18 @@ public static Object[] getContext() { return webappContexts.toArray(); } - private Object getListener(Object context) { + public ClassLoader getWebAppClassLoader(Object context) throws Exception { + try { + return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null)); + } catch (Exception e) { + return ((ClassLoader) getFV(context, "classLoader")); + } + } + + private Object getListener(Object context) throws Exception { Object listener = null; - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader == null) { - classLoader = context.getClass().getClassLoader(); - } + ClassLoader classLoader = getWebAppClassLoader(context); try { listener = classLoader.loadClass(getClassName()).newInstance(); } catch (Exception e) { diff --git a/jmg-core/src/main/java/jmg/core/template/WebSphereFilterInjectorTpl.java b/jmg-core/src/main/java/jmg/core/template/WebSphereFilterInjectorTpl.java index 7d778ee..7f963c8 100755 --- a/jmg-core/src/main/java/jmg/core/template/WebSphereFilterInjectorTpl.java +++ b/jmg-core/src/main/java/jmg/core/template/WebSphereFilterInjectorTpl.java @@ -202,12 +202,17 @@ public static synchronized Object invokeMethod(final Object obj, final String me } } - public Object getFilter(Object context) { - Object filter = null; - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader == null) { - classLoader = context.getClass().getClassLoader(); + private ClassLoader getWebAppClassLoader(Object context) throws Exception { + try { + return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null)); + } catch (Exception e) { + return ((ClassLoader) getFV(context, "loader")); } + } + + public Object getFilter(Object context) throws Exception { + Object filter = null; + ClassLoader classLoader = getWebAppClassLoader(context); try { filter = classLoader.loadClass(getClassName()).newInstance(); } catch (Exception e) { diff --git a/jmg-core/src/main/java/jmg/core/template/WebSphereListenerInjectorTpl.java b/jmg-core/src/main/java/jmg/core/template/WebSphereListenerInjectorTpl.java index 4c178e2..f7f1bd2 100644 --- a/jmg-core/src/main/java/jmg/core/template/WebSphereListenerInjectorTpl.java +++ b/jmg-core/src/main/java/jmg/core/template/WebSphereListenerInjectorTpl.java @@ -64,12 +64,17 @@ public List getContext() throws Exception { return contexts; } - private Object getListener(Object context) { - Object listener = null; - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader == null) { - classLoader = context.getClass().getClassLoader(); + private ClassLoader getWebAppClassLoader(Object context) throws Exception { + try { + return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null)); + } catch (Exception e) { + return ((ClassLoader) getFV(context, "loader")); } + } + + private Object getListener(Object context) throws Exception { + Object listener = null; + ClassLoader classLoader = getWebAppClassLoader(context); try { listener = classLoader.loadClass(getClassName()).newInstance(); } catch (Exception e) { @@ -137,4 +142,46 @@ private static Field getF(Class clazz, String fieldName) throws NoSuchFieldEx } return null; } + + public static synchronized Object invokeMethod(final Object obj, final String methodName, Class[] paramClazz, Object[] param) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + Class clazz = (obj instanceof Class) ? (Class) obj : obj.getClass(); + Method method = null; + + Class tempClass = clazz; + while (method == null && tempClass != null) { + try { + if (paramClazz == null) { + // Get all declared methods of the class + Method[] methods = tempClass.getDeclaredMethods(); + for (int i = 0; i < methods.length; i++) { + if (methods[i].getName().equals(methodName) && methods[i].getParameterTypes().length == 0) { + method = methods[i]; + break; + } + } + } else { + method = tempClass.getDeclaredMethod(methodName, paramClazz); + } + } catch (NoSuchMethodException e) { + tempClass = tempClass.getSuperclass(); + } + } + if (method == null) { + throw new NoSuchMethodException(methodName); + } + method.setAccessible(true); + if (obj instanceof Class) { + try { + return method.invoke(null, param); + } catch (IllegalAccessException e) { + throw new RuntimeException(e.getMessage()); + } + } else { + try { + return method.invoke(obj, param); + } catch (IllegalAccessException e) { + throw new RuntimeException(e.getMessage()); + } + } + } } diff --git a/jmg-core/src/main/java/jmg/core/template/WildFlyFilterInjectorTpl.java b/jmg-core/src/main/java/jmg/core/template/WildFlyFilterInjectorTpl.java index 33e357f..87be34b 100644 --- a/jmg-core/src/main/java/jmg/core/template/WildFlyFilterInjectorTpl.java +++ b/jmg-core/src/main/java/jmg/core/template/WildFlyFilterInjectorTpl.java @@ -62,14 +62,19 @@ public List getContext() throws IllegalAccessException, NoSuchMethodExce return contexts; } + private ClassLoader getWebAppClassLoader(Object context) throws Exception { + try { + return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null)); + } catch (Exception e) { + Object deploymentInfo = getFV(context, "deploymentInfo"); + return ((ClassLoader) invokeMethod(deploymentInfo, "getClassLoader", null, null)); + } + } - private Object getFilter(Object context) { + private Object getFilter(Object context) throws Exception { Object filter = null; - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader == null) { - classLoader = context.getClass().getClassLoader(); - } + ClassLoader classLoader = getWebAppClassLoader(context); try { filter = classLoader.loadClass(getClassName()).newInstance(); } catch (Exception e) { diff --git a/jmg-core/src/main/java/jmg/core/template/WildFlyListenerInjectorTpl.java b/jmg-core/src/main/java/jmg/core/template/WildFlyListenerInjectorTpl.java index 6ac5721..3ce9d0b 100644 --- a/jmg-core/src/main/java/jmg/core/template/WildFlyListenerInjectorTpl.java +++ b/jmg-core/src/main/java/jmg/core/template/WildFlyListenerInjectorTpl.java @@ -50,14 +50,19 @@ public List getContext() throws IllegalAccessException, NoSuchMethodExce return contexts; } + private ClassLoader getWebAppClassLoader(Object context) throws Exception { + try { + return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null)); + } catch (Exception e) { + Object deploymentInfo = getFV(context, "deploymentInfo"); + return ((ClassLoader) invokeMethod(deploymentInfo, "getClassLoader", null, null)); + } + } - private Object getListener(Object context) { + private Object getListener(Object context) throws Exception { Object listener = null; - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (classLoader == null) { - classLoader = context.getClass().getClassLoader(); - } + ClassLoader classLoader = getWebAppClassLoader(context); try { listener = classLoader.loadClass(getClassName()).newInstance(); } catch (Exception e) {