mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-21 22:50:42 +08:00
refactor: simplify code
This commit is contained in:
+16
-21
@@ -224,30 +224,25 @@ public class ApusicFilterInjector {
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) {
|
||||
try {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) throws Exception {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error invoking method: " + methodName, e);
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
|
||||
+16
-21
@@ -197,30 +197,25 @@ public class ApusicListenerInjector {
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) {
|
||||
try {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) throws Exception {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error invoking method: " + methodName, e);
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
|
||||
+16
-21
@@ -198,30 +198,25 @@ public class ApusicServletInjector {
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) {
|
||||
try {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) throws Exception {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error invoking method: " + methodName, e);
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
|
||||
+16
-21
@@ -218,30 +218,25 @@ public class BesFilterInjector {
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) {
|
||||
try {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) throws Exception {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error invoking method: " + methodName, e);
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
|
||||
+16
-21
@@ -232,30 +232,25 @@ public static void setFieldValue(final Object obj, final String fieldName, final
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) {
|
||||
try {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) throws Exception {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error invoking method: " + methodName, e);
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
|
||||
+16
-21
@@ -198,30 +198,25 @@ public class ResinFilterInjector {
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) {
|
||||
try {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) throws Exception {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error invoking method: " + methodName, e);
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
|
||||
+16
-21
@@ -182,30 +182,25 @@ public class ResinListenerInjector {
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) {
|
||||
try {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) throws Exception {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error invoking method: " + methodName, e);
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
|
||||
+16
-21
@@ -183,30 +183,25 @@ public class ResinServletInjector {
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) {
|
||||
try {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) throws Exception {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error invoking method: " + methodName, e);
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
|
||||
+16
-21
@@ -226,30 +226,25 @@ public class TomcatListenerInjector {
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) {
|
||||
try {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) throws Exception {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error invoking method: " + methodName, e);
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
|
||||
+16
-21
@@ -232,30 +232,25 @@ public class TongWebFilterInjector {
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) {
|
||||
try {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) throws Exception {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error invoking method: " + methodName, e);
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+16
-21
@@ -218,30 +218,25 @@ public class TongWebListenerInjector {
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) {
|
||||
try {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) throws Exception {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error invoking method: " + methodName, e);
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
|
||||
+17
-21
@@ -78,6 +78,7 @@ public class UndertowFilterInjector {
|
||||
return c + "(" + r + ")";
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
public Set<Object> getContext() throws Exception {
|
||||
Set<Object> contexts = new HashSet<Object>();
|
||||
Set<Thread> threads = Thread.getAllStackTraces().keySet();
|
||||
@@ -218,30 +219,25 @@ public class UndertowFilterInjector {
|
||||
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) {
|
||||
try {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) throws Exception {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error invoking method: " + methodName, e);
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
|
||||
+16
-21
@@ -191,30 +191,25 @@ public class UndertowListenerInjector {
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) {
|
||||
try {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) throws Exception {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error invoking method: " + methodName, e);
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
|
||||
+16
-21
@@ -213,30 +213,25 @@ public class UndertowServletInjector {
|
||||
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) {
|
||||
try {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) throws Exception {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error invoking method: " + methodName, e);
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
|
||||
+16
-21
@@ -191,30 +191,25 @@ public class WebLogicFilterInjector {
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) {
|
||||
try {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) throws Exception {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error invoking method: " + methodName, e);
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
|
||||
+16
-18
@@ -12,9 +12,9 @@ import java.util.*;
|
||||
public class ApusicFilterProbe {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("Duplicates")
|
||||
public String toString() {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
Map<String, List<Map<String, String>>> allFiltersData = new LinkedHashMap<String, List<Map<String, String>>>();
|
||||
Set<Object> contexts = null;
|
||||
try {
|
||||
contexts = getContext();
|
||||
@@ -24,6 +24,7 @@ public class ApusicFilterProbe {
|
||||
if (contexts == null || contexts.isEmpty()) {
|
||||
msg.append("context not found\n");
|
||||
} else {
|
||||
Map<String, List<Map<String, String>>> allFiltersData = new LinkedHashMap<String, List<Map<String, String>>>();
|
||||
for (Object context : contexts) {
|
||||
String contextRoot = getContextRoot(context);
|
||||
try {
|
||||
@@ -38,14 +39,15 @@ public class ApusicFilterProbe {
|
||||
return msg.toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
@SuppressWarnings({"unchecked", "Duplicates"})
|
||||
private List<Map<String, String>> collectFiltersData(Object context) throws Exception {
|
||||
// context -> com.apusic.web.container.WebContainer
|
||||
Map<String, Map<String, Object>> aggregatedData = new LinkedHashMap<>();
|
||||
// webModule -> com.apusic.deploy.runtime.WebModule
|
||||
Object webModule = getFieldValue(context, "webapp");
|
||||
Object[] filterMappings = (Object[]) invokeMethod(webModule, "getAllFilterMappings");
|
||||
Map<String, String> filterClassMap = new HashMap<>();
|
||||
|
||||
for (Object fm : filterMappings) {
|
||||
// fm -> com.apusic.deploy.runtime.FilterMapping
|
||||
String name = (String) invokeMethod(fm, "getFilterName");
|
||||
if (!aggregatedData.containsKey(name)) {
|
||||
Map<String, Object> info = new HashMap<>();
|
||||
@@ -58,15 +60,10 @@ public class ApusicFilterProbe {
|
||||
}
|
||||
Map<String, Object> info = aggregatedData.get(name);
|
||||
String urlPattern = (String) invokeMethod(fm, "getUrlPattern");
|
||||
if (urlPattern != null) {
|
||||
((Set<String>) info.get("urlPatterns")).add(urlPattern);
|
||||
}
|
||||
if (urlPattern != null && !urlPattern.isEmpty()) ((Set<String>) info.get("urlPatterns")).add(urlPattern);
|
||||
String servletName = (String) invokeMethod(fm, "getServletName");
|
||||
if (servletName != null) {
|
||||
((Set<String>) info.get("servletNames")).add(servletName);
|
||||
}
|
||||
if (servletName != null && !servletName.isEmpty()) ((Set<String>) info.get("servletNames")).add(servletName);
|
||||
}
|
||||
|
||||
List<Map<String, String>> result = new ArrayList<>();
|
||||
for (Map<String, Object> entry : aggregatedData.values()) {
|
||||
Map<String, String> finalInfo = new HashMap<>();
|
||||
@@ -92,10 +89,10 @@ public class ApusicFilterProbe {
|
||||
output.append("No filters found\n");
|
||||
} else {
|
||||
for (Map<String, String> info : filters) {
|
||||
appendIfPresent(output, "", info.get("filterName"), "");
|
||||
appendIfPresent(output, " -> ", info.get("filterClass"), "");
|
||||
appendIfPresent(output, " -> URL:", info.get("urlPatterns"), "");
|
||||
appendIfPresent(output, " -> Servlet:", info.get("servletNames"), "");
|
||||
appendIfPresent(output, "", info.get("filterName"));
|
||||
appendIfPresent(output, " -> ", info.get("filterClass"));
|
||||
appendIfPresent(output, " -> URL:", info.get("urlPatterns"));
|
||||
appendIfPresent(output, " -> Servlet:", info.get("servletNames"));
|
||||
output.append("\n");
|
||||
}
|
||||
}
|
||||
@@ -103,13 +100,13 @@ public class ApusicFilterProbe {
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
private void appendIfPresent(StringBuilder sb, String prefix, String value, String suffix) {
|
||||
private void appendIfPresent(StringBuilder sb, String prefix, String value) {
|
||||
if (value != null && !value.isEmpty()) {
|
||||
sb.append(prefix).append(value).append(suffix);
|
||||
sb.append(prefix).append(value);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
@SuppressWarnings("Duplicates")
|
||||
private String getContextRoot(Object context) {
|
||||
String r = null;
|
||||
try {
|
||||
@@ -131,6 +128,7 @@ public class ApusicFilterProbe {
|
||||
* context - webapp: com.apusic.deploy.runtime.WebModule
|
||||
* /usr/local/ass/lib/apusic.jar
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public Set<Object> getContext() throws Exception {
|
||||
Set<Object> contexts = new HashSet<Object>();
|
||||
Set<Thread> threads = Thread.getAllStackTraces().keySet();
|
||||
|
||||
+40
-65
@@ -38,32 +38,24 @@ public class GlassFishFilterProbe {
|
||||
return msg.toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({"unchecked", "Duplicates"})
|
||||
private List<Map<String, String>> collectFiltersData(Object context) throws Exception {
|
||||
// context -> org.apache.catalina.core.StandardContext
|
||||
Map<String, Map<String, Object>> aggregatedData = new LinkedHashMap<>();
|
||||
|
||||
List filterMaps = (List) invokeMethod(context, "findFilterMaps");
|
||||
if (filterMaps == null || filterMaps.isEmpty()) return Collections.emptyList();
|
||||
|
||||
Object[] filterDefs = (Object[]) invokeMethod(context, "findFilterDefs");
|
||||
|
||||
List<Object> filterMaps = (List<Object>) invokeMethod(context, "findFilterMaps");
|
||||
for (Object fm : filterMaps) {
|
||||
// fm -> org.apache.catalina.deploy.FilterMap
|
||||
String name = (String) invokeMethod(fm, "getFilterName");
|
||||
if (name == null) continue;
|
||||
if (!aggregatedData.containsKey(name)) {
|
||||
String filterClass = "N/A";
|
||||
if (filterDefs != null) {
|
||||
Object filterDef = invokeMethod(context, "findFilterDef", new Class[]{String.class}, new Object[]{name});
|
||||
try {
|
||||
filterClass = (String) invokeMethod(filterDef, "getFilterClass");
|
||||
} catch (Throwable throwable) {
|
||||
filterClass = (String) invokeMethod(filterDef, "getFilterClassName");
|
||||
}
|
||||
if (filterClass == null) {
|
||||
Object filterConfig = invokeMethod(context, "findFilterConfig", new Class[]{String.class}, new Object[]{name});
|
||||
Object filter = invokeMethod(filterConfig, "getFilter");
|
||||
if (filter != null) filterClass = filter.getClass().getName();
|
||||
}
|
||||
// filterDef -> org.apache.catalina.deploy.FilterDef
|
||||
Object filterDef = invokeMethod(context, "findFilterDef", new Class[]{String.class}, new Object[]{name});
|
||||
String filterClass = (String) invokeMethod(filterDef, "getFilterClassName");
|
||||
if (filterClass == null) {
|
||||
// filterConfig -> org.apache.catalina.core.ApplicationFilterConfig
|
||||
Object filterConfig = invokeMethod(context, "findFilterConfig", new Class[]{String.class}, new Object[]{name});
|
||||
Object filter = invokeMethod(filterConfig, "getFilter");
|
||||
if (filter != null) filterClass = filter.getClass().getName();
|
||||
}
|
||||
Map<String, Object> info = new HashMap<>();
|
||||
info.put("filterName", name);
|
||||
@@ -79,9 +71,7 @@ public class GlassFishFilterProbe {
|
||||
} catch (Exception e) {
|
||||
// Tomcat 5
|
||||
String urlPattern = (String) invokeMethod(fm, "getURLPattern");
|
||||
if (urlPattern != null) {
|
||||
urls = new String[]{urlPattern};
|
||||
}
|
||||
if (urlPattern != null) urls = new String[]{urlPattern};
|
||||
}
|
||||
if (urls != null) ((Set<String>) info.get("urlPatterns")).addAll(Arrays.asList(urls));
|
||||
String[] servletNames = null;
|
||||
@@ -90,9 +80,7 @@ public class GlassFishFilterProbe {
|
||||
} catch (Exception e) {
|
||||
// Tomcat 5
|
||||
String servletName = (String) invokeMethod(fm, "getServletName");
|
||||
if (servletName != null) {
|
||||
servletNames = new String[]{servletName};
|
||||
}
|
||||
if (servletName != null) servletNames = new String[]{servletName};
|
||||
}
|
||||
if (servletNames != null) ((Set<String>) info.get("servletNames")).addAll(Arrays.asList(servletNames));
|
||||
}
|
||||
@@ -124,10 +112,10 @@ public class GlassFishFilterProbe {
|
||||
output.append(filters.get(0).get("error")).append("\n");
|
||||
} else {
|
||||
for (Map<String, String> info : filters) {
|
||||
appendIfPresent(output, "", info.get("filterName"), "");
|
||||
appendIfPresent(output, " -> ", info.get("filterClass"), "");
|
||||
appendIfPresent(output, " -> URL:", info.get("urlPatterns"), "");
|
||||
appendIfPresent(output, " -> Servlet:", info.get("servletNames"), "");
|
||||
appendIfPresent(output, "", info.get("filterName"));
|
||||
appendIfPresent(output, " -> ", info.get("filterClass"));
|
||||
appendIfPresent(output, " -> URL:", info.get("urlPatterns"));
|
||||
appendIfPresent(output, " -> Servlet:", info.get("servletNames"));
|
||||
output.append("\n");
|
||||
}
|
||||
}
|
||||
@@ -135,22 +123,13 @@ public class GlassFishFilterProbe {
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
private void appendIfPresent(StringBuilder sb, String prefix, String value, String suffix) {
|
||||
private void appendIfPresent(StringBuilder sb, String prefix, String value) {
|
||||
if (value != null && !value.isEmpty()) {
|
||||
sb.append(prefix).append(value).append(suffix);
|
||||
sb.append(prefix).append(value);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
private static String repeatString(String str, int count) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < count; i++) {
|
||||
sb.append(str);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
@SuppressWarnings("Duplicates")
|
||||
private String getContextRoot(Object context) {
|
||||
String r = null;
|
||||
try {
|
||||
@@ -171,8 +150,9 @@ public class GlassFishFilterProbe {
|
||||
* com.sun.enterprise.web.WebModule
|
||||
* /xxx/modules/web-glue.jar
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public Set<Object> getContext() throws Exception {
|
||||
Set<Object> contexts = new HashSet<Object>();
|
||||
Set<Object> contexts = new HashSet<>();
|
||||
Set<Thread> threads = Thread.getAllStackTraces().keySet();
|
||||
for (Thread thread : threads) {
|
||||
if (thread.getName().contains("ContainerBackgroundProcessor")) {
|
||||
@@ -186,35 +166,30 @@ public class GlassFishFilterProbe {
|
||||
return contexts;
|
||||
}
|
||||
|
||||
public static Object invokeMethod(Object obj, String methodName) {
|
||||
public static Object invokeMethod(Object obj, String methodName) throws Exception {
|
||||
return invokeMethod(obj, methodName, null, null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) {
|
||||
try {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) throws Exception {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error invoking method: " + methodName, e);
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
|
||||
+23
-16
@@ -13,9 +13,9 @@ import java.util.*;
|
||||
public class JettyFilterProbe {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("Duplicates")
|
||||
public String toString() {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
Map<String, List<Map<String, String>>> allFiltersData = new LinkedHashMap<String, List<Map<String, String>>>();
|
||||
Set<Object> contexts = null;
|
||||
try {
|
||||
contexts = getContext();
|
||||
@@ -25,6 +25,7 @@ public class JettyFilterProbe {
|
||||
if (contexts == null || contexts.isEmpty()) {
|
||||
msg.append("context not found\n");
|
||||
} else {
|
||||
Map<String, List<Map<String, String>>> allFiltersData = new LinkedHashMap<String, List<Map<String, String>>>();
|
||||
for (Object context : contexts) {
|
||||
String contextRoot = getContextRoot(context);
|
||||
try {
|
||||
@@ -39,24 +40,37 @@ public class JettyFilterProbe {
|
||||
return msg.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* jetty6 -> org.mortbay.jetty.webapp.WebAppContext
|
||||
* jetty7+ -> org.eclipse.jetty.webapp.WebAppContext
|
||||
* org.eclipse.jetty.ee8.webapp.WebAppContext
|
||||
* org.eclipse.jetty.ee9.webapp.WebAppContext
|
||||
* org.eclipse.jetty.ee10.webapp.WebAppContext
|
||||
* org.eclipse.jetty.ee11.webapp.WebAppContext
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Map<String, String>> collectFiltersData(Object context) throws Exception {
|
||||
Map<String, Map<String, Object>> aggregatedData = new LinkedHashMap<>();
|
||||
|
||||
// servletHandler -> org.mortbay.jetty.servlet.ServletHandler(jetty 6)
|
||||
// servletHandler -> org.eclipse.jetty.servlet.ServletHandler(jetty 7+)
|
||||
Object servletHandler = getFieldValue(context, "_servletHandler");
|
||||
|
||||
Object[] filterMappings = (Object[]) invokeMethod(servletHandler, "getFilterMappings");
|
||||
if (filterMappings == null || filterMappings.length == 0) return Collections.emptyList();
|
||||
|
||||
Object[] filterHolders = (Object[]) invokeMethod(servletHandler, "getFilters");
|
||||
|
||||
for (Object mapping : filterMappings) {
|
||||
// mapping -> org.mortbay.jetty.servlet.FilterMapping(jetty 6)
|
||||
// mapping -> org.eclipse.jetty.servlet.FilterMapping(jetty 7+)
|
||||
String name = (String) invokeMethod(mapping, "getFilterName");
|
||||
if (name == null) continue;
|
||||
|
||||
if (!aggregatedData.containsKey(name)) {
|
||||
String filterClass = "N/A";
|
||||
if (filterHolders != null) {
|
||||
for (Object holder : filterHolders) {
|
||||
// hodler -> org.mortbay.jetty.servlet.FilterHolder(jetty 6)
|
||||
// hodler -> org.eclipse.jetty.servlet.FilterHolder(jetty 7+)
|
||||
String holderName = (String) invokeMethod(holder, "getName");
|
||||
if (!name.equals(holderName)) continue;
|
||||
String cls = (String) invokeMethod(holder, "getClassName");
|
||||
@@ -114,10 +128,10 @@ public class JettyFilterProbe {
|
||||
output.append(filters.get(0).get("error")).append("\n");
|
||||
} else {
|
||||
for (Map<String, String> info : filters) {
|
||||
appendIfPresent(output, "", info.get("filterName"), "");
|
||||
appendIfPresent(output, " -> ", info.get("filterClass"), "");
|
||||
appendIfPresent(output, " -> URL:", info.get("urlPatterns"), "");
|
||||
appendIfPresent(output, " -> Servlet:", info.get("servletNames"), "");
|
||||
appendIfPresent(output, "", info.get("filterName"));
|
||||
appendIfPresent(output, " -> ", info.get("filterClass"));
|
||||
appendIfPresent(output, " -> URL:", info.get("urlPatterns"));
|
||||
appendIfPresent(output, " -> Servlet:", info.get("servletNames"));
|
||||
output.append("\n");
|
||||
}
|
||||
}
|
||||
@@ -125,9 +139,9 @@ public class JettyFilterProbe {
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
private void appendIfPresent(StringBuilder sb, String prefix, String value, String suffix) {
|
||||
private void appendIfPresent(StringBuilder sb, String prefix, String value) {
|
||||
if (value != null && !value.isEmpty()) {
|
||||
sb.append(prefix).append(value).append(suffix);
|
||||
sb.append(prefix).append(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,13 +162,6 @@ public class JettyFilterProbe {
|
||||
return c + "(" + r + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* org.mortbay.jetty.webapp.WebAppContext
|
||||
* org.eclipse.jetty.webapp.WebAppContext
|
||||
* org.eclipse.jetty.ee8.webapp.WebAppContext
|
||||
* org.eclipse.jetty.ee9.webapp.WebAppContext
|
||||
* org.eclipse.jetty.ee10.webapp.WebAppContext
|
||||
*/
|
||||
public Set<Object> getContext() throws Exception {
|
||||
Set<Object> contexts = new HashSet<Object>();
|
||||
Set<Thread> threads = Thread.getAllStackTraces().keySet();
|
||||
|
||||
+31
-31
@@ -12,9 +12,9 @@ import java.util.*;
|
||||
public class ResinFilterProbe {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("Duplicates")
|
||||
public String toString() {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
Map<String, List<Map<String, String>>> allFiltersData = new LinkedHashMap<String, List<Map<String, String>>>();
|
||||
Set<Object> contexts = null;
|
||||
try {
|
||||
contexts = getContext();
|
||||
@@ -24,6 +24,7 @@ public class ResinFilterProbe {
|
||||
if (contexts == null || contexts.isEmpty()) {
|
||||
msg.append("context not found\n");
|
||||
} else {
|
||||
Map<String, List<Map<String, String>>> allFiltersData = new LinkedHashMap<String, List<Map<String, String>>>();
|
||||
for (Object context : contexts) {
|
||||
String contextRoot = getContextRoot(context);
|
||||
try {
|
||||
@@ -40,14 +41,18 @@ public class ResinFilterProbe {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Map<String, String>> collectFiltersData(Object context) throws Exception {
|
||||
// context -> com.caucho.server.webapp.Application
|
||||
Map<String, Map<String, Object>> aggregatedData = new LinkedHashMap<>();
|
||||
// filterMapper -> com.caucho.server.dispatch.FilterMapper
|
||||
Object filterMapper = getFieldValue(context, "_filterMapper");
|
||||
// filterManager -> com.caucho.server.dispatch.FilterManager
|
||||
Object filterManager = getFieldValue(context, "_filterManager");
|
||||
if (filterMapper == null) return Collections.emptyList();
|
||||
ArrayList<Object> filterMappings = (ArrayList<Object>) getFieldValue(filterMapper, "_filterMap");
|
||||
for (Object filterMapping : filterMappings) {
|
||||
// filterMapping -> com.caucho.server.dispatch.FilterMapping
|
||||
String filterName = (String) invokeMethod(filterMapping, "getFilterName", null, null);
|
||||
if (aggregatedData.get(filterName) == null) {
|
||||
if (!aggregatedData.containsKey(filterName)) {
|
||||
Map<String, Object> info = new HashMap<>();
|
||||
info.put("filterName", filterName);
|
||||
String filterClassName = (String) invokeMethod(filterMapping, "getFilterClassName", null, null);
|
||||
@@ -83,11 +88,11 @@ public class ResinFilterProbe {
|
||||
urlPatterns.add(urlPattern);
|
||||
}
|
||||
if (!urlPatterns.isEmpty()) {
|
||||
((Set) info.get("urlPatterns")).addAll(urlPatterns);
|
||||
((Set<String>) info.get("urlPatterns")).addAll(urlPatterns);
|
||||
}
|
||||
List<String> servletNames = (List<String>) getFieldValue(filterMapping, "_servletNames");
|
||||
if (servletNames != null && !servletNames.isEmpty()) {
|
||||
((Set) info.get("servletNames")).addAll(servletNames);
|
||||
((Set<String>) info.get("servletNames")).addAll(servletNames);
|
||||
}
|
||||
}
|
||||
List<Map<String, String>> result = new ArrayList<>();
|
||||
@@ -117,10 +122,10 @@ public class ResinFilterProbe {
|
||||
output.append(filters.get(0).get("error")).append("\n");
|
||||
} else {
|
||||
for (Map<String, String> info : filters) {
|
||||
appendIfPresent(output, "", info.get("filterName"), "");
|
||||
appendIfPresent(output, " -> ", info.get("filterClass"), "");
|
||||
appendIfPresent(output, " -> URL:", info.get("urlPatterns"), "");
|
||||
appendIfPresent(output, " -> Servlet:", info.get("servletNames"), "");
|
||||
appendIfPresent(output, "", info.get("filterName"));
|
||||
appendIfPresent(output, " -> ", info.get("filterClass"));
|
||||
appendIfPresent(output, " -> URL:", info.get("urlPatterns"));
|
||||
appendIfPresent(output, " -> Servlet:", info.get("servletNames"));
|
||||
output.append("\n");
|
||||
}
|
||||
}
|
||||
@@ -128,9 +133,9 @@ public class ResinFilterProbe {
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
private void appendIfPresent(StringBuilder sb, String prefix, String value, String suffix) {
|
||||
private void appendIfPresent(StringBuilder sb, String prefix, String value) {
|
||||
if (value != null && !value.isEmpty()) {
|
||||
sb.append(prefix).append(value).append(suffix);
|
||||
sb.append(prefix).append(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,30 +181,25 @@ public class ResinFilterProbe {
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) {
|
||||
try {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) throws Exception {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error invoking method: " + methodName, e);
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
|
||||
+37
-54
@@ -12,9 +12,9 @@ import java.util.*;
|
||||
public class TomcatFilterProbe {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("Duplicates")
|
||||
public String toString() {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
Map<String, List<Map<String, String>>> allFiltersData = new LinkedHashMap<String, List<Map<String, String>>>();
|
||||
Set<Object> contexts = null;
|
||||
try {
|
||||
contexts = getContext();
|
||||
@@ -24,6 +24,7 @@ public class TomcatFilterProbe {
|
||||
if (contexts == null || contexts.isEmpty()) {
|
||||
msg.append("context not found\n");
|
||||
} else {
|
||||
Map<String, List<Map<String, String>>> allFiltersData = new LinkedHashMap<String, List<Map<String, String>>>();
|
||||
for (Object context : contexts) {
|
||||
String contextRoot = getContextRoot(context);
|
||||
try {
|
||||
@@ -40,26 +41,22 @@ public class TomcatFilterProbe {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Map<String, String>> collectFiltersData(Object context) throws Exception {
|
||||
// context -> org.apache.catalina.core.StandardContext
|
||||
Map<String, Map<String, Object>> aggregatedData = new LinkedHashMap<>();
|
||||
|
||||
Object[] filterMaps = (Object[]) invokeMethod(context, "findFilterMaps");
|
||||
if (filterMaps == null || filterMaps.length == 0) return Collections.emptyList();
|
||||
|
||||
Object[] filterDefs = (Object[]) invokeMethod(context, "findFilterDefs");
|
||||
|
||||
for (Object fm : filterMaps) {
|
||||
// fm -> org.apache.tomcat.util.descriptor.web.FilterMap/org.apache.catalina.deploy.FilterMap
|
||||
String name = (String) invokeMethod(fm, "getFilterName");
|
||||
if (name == null) continue;
|
||||
if (!aggregatedData.containsKey(name)) {
|
||||
String filterClass = "N/A";
|
||||
if (filterDefs != null) {
|
||||
Object filterDef = invokeMethod(context, "findFilterDef", new Class[]{String.class}, new Object[]{name});
|
||||
filterClass = (String) invokeMethod(filterDef, "getFilterClass");
|
||||
if (filterClass == null) {
|
||||
Object filterConfig = invokeMethod(context, "findFilterConfig", new Class[]{String.class}, new Object[]{name});
|
||||
Object filter = invokeMethod(filterConfig, "getFilter");
|
||||
if (filter != null) filterClass = filter.getClass().getName();
|
||||
}
|
||||
// filterDef -> org.apache.tomcat.util.descriptor.web.FilterDef/org.apache.catalina.deploy.FilterDef
|
||||
Object filterDef = invokeMethod(context, "findFilterDef", new Class[]{String.class}, new Object[]{name});
|
||||
String filterClass = (String) invokeMethod(filterDef, "getFilterClass");
|
||||
if (filterClass == null) {
|
||||
// filterConfig -> org.apache.catalina.core.ApplicationFilterConfig
|
||||
Object filterConfig = invokeMethod(context, "findFilterConfig", new Class[]{String.class}, new Object[]{name});
|
||||
Object filter = invokeMethod(filterConfig, "getFilter");
|
||||
if (filter != null) filterClass = filter.getClass().getName();
|
||||
}
|
||||
Map<String, Object> info = new HashMap<>();
|
||||
info.put("filterName", name);
|
||||
@@ -73,7 +70,7 @@ public class TomcatFilterProbe {
|
||||
try {
|
||||
urls = (String[]) invokeMethod(fm, "getURLPatterns");
|
||||
} catch (Exception e) {
|
||||
// Tomcat 5
|
||||
// Tomcat 5 org.apache.catalina.deploy.FilterMap
|
||||
String urlPattern = (String) invokeMethod(fm, "getURLPattern");
|
||||
if (urlPattern != null) {
|
||||
urls = new String[]{urlPattern};
|
||||
@@ -84,7 +81,7 @@ public class TomcatFilterProbe {
|
||||
try {
|
||||
servletNames = (String[]) invokeMethod(fm, "getServletNames");
|
||||
} catch (Exception e) {
|
||||
// Tomcat 5
|
||||
// Tomcat 5 org.apache.catalina.deploy.FilterMap
|
||||
String servletName = (String) invokeMethod(fm, "getServletName");
|
||||
if (servletName != null) {
|
||||
servletNames = new String[]{servletName};
|
||||
@@ -120,10 +117,10 @@ public class TomcatFilterProbe {
|
||||
output.append(filters.get(0).get("error")).append("\n");
|
||||
} else {
|
||||
for (Map<String, String> info : filters) {
|
||||
appendIfPresent(output, "", info.get("filterName"), "");
|
||||
appendIfPresent(output, " -> ", info.get("filterClass"), "");
|
||||
appendIfPresent(output, " -> URL:", info.get("urlPatterns"), "");
|
||||
appendIfPresent(output, " -> Servlet:", info.get("servletNames"), "");
|
||||
appendIfPresent(output, "", info.get("filterName"));
|
||||
appendIfPresent(output, " -> ", info.get("filterClass"));
|
||||
appendIfPresent(output, " -> URL:", info.get("urlPatterns"));
|
||||
appendIfPresent(output, " -> Servlet:", info.get("servletNames"));
|
||||
output.append("\n");
|
||||
}
|
||||
}
|
||||
@@ -131,21 +128,12 @@ public class TomcatFilterProbe {
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
private void appendIfPresent(StringBuilder sb, String prefix, String value, String suffix) {
|
||||
private void appendIfPresent(StringBuilder sb, String prefix, String value) {
|
||||
if (value != null && !value.isEmpty()) {
|
||||
sb.append(prefix).append(value).append(suffix);
|
||||
sb.append(prefix).append(value);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
private static String repeatString(String str, int count) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < count; i++) {
|
||||
sb.append(str);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
private String getContextRoot(Object context) {
|
||||
String r = null;
|
||||
@@ -204,35 +192,30 @@ public class TomcatFilterProbe {
|
||||
return contexts;
|
||||
}
|
||||
|
||||
public static Object invokeMethod(Object obj, String methodName){
|
||||
public static Object invokeMethod(Object obj, String methodName) throws Exception {
|
||||
return invokeMethod(obj, methodName, null, null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) {
|
||||
try {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) throws Exception {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error invoking method: " + methodName, e);
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
|
||||
+45
-50
@@ -12,9 +12,9 @@ import java.util.*;
|
||||
public class UndertowFilterProbe {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("Duplicates")
|
||||
public String toString() {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
Map<String, List<Map<String, String>>> allFiltersData = new LinkedHashMap<String, List<Map<String, String>>>();
|
||||
Set<Object> contexts = null;
|
||||
try {
|
||||
contexts = getContext();
|
||||
@@ -24,6 +24,7 @@ public class UndertowFilterProbe {
|
||||
if (contexts == null || contexts.isEmpty()) {
|
||||
msg.append("context not found\n");
|
||||
} else {
|
||||
Map<String, List<Map<String, String>>> allFiltersData = new LinkedHashMap<String, List<Map<String, String>>>();
|
||||
for (Object context : contexts) {
|
||||
String contextRoot = getContextRoot(context);
|
||||
try {
|
||||
@@ -40,40 +41,24 @@ public class UndertowFilterProbe {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Map<String, String>> collectFiltersData(Object context) throws Exception {
|
||||
// context -> io.undertow.servlet.spec.ServletContextImpl
|
||||
Map<String, Map<String, Object>> aggregatedData = new LinkedHashMap<>();
|
||||
// deploymentInfo -> io.undertow.servlet.api.DeploymentInfo
|
||||
Object deploymentInfo = getFieldValue(context, "deploymentInfo");
|
||||
Map<String, Object> filters = (Map<String, Object>) getFieldValue(deploymentInfo, "filters");
|
||||
List<Object> filterUrlMappings = (List<Object>) getFieldValue(deploymentInfo, "filterUrlMappings");
|
||||
List<Object> filterServletNameMappings = (List<Object>) getFieldValue(deploymentInfo, "filterServletNameMappings");
|
||||
for (Object filterUrlMapping : filterUrlMappings) {
|
||||
String filterName = (String) getFieldValue(filterUrlMapping, "filterName");
|
||||
Class<?> filterClass = (Class<?>) getFieldValue(filters.get(filterName), "filterClass");
|
||||
if (aggregatedData.get(filterName) == null) {
|
||||
Map<String, Object> info = new HashMap<>();
|
||||
info.put("filterName", filterName);
|
||||
info.put("filterClass", filterClass.getName());
|
||||
info.put("urlPatterns", new LinkedHashSet<String>());
|
||||
info.put("servletNames", new LinkedHashSet<String>());
|
||||
aggregatedData.put(filterName, info);
|
||||
}
|
||||
Map<String, Object> info = aggregatedData.get(filterName);
|
||||
// filterUrlMapping -> io.undertow.servlet.api.FilterMappingInfo
|
||||
Map<String, Object> info = fillFilterInfo(filterUrlMapping, filters, aggregatedData);
|
||||
String urlPattern = (String) getFieldValue(filterUrlMapping, "mapping");
|
||||
if (urlPattern != null) {
|
||||
((Set<String>) info.get("urlPatterns")).add(urlPattern);
|
||||
}
|
||||
}
|
||||
for (Object filterServletNameMapping : filterServletNameMappings) {
|
||||
String filterName = (String) getFieldValue(filterServletNameMapping, "filterName");
|
||||
Class<?> filterClass = (Class<?>) getFieldValue(filters.get(filterName), "filterClass");
|
||||
if (aggregatedData.get(filterName) == null) {
|
||||
Map<String, Object> info = new HashMap<>();
|
||||
info.put("filterName", filterName);
|
||||
info.put("filterClass", filterClass.getName());
|
||||
info.put("urlPatterns", new LinkedHashSet<String>());
|
||||
info.put("servletNames", new LinkedHashSet<String>());
|
||||
aggregatedData.put(filterName, info);
|
||||
}
|
||||
Map<String, Object> info = aggregatedData.get(filterName);
|
||||
// filterServletNameMapping -> io.undertow.servlet.api.FilterMappingInfo
|
||||
Map<String, Object> info = fillFilterInfo(filterServletNameMapping, filters, aggregatedData);
|
||||
String servletNames = (String) getFieldValue(filterServletNameMapping, "mapping");
|
||||
if (servletNames != null) {
|
||||
((Set<String>) info.get("servletNames")).add(servletNames);
|
||||
@@ -93,6 +78,20 @@ public class UndertowFilterProbe {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Map<String, Object> fillFilterInfo(Object filterServletNameMapping, Map<String, Object> filters, Map<String, Map<String, Object>> aggregatedData) throws NoSuchFieldException, IllegalAccessException {
|
||||
String filterName = (String) getFieldValue(filterServletNameMapping, "filterName");
|
||||
if (!aggregatedData.containsKey(filterName)) {
|
||||
Map<String, Object> info = new HashMap<>();
|
||||
info.put("filterName", filterName);
|
||||
Class<?> filterClass = (Class<?>) getFieldValue(filters.get(filterName), "filterClass");
|
||||
info.put("filterClass", filterClass.getName());
|
||||
info.put("urlPatterns", new LinkedHashSet<String>());
|
||||
info.put("servletNames", new LinkedHashSet<String>());
|
||||
aggregatedData.put(filterName, info);
|
||||
}
|
||||
return aggregatedData.get(filterName);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
private String formatFiltersData(Map<String, List<Map<String, String>>> allFiltersData) {
|
||||
StringBuilder output = new StringBuilder();
|
||||
@@ -106,10 +105,10 @@ public class UndertowFilterProbe {
|
||||
output.append(filters.get(0).get("error")).append("\n");
|
||||
} else {
|
||||
for (Map<String, String> info : filters) {
|
||||
appendIfPresent(output, "", info.get("filterName"), "");
|
||||
appendIfPresent(output, " -> ", info.get("filterClass"), "");
|
||||
appendIfPresent(output, " -> URL:", info.get("urlPatterns"), "");
|
||||
appendIfPresent(output, " -> Servlet:", info.get("servletNames"), "");
|
||||
appendIfPresent(output, "", info.get("filterName"));
|
||||
appendIfPresent(output, " -> ", info.get("filterClass"));
|
||||
appendIfPresent(output, " -> URL:", info.get("urlPatterns"));
|
||||
appendIfPresent(output, " -> Servlet:", info.get("servletNames"));
|
||||
output.append("\n");
|
||||
}
|
||||
}
|
||||
@@ -117,9 +116,9 @@ public class UndertowFilterProbe {
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
private void appendIfPresent(StringBuilder sb, String prefix, String value, String suffix) {
|
||||
private void appendIfPresent(StringBuilder sb, String prefix, String value) {
|
||||
if (value != null && !value.isEmpty()) {
|
||||
sb.append(prefix).append(value).append(suffix);
|
||||
sb.append(prefix).append(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,6 +139,7 @@ public class UndertowFilterProbe {
|
||||
return c + "(" + r + ")";
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
public Set<Object> getContext() throws Exception {
|
||||
Set<Object> contexts = new HashSet<Object>();
|
||||
Set<Thread> threads = Thread.getAllStackTraces().keySet();
|
||||
@@ -159,30 +159,25 @@ public class UndertowFilterProbe {
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) {
|
||||
try {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) throws Exception {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error invoking method: " + methodName, e);
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
|
||||
+57
-75
@@ -14,9 +14,9 @@ import java.util.*;
|
||||
public class WebLogicFilterProbe {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("Duplicates")
|
||||
public String toString() {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
Map<String, List<Map<String, String>>> allFiltersData = new LinkedHashMap<String, List<Map<String, String>>>();
|
||||
Set<Object> contexts = null;
|
||||
try {
|
||||
contexts = getContext();
|
||||
@@ -26,6 +26,7 @@ public class WebLogicFilterProbe {
|
||||
if (contexts == null || contexts.isEmpty()) {
|
||||
msg.append("context not found\n");
|
||||
} else {
|
||||
Map<String, List<Map<String, String>>> allFiltersData = new LinkedHashMap<String, List<Map<String, String>>>();
|
||||
for (Object context : contexts) {
|
||||
String contextRoot = getContextRoot(context);
|
||||
try {
|
||||
@@ -42,13 +43,15 @@ public class WebLogicFilterProbe {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Map<String, String>> collectFiltersData(Object context) throws Exception {
|
||||
|
||||
// context -> weblogic.servlet.internal.WebAppServletContext
|
||||
// filterManager -> weblogic.servlet.internal.FilterManager
|
||||
Object filterManager = getFieldValue(context, "filterManager");
|
||||
Map<String, Object> filters = (Map<String, Object>) getFieldValue(filterManager, "filters");
|
||||
List<Object> filterPatternList = (ArrayList<Object>) getFieldValue(filterManager, "filterPatternList");
|
||||
List<Object> filterServletList = (ArrayList<Object>) getFieldValue(filterManager, "filterServletList");
|
||||
Map<String, Map<String, Object>> aggregatedData = new LinkedHashMap<>();
|
||||
for (Object filterInfo : filterPatternList) {
|
||||
// filterInfo -> weblogic.servlet.internal.FilterManager$FilterInfo
|
||||
Object urlMap = getFieldValue(filterInfo, "map");
|
||||
String filterName = (String) getFieldValue(filterInfo, "filterName");
|
||||
if (filterName == null) {
|
||||
@@ -56,59 +59,16 @@ public class WebLogicFilterProbe {
|
||||
Object[] mapValues = (Object[]) invokeMethod(urlMap, "values", null, null);
|
||||
filterName = ((String) mapValues[0]);
|
||||
}
|
||||
if (aggregatedData.get(filterName) == null) {
|
||||
Object filterWrapper = filters.get(filterName);
|
||||
String filterClassName = null;
|
||||
try {
|
||||
filterClassName = (String) getFieldValue(filterWrapper, "filterClassName");
|
||||
} catch (NoSuchFieldException e) {
|
||||
// WebLogic 10.3.6
|
||||
filterClassName = (String) getFieldValue(filterWrapper, "filterclass");
|
||||
}
|
||||
if (filterClassName == null) {
|
||||
Object filter = getFieldValue(filterWrapper, "filter");
|
||||
if (filter != null) {
|
||||
filterClassName = filter.getClass().getName();
|
||||
}
|
||||
}
|
||||
Map<String, Object> info = new HashMap<>();
|
||||
info.put("filterName", filterName);
|
||||
info.put("filterClass", filterClassName);
|
||||
info.put("urlPatterns", new LinkedHashSet<String>());
|
||||
info.put("servletNames", new LinkedHashSet<String>());
|
||||
aggregatedData.put(filterName, info);
|
||||
}
|
||||
Map<String, Object> info = aggregatedData.get(filterName);
|
||||
Map<String, Object> info = fillFilterInfo(aggregatedData, filterName, filters);
|
||||
String[] urlPatterns = (String[]) invokeMethod(urlMap, "keys", null, null);
|
||||
if (urlPatterns != null) {
|
||||
((Set<String>) info.get("urlPatterns")).addAll(Arrays.asList(urlPatterns));
|
||||
}
|
||||
}
|
||||
for (Object filterInfo : filterServletList) {
|
||||
// filterInfo -> weblogic.servlet.internal.FilterManager$FilterInfo
|
||||
String filterName = (String) getFieldValue(filterInfo, "filterName");
|
||||
if (aggregatedData.get(filterName) == null) {
|
||||
Object filterWrapper = filters.get(filterName);
|
||||
String filterClassName = null;
|
||||
try {
|
||||
filterClassName = (String) getFieldValue(filterWrapper, "filterClassName");
|
||||
} catch (NoSuchFieldException e) {
|
||||
// WebLogic 10.3.6
|
||||
filterClassName = (String) getFieldValue(filterWrapper, "filterclass");
|
||||
}
|
||||
if (filterClassName == null) {
|
||||
Object filter = getFieldValue(filterWrapper, "filter");
|
||||
if (filter != null) {
|
||||
filterClassName = filter.getClass().getName();
|
||||
}
|
||||
}
|
||||
Map<String, Object> info = new HashMap<>();
|
||||
info.put("filterName", filterName);
|
||||
info.put("filterClass", filterClassName);
|
||||
info.put("urlPatterns", new LinkedHashSet<String>());
|
||||
info.put("servletNames", new LinkedHashSet<String>());
|
||||
aggregatedData.put(filterName, info);
|
||||
}
|
||||
Map<String, Object> info = aggregatedData.get(filterName);
|
||||
Map<String, Object> info = fillFilterInfo(aggregatedData, filterName, filters);
|
||||
String servletName = (String) getFieldValue(filterInfo, "servletName");
|
||||
if (servletName != null) {
|
||||
((Set<String>) info.get("servletNames")).add(servletName);
|
||||
@@ -128,6 +88,33 @@ public class WebLogicFilterProbe {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Map<String, Object> fillFilterInfo(Map<String, Map<String, Object>> aggregatedData, String filterName, Map<String, Object> filters) throws Exception {
|
||||
if (!aggregatedData.containsKey(filterName)) {
|
||||
// filterWrapper -> weblogic.servlet.internal.FilterWrapper
|
||||
Object filterWrapper = filters.get(filterName);
|
||||
String filterClassName = null;
|
||||
try {
|
||||
filterClassName = (String) getFieldValue(filterWrapper, "filterClassName");
|
||||
} catch (NoSuchFieldException e) {
|
||||
// WebLogic 10.3.6
|
||||
filterClassName = (String) getFieldValue(filterWrapper, "filterclass");
|
||||
}
|
||||
if (filterClassName == null) {
|
||||
Object filter = getFieldValue(filterWrapper, "filter");
|
||||
if (filter != null) {
|
||||
filterClassName = filter.getClass().getName();
|
||||
}
|
||||
}
|
||||
Map<String, Object> info = new HashMap<>();
|
||||
info.put("filterName", filterName);
|
||||
info.put("filterClass", filterClassName);
|
||||
info.put("urlPatterns", new LinkedHashSet<String>());
|
||||
info.put("servletNames", new LinkedHashSet<String>());
|
||||
aggregatedData.put(filterName, info);
|
||||
}
|
||||
return aggregatedData.get(filterName);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
private String formatFiltersData(Map<String, List<Map<String, String>>> allFiltersData) {
|
||||
StringBuilder output = new StringBuilder();
|
||||
@@ -141,10 +128,10 @@ public class WebLogicFilterProbe {
|
||||
output.append(filters.get(0).get("error")).append("\n");
|
||||
} else {
|
||||
for (Map<String, String> info : filters) {
|
||||
appendIfPresent(output, "", info.get("filterName"), "");
|
||||
appendIfPresent(output, " -> ", info.get("filterClass"), "");
|
||||
appendIfPresent(output, " -> URL:", info.get("urlPatterns"), "");
|
||||
appendIfPresent(output, " -> Servlet:", info.get("servletNames"), "");
|
||||
appendIfPresent(output, "", info.get("filterName"));
|
||||
appendIfPresent(output, " -> ", info.get("filterClass"));
|
||||
appendIfPresent(output, " -> URL:", info.get("urlPatterns"));
|
||||
appendIfPresent(output, " -> Servlet:", info.get("servletNames"));
|
||||
output.append("\n");
|
||||
}
|
||||
}
|
||||
@@ -152,9 +139,9 @@ public class WebLogicFilterProbe {
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
private void appendIfPresent(StringBuilder sb, String prefix, String value, String suffix) {
|
||||
private void appendIfPresent(StringBuilder sb, String prefix, String value) {
|
||||
if (value != null && !value.isEmpty()) {
|
||||
sb.append(prefix).append(value).append(suffix);
|
||||
sb.append(prefix).append(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,30 +201,25 @@ public class WebLogicFilterProbe {
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) {
|
||||
try {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) throws Exception {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error invoking method: " + methodName, e);
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
|
||||
+95
-109
@@ -12,9 +12,9 @@ import java.util.*;
|
||||
public class WebSphereFilterProbe {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("Duplicates")
|
||||
public String toString() {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
Map<String, List<Map<String, String>>> allFiltersData = new LinkedHashMap<String, List<Map<String, String>>>();
|
||||
Set<Object> contexts = null;
|
||||
try {
|
||||
contexts = getContext();
|
||||
@@ -24,6 +24,7 @@ public class WebSphereFilterProbe {
|
||||
if (contexts == null || contexts.isEmpty()) {
|
||||
msg.append("context not found\n");
|
||||
} else {
|
||||
Map<String, List<Map<String, String>>> allFiltersData = new LinkedHashMap<String, List<Map<String, String>>>();
|
||||
for (Object context : contexts) {
|
||||
String contextRoot = getContextRoot(context);
|
||||
try {
|
||||
@@ -38,94 +39,54 @@ public class WebSphereFilterProbe {
|
||||
return msg.toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Map<String, String>> collectFiltersData(Object context) throws Exception {
|
||||
// context -> com.ibm.ws.webcontainer.webapp.WebAppImpl
|
||||
Map<String, Map<String, Object>> aggregatedData = new LinkedHashMap<>();
|
||||
// filterManager -> com.ibm.ws.webcontainer.filter.WebAppFilterManager
|
||||
Object filterManager = getFieldValue(context, "filterManager");
|
||||
// webAppConfig -> com.ibm.ws.webcontainer.webapp.WebAppConfigurationImpl
|
||||
Object webAppConfig = getFieldValue(context, "config");
|
||||
try {
|
||||
Object filterManager = getFieldValue(context, "filterManager");
|
||||
Object webAppConfig = getFieldValue(context, "config");
|
||||
try {
|
||||
List uriFilterMappingInfos = (List) getFieldValue(webAppConfig, "uriFilterMappingInfos");
|
||||
for (Object uriFilterMappingInfo : uriFilterMappingInfos) {
|
||||
Object filterConfig = getFieldValue(uriFilterMappingInfo, "filterConfig");
|
||||
String filterName = (String) invokeMethod(filterConfig, "getFilterName", null, null);
|
||||
if (!aggregatedData.containsKey(filterName)) {
|
||||
String filterClassName = (String) invokeMethod(filterConfig, "getFilterClassName", null, null);
|
||||
Map<String, Object> info = new HashMap<>();
|
||||
info.put("filterName", filterName);
|
||||
info.put("filterClass", filterClassName);
|
||||
info.put("urlPatterns", new LinkedHashSet<>());
|
||||
info.put("servletNames", new LinkedHashSet<>());
|
||||
aggregatedData.put(filterName, info);
|
||||
}
|
||||
Map<String, Object> info = aggregatedData.get(filterName);
|
||||
String urlPattern = (String) invokeMethod(uriFilterMappingInfo, "getUrlPattern", null, null);
|
||||
if (urlPattern != null && !urlPattern.isEmpty()) {
|
||||
((Set) info.get("urlPatterns")).add(urlPattern);
|
||||
}
|
||||
// WebLogic 12+
|
||||
List<Object> uriFilterMappingInfos = (List<Object>) getFieldValue(webAppConfig, "uriFilterMappingInfos");
|
||||
for (Object uriFilterMappingInfo : uriFilterMappingInfos) {
|
||||
// uriFilterMappingInfo -> com.ibm.ws.webcontainer.filter.FilterMapping
|
||||
Map<String, Object> info = filterFilterInfo1(uriFilterMappingInfo, aggregatedData);
|
||||
String urlPattern = (String) invokeMethod(uriFilterMappingInfo, "getUrlPattern", null, null);
|
||||
if (urlPattern != null && !urlPattern.isEmpty()) {
|
||||
((Set<String>) info.get("urlPatterns")).add(urlPattern);
|
||||
}
|
||||
|
||||
List servletFilterMappingInfos = (List) getFieldValue(webAppConfig, "servletFilterMappingInfos");
|
||||
for (Object servletFilterMappingInfo : servletFilterMappingInfos) {
|
||||
Object filterConfig = getFieldValue(servletFilterMappingInfo, "filterConfig");
|
||||
String filterName = (String) invokeMethod(filterConfig, "getFilterName", null, null);
|
||||
if (!aggregatedData.containsKey(filterName)) {
|
||||
String filterClassName = (String) invokeMethod(filterConfig, "getFilterClassName", null, null);
|
||||
Map<String, Object> info = new HashMap<>();
|
||||
info.put("filterName", filterName);
|
||||
info.put("filterClass", filterClassName);
|
||||
info.put("urlPatterns", new LinkedHashSet<>());
|
||||
info.put("servletNames", new LinkedHashSet<>());
|
||||
aggregatedData.put(filterName, info);
|
||||
}
|
||||
Map<String, Object> info = aggregatedData.get(filterName);
|
||||
String servletName = (String) invokeMethod(invokeMethod(servletFilterMappingInfo, "getServletConfig"), "getServletName");
|
||||
if (servletName != null && !servletName.isEmpty()) {
|
||||
((Set) info.get("servletNames")).add(servletName);
|
||||
}
|
||||
}
|
||||
List<Object> servletFilterMappingInfos = (List<Object>) getFieldValue(webAppConfig, "servletFilterMappingInfos");
|
||||
for (Object servletFilterMappingInfo : servletFilterMappingInfos) {
|
||||
// servletFilterMappingInfo -> com.ibm.ws.webcontainer.filter.FilterMapping
|
||||
Map<String, Object> info = filterFilterInfo1(servletFilterMappingInfo, aggregatedData);
|
||||
String servletName = (String) invokeMethod(invokeMethod(servletFilterMappingInfo, "getServletConfig"), "getServletName");
|
||||
if (servletName != null && !servletName.isEmpty()) {
|
||||
((Set<String>) info.get("servletNames")).add(servletName);
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
// WebLogic 10.3.6
|
||||
List uriFilterMappings = (List) getFieldValue(filterManager, "_uriFilterMappings");
|
||||
for (Object uriFilterMapping : uriFilterMappings) {
|
||||
String filterName = (String) getFieldValue(uriFilterMapping, "_filterName");
|
||||
if (!aggregatedData.containsKey(filterName)) {
|
||||
Object filterConfig = invokeMethod(webAppConfig, "getFilterInfo", new Class[]{String.class}, new Object[]{filterName});
|
||||
String filterClassName = (String) invokeMethod(filterConfig, "getFilterClassName", null, null);
|
||||
Map<String, Object> info = new HashMap<>();
|
||||
info.put("filterName", filterName);
|
||||
info.put("filterClass", filterClassName);
|
||||
info.put("urlPatterns", new LinkedHashSet<>());
|
||||
info.put("servletNames", new LinkedHashSet<>());
|
||||
aggregatedData.put(filterName, info);
|
||||
}
|
||||
Map<String, Object> info = aggregatedData.get(filterName);
|
||||
String urlPattern = (String) getFieldValue(uriFilterMapping, "_filterURI");
|
||||
if (urlPattern != null && !urlPattern.isEmpty()) {
|
||||
((Set) info.get("urlPatterns")).add(urlPattern);
|
||||
}
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
// WebLogic 10.3.6
|
||||
List<Object> uriFilterMappings = (List<Object>) getFieldValue(filterManager, "_uriFilterMappings");
|
||||
for (Object uriFilterMapping : uriFilterMappings) {
|
||||
// uriFilterMapping -> com.ibm.ws.webcontainer.filter.WebAppFilterManager$FilterMappingInfo
|
||||
Map<String, Object> info = fillFilterInfo2(uriFilterMapping, aggregatedData, webAppConfig);
|
||||
String urlPattern = (String) getFieldValue(uriFilterMapping, "_filterURI");
|
||||
if (urlPattern != null && !urlPattern.isEmpty()) {
|
||||
((Set<String>) info.get("urlPatterns")).add(urlPattern);
|
||||
}
|
||||
List servletFilterMappings = (List) getFieldValue(filterManager, "_servletFilterMappings");
|
||||
for (Object servletFilterMapping : servletFilterMappings) {
|
||||
String filterName = (String) getFieldValue(servletFilterMapping, "_filterName");
|
||||
if (!aggregatedData.containsKey(filterName)) {
|
||||
Object filterConfig = invokeMethod(webAppConfig, "getFilterInfo", new Class[]{String.class}, new Object[]{filterName});
|
||||
String filterClassName = (String) invokeMethod(filterConfig, "getFilterClassName", null, null);
|
||||
Map<String, Object> info = new HashMap<>();
|
||||
info.put("filterName", filterName);
|
||||
info.put("filterClass", filterClassName);
|
||||
info.put("urlPatterns", new LinkedHashSet<>());
|
||||
info.put("servletNames", new LinkedHashSet<>());
|
||||
aggregatedData.put(filterName, info);
|
||||
}
|
||||
Map<String, Object> info = aggregatedData.get(filterName);
|
||||
String servletName = (String) getFieldValue(servletFilterMapping, "_filterServlet");
|
||||
if (servletName != null && !servletName.isEmpty()) {
|
||||
((Set) info.get("servletNames")).add(servletName);
|
||||
}
|
||||
}
|
||||
List<Object> servletFilterMappings = (List<Object>) getFieldValue(filterManager, "_servletFilterMappings");
|
||||
for (Object servletFilterMapping : servletFilterMappings) {
|
||||
// servletFilterMapping -> com.ibm.ws.webcontainer.filter.WebAppFilterManager$FilterMappingInfo
|
||||
Map<String, Object> info = fillFilterInfo2(servletFilterMapping, aggregatedData, webAppConfig);
|
||||
String servletName = (String) getFieldValue(servletFilterMapping, "_filterServlet");
|
||||
if (servletName != null && !servletName.isEmpty()) {
|
||||
((Set<String>) info.get("servletNames")).add(servletName);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
List<Map<String, String>> result = new ArrayList<>();
|
||||
for (Map<String, Object> entry : aggregatedData.values()) {
|
||||
@@ -141,6 +102,36 @@ public class WebSphereFilterProbe {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Map<String, Object> filterFilterInfo1(Object uriFilterMappingInfo, Map<String, Map<String, Object>> aggregatedData) throws Exception {
|
||||
Object filterConfig = getFieldValue(uriFilterMappingInfo, "filterConfig");
|
||||
String filterName = (String) invokeMethod(filterConfig, "getFilterName", null, null);
|
||||
if (!aggregatedData.containsKey(filterName)) {
|
||||
String filterClassName = (String) invokeMethod(filterConfig, "getFilterClassName", null, null);
|
||||
Map<String, Object> info = new HashMap<>();
|
||||
info.put("filterName", filterName);
|
||||
info.put("filterClass", filterClassName);
|
||||
info.put("urlPatterns", new LinkedHashSet<>());
|
||||
info.put("servletNames", new LinkedHashSet<>());
|
||||
aggregatedData.put(filterName, info);
|
||||
}
|
||||
return aggregatedData.get(filterName);
|
||||
}
|
||||
|
||||
private static Map<String, Object> fillFilterInfo2(Object servletFilterMapping, Map<String, Map<String, Object>> aggregatedData, Object webAppConfig) throws Exception {
|
||||
String filterName = (String) getFieldValue(servletFilterMapping, "_filterName");
|
||||
if (!aggregatedData.containsKey(filterName)) {
|
||||
Object filterConfig = invokeMethod(webAppConfig, "getFilterInfo", new Class[]{String.class}, new Object[]{filterName});
|
||||
String filterClassName = (String) invokeMethod(filterConfig, "getFilterClassName", null, null);
|
||||
Map<String, Object> info = new HashMap<>();
|
||||
info.put("filterName", filterName);
|
||||
info.put("filterClass", filterClassName);
|
||||
info.put("urlPatterns", new LinkedHashSet<>());
|
||||
info.put("servletNames", new LinkedHashSet<>());
|
||||
aggregatedData.put(filterName, info);
|
||||
}
|
||||
return aggregatedData.get(filterName);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
private String formatFiltersData(Map<String, List<Map<String, String>>> allFiltersData) {
|
||||
StringBuilder output = new StringBuilder();
|
||||
@@ -154,10 +145,10 @@ public class WebSphereFilterProbe {
|
||||
output.append(filters.get(0).get("error")).append("\n");
|
||||
} else {
|
||||
for (Map<String, String> info : filters) {
|
||||
appendIfPresent(output, "", info.get("filterName"), "");
|
||||
appendIfPresent(output, " -> ", info.get("filterClass"), "");
|
||||
appendIfPresent(output, " -> URL:", info.get("urlPatterns"), "");
|
||||
appendIfPresent(output, " -> Servlet:", info.get("servletNames"), "");
|
||||
appendIfPresent(output, "", info.get("filterName"));
|
||||
appendIfPresent(output, " -> ", info.get("filterClass"));
|
||||
appendIfPresent(output, " -> URL:", info.get("urlPatterns"));
|
||||
appendIfPresent(output, " -> Servlet:", info.get("servletNames"));
|
||||
output.append("\n");
|
||||
}
|
||||
}
|
||||
@@ -165,9 +156,9 @@ public class WebSphereFilterProbe {
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
private void appendIfPresent(StringBuilder sb, String prefix, String value, String suffix) {
|
||||
private void appendIfPresent(StringBuilder sb, String prefix, String value) {
|
||||
if (value != null && !value.isEmpty()) {
|
||||
sb.append(prefix).append(value).append(suffix);
|
||||
sb.append(prefix).append(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,35 +227,30 @@ public class WebSphereFilterProbe {
|
||||
return contexts;
|
||||
}
|
||||
|
||||
public static Object invokeMethod(Object obj, String methodName) {
|
||||
public static Object invokeMethod(Object obj, String methodName) throws Exception {
|
||||
return invokeMethod(obj, methodName, null, null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) {
|
||||
try {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
public static Object invokeMethod(Object obj, String methodName, Class<?>[] paramClazz, Object[] param) throws Exception {
|
||||
Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
|
||||
Method method = null;
|
||||
while (clazz != null && method == null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
method = clazz.getDeclaredMethod(methodName);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error invoking method: " + methodName, e);
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException("Method not found: " + methodName);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj instanceof Class ? null : obj, param);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
|
||||
Reference in New Issue
Block a user