Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dab77b3

Browse files
authored
Merge pull request #38 from ReaJason/main
feat: support getWebAppClassLoader from context
2 parents 2b16edb + 4ce27b2 commit dab77b3

20 files changed

+234
-98
lines changed

‎jmg-core/src/main/java/jmg/core/template/BESFilterInjectorTpl.java‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,18 @@ public Thread[] getThreads() {
8181
return var0;
8282
}
8383

84+
private ClassLoader getWebAppClassLoader(Object context) throws Exception {
85+
try {
86+
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
87+
} catch (Exception e) {
88+
Object loader = invokeMethod(context, "getLoader", null, null);
89+
return ((ClassLoader) invokeMethod(loader, "getClassLoader", null, null));
90+
}
91+
}
92+
8493
private Object getFilter(Object context) throws Exception {
8594
Object filter = null;
86-
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
87-
if (classLoader == null) {
88-
classLoader = context.getClass().getClassLoader();
89-
}
95+
ClassLoader classLoader = getWebAppClassLoader(context);
9096
try {
9197
filter = classLoader.loadClass(getClassName()).newInstance();
9298
} catch (Exception e1) {

‎jmg-core/src/main/java/jmg/core/template/BESListenerInjectorTpl.java‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,18 @@ public Thread[] getThreads() {
7373
return var0;
7474
}
7575

76-
private Object getListener(Object context) throws Exception {
77-
Object listener = null;
78-
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
79-
if (classLoader == null) {
80-
classLoader = context.getClass().getClassLoader();
76+
private ClassLoader getWebAppClassLoader(Object context) throws Exception {
77+
try {
78+
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
79+
} catch (Exception e) {
80+
Object loader = invokeMethod(context, "getLoader", null, null);
81+
return ((ClassLoader) invokeMethod(loader, "getClassLoader", null, null));
8182
}
83+
}
8284

85+
private Object getListener(Object context) throws Exception {
86+
Object listener = null;
87+
ClassLoader classLoader = getWebAppClassLoader(context);
8388
try {
8489
listener = classLoader.loadClass(getClassName()).newInstance();
8590
} catch (Exception e) {

‎jmg-core/src/main/java/jmg/core/template/GlassFishFilterInjectorTpl.java‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,18 @@ public List<Object> getContext() throws IllegalAccessException, NoSuchMethodExce
6464
return contexts;
6565
}
6666

67+
private ClassLoader getWebAppClassLoader(Object context) throws Exception {
68+
try {
69+
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
70+
} catch (Exception e) {
71+
Object loader = invokeMethod(context, "getLoader", null, null);
72+
return ((ClassLoader) invokeMethod(loader, "getClassLoader", null, null));
73+
}
74+
}
75+
6776
private Object getFilter(Object context) throws Exception {
6877
Object filter = null;
69-
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
70-
if (classLoader == null) {
71-
classLoader = context.getClass().getClassLoader();
72-
}
78+
ClassLoader classLoader = getWebAppClassLoader(context);
7379
try {
7480
filter = classLoader.loadClass(getClassName()).newInstance();
7581
} catch (Exception e) {

‎jmg-core/src/main/java/jmg/core/template/GlassFishListenerInjectorTpl.java‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,18 @@ public List<Object> getContext() throws IllegalAccessException, NoSuchMethodExce
6060
return contexts;
6161
}
6262

63-
private Object getListener(Object context) throws Exception {
64-
Object listener = null;
65-
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
66-
if (classLoader == null) {
67-
classLoader = context.getClass().getClassLoader();
63+
private ClassLoader getWebAppClassLoader(Object context) throws Exception {
64+
try {
65+
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
66+
} catch (Exception e) {
67+
Object loader = invokeMethod(context, "getLoader", null, null);
68+
return ((ClassLoader) invokeMethod(loader, "getClassLoader", null, null));
6869
}
70+
}
6971

72+
private Object getListener(Object context) throws Exception {
73+
Object listener = null;
74+
ClassLoader classLoader = getWebAppClassLoader(context);
7075
try {
7176
listener = classLoader.loadClass(getClassName()).newInstance();
7277
} catch (Exception e) {

‎jmg-core/src/main/java/jmg/core/template/JettyFilterInjectorTpl.java‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,17 @@ private Object getContextFromHttpConnection(Thread thread) throws Exception {
164164
throw new Exception("HttpConnection not found");
165165
}
166166

167+
public ClassLoader getWebAppClassLoader(Object context) throws Exception {
168+
try {
169+
return ((ClassLoader) invokeMethod(context, "getClassLoader"));
170+
} catch (Exception e) {
171+
return ((ClassLoader) getFV(context, "_classLoader"));
172+
}
173+
}
167174

168-
private Object getFilter(Object context) {
169-
175+
private Object getFilter(Object context) throws Exception {
170176
Object filter = null;
171-
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
172-
if (classLoader == null) {
173-
classLoader = context.getClass().getClassLoader();
174-
}
177+
ClassLoader classLoader = getWebAppClassLoader(context);
175178
try {
176179
filter = classLoader.loadClass(getClassName()).newInstance();
177180
} catch (Exception e) {

‎jmg-core/src/main/java/jmg/core/template/JettyListenerInjectorTpl.java‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,17 @@ private Object getContextFromHttpConnection(Thread thread) throws Exception {
108108
throw new Exception("HttpConnection not found");
109109
}
110110

111+
public ClassLoader getWebAppClassLoader(Object context) throws Exception {
112+
try {
113+
return ((ClassLoader) invokeMethod(context, "getClassLoader"));
114+
} catch (Exception e) {
115+
return ((ClassLoader) getFV(context, "_classLoader"));
116+
}
117+
}
111118

112-
private Object getListener(Object context) {
119+
private Object getListener(Object context) throwsException{
113120
Object listener = null;
114-
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
115-
if (classLoader == null) {
116-
classLoader = context.getClass().getClassLoader();
117-
}
121+
ClassLoader classLoader = getWebAppClassLoader(context);
118122
try {
119123
listener = classLoader.loadClass(getClassName()).newInstance();
120124
} catch (Exception e) {

‎jmg-core/src/main/java/jmg/core/template/ResinFilterInjectorTpl.java‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,17 @@ public List<Object> getContext() {
8787

8888
}
8989

90-
privateObjectgetFilter(Object context) {
91-
Objectfilter = null;
92-
ClassLoaderclassLoader = Thread.currentThread().getContextClassLoader();
93-
if (classLoader == null) {
94-
classLoader = context.getClass().getClassLoader();
90+
publicClassLoadergetWebAppClassLoader(Object context)throwsException {
91+
try {
92+
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
93+
} catch (Exceptione) {
94+
return ((ClassLoader) getFV(context, "_classLoader"));
9595
}
96+
}
97+
98+
private Object getFilter(Object context) throws Exception {
99+
Object filter = null;
100+
ClassLoader classLoader = getWebAppClassLoader(context);
96101
try {
97102
filter = classLoader.loadClass(getClassName()).newInstance();
98103
} catch (Exception e) {

‎jmg-core/src/main/java/jmg/core/template/ResinListenerInjectorTpl.java‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,17 @@ public List<Object> getContext() {
6565

6666
}
6767

68-
privateObjectgetListener(Object context) {
69-
Objectlistener = null;
70-
ClassLoaderclassLoader = Thread.currentThread().getContextClassLoader();
71-
if (classLoader == null) {
72-
classLoader = context.getClass().getClassLoader();
68+
publicClassLoadergetWebAppClassLoader(Object context)throwsException {
69+
try {
70+
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
71+
} catch (Exceptione) {
72+
return ((ClassLoader) getFV(context, "_classLoader"));
7373
}
74+
}
75+
76+
private Object getListener(Object context) throws Exception {
77+
Object listener = null;
78+
ClassLoader classLoader = getWebAppClassLoader(context);
7479
try {
7580
listener = classLoader.loadClass(getClassName()).newInstance();
7681
} catch (Exception e) {

‎jmg-core/src/main/java/jmg/core/template/TomcatFilterInjectorTpl.java‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,19 @@ else if (thread.getContextClassLoader() != null && (thread.getContextClassLoader
9595
return contexts;
9696
}
9797

98+
private ClassLoader getWebAppClassLoader(Object context) throws Exception {
99+
try {
100+
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
101+
} catch (Exception e) {
102+
Object loader = invokeMethod(context, "getLoader", null, null);
103+
return ((ClassLoader) invokeMethod(loader, "getClassLoader", null, null));
104+
}
105+
}
98106

99-
private Object getFilter(Object context) {
107+
private Object getFilter(Object context) throwsException{
100108

101109
Object filter = null;
102-
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
103-
if (classLoader == null) {
104-
classLoader = context.getClass().getClassLoader();
105-
}
110+
ClassLoader classLoader = getWebAppClassLoader(context);
106111
try {
107112
filter = classLoader.loadClass(getClassName());
108113
} catch (Exception e) {

‎jmg-core/src/main/java/jmg/core/template/TomcatListenerInjectorTpl.java‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,19 @@ else if (thread.getContextClassLoader() != null && (thread.getContextClassLoader
8787
return contexts;
8888
}
8989

90-
private Object getListener(Object context) {
90+
private ClassLoader getWebAppClassLoader(Object context) throws Exception {
91+
try {
92+
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
93+
} catch (Exception e) {
94+
Object loader = invokeMethod(context, "getLoader", null, null);
95+
return ((ClassLoader) invokeMethod(loader, "getClassLoader", null, null));
96+
}
97+
}
98+
99+
private Object getListener(Object context) throws Exception {
91100

92101
Object listener = null;
93-
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
94-
if (classLoader == null) {
95-
classLoader = context.getClass().getClassLoader();
96-
}
102+
ClassLoader classLoader = getWebAppClassLoader(context);
97103
try {
98104
listener = classLoader.loadClass(getClassName()).newInstance();
99105
} catch (Exception e) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /