diff --git a/generator/src/main/java/com/reajason/javaweb/memshell/injector/apusic/ApusicFilterInjector.java b/generator/src/main/java/com/reajason/javaweb/memshell/injector/apusic/ApusicFilterInjector.java index 6532a78b..75065083 100644 --- a/generator/src/main/java/com/reajason/javaweb/memshell/injector/apusic/ApusicFilterInjector.java +++ b/generator/src/main/java/com/reajason/javaweb/memshell/injector/apusic/ApusicFilterInjector.java @@ -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") diff --git a/generator/src/main/java/com/reajason/javaweb/memshell/injector/apusic/ApusicListenerInjector.java b/generator/src/main/java/com/reajason/javaweb/memshell/injector/apusic/ApusicListenerInjector.java index 6095d3ab..50313200 100644 --- a/generator/src/main/java/com/reajason/javaweb/memshell/injector/apusic/ApusicListenerInjector.java +++ b/generator/src/main/java/com/reajason/javaweb/memshell/injector/apusic/ApusicListenerInjector.java @@ -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") diff --git a/generator/src/main/java/com/reajason/javaweb/memshell/injector/apusic/ApusicServletInjector.java b/generator/src/main/java/com/reajason/javaweb/memshell/injector/apusic/ApusicServletInjector.java index 3c0fb3b3..206b6117 100644 --- a/generator/src/main/java/com/reajason/javaweb/memshell/injector/apusic/ApusicServletInjector.java +++ b/generator/src/main/java/com/reajason/javaweb/memshell/injector/apusic/ApusicServletInjector.java @@ -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") diff --git a/generator/src/main/java/com/reajason/javaweb/memshell/injector/bes/BesFilterInjector.java b/generator/src/main/java/com/reajason/javaweb/memshell/injector/bes/BesFilterInjector.java index dd87e78c..acc568f9 100644 --- a/generator/src/main/java/com/reajason/javaweb/memshell/injector/bes/BesFilterInjector.java +++ b/generator/src/main/java/com/reajason/javaweb/memshell/injector/bes/BesFilterInjector.java @@ -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") diff --git a/generator/src/main/java/com/reajason/javaweb/memshell/injector/inforsuite/InforSuiteFilterInjector.java b/generator/src/main/java/com/reajason/javaweb/memshell/injector/inforsuite/InforSuiteFilterInjector.java index 65b9b860..511afcc3 100644 --- a/generator/src/main/java/com/reajason/javaweb/memshell/injector/inforsuite/InforSuiteFilterInjector.java +++ b/generator/src/main/java/com/reajason/javaweb/memshell/injector/inforsuite/InforSuiteFilterInjector.java @@ -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") diff --git a/generator/src/main/java/com/reajason/javaweb/memshell/injector/resin/ResinFilterInjector.java b/generator/src/main/java/com/reajason/javaweb/memshell/injector/resin/ResinFilterInjector.java index 85738f6e..46c5f2e4 100644 --- a/generator/src/main/java/com/reajason/javaweb/memshell/injector/resin/ResinFilterInjector.java +++ b/generator/src/main/java/com/reajason/javaweb/memshell/injector/resin/ResinFilterInjector.java @@ -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") diff --git a/generator/src/main/java/com/reajason/javaweb/memshell/injector/resin/ResinListenerInjector.java b/generator/src/main/java/com/reajason/javaweb/memshell/injector/resin/ResinListenerInjector.java index a27128e5..6f220157 100644 --- a/generator/src/main/java/com/reajason/javaweb/memshell/injector/resin/ResinListenerInjector.java +++ b/generator/src/main/java/com/reajason/javaweb/memshell/injector/resin/ResinListenerInjector.java @@ -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") diff --git a/generator/src/main/java/com/reajason/javaweb/memshell/injector/resin/ResinServletInjector.java b/generator/src/main/java/com/reajason/javaweb/memshell/injector/resin/ResinServletInjector.java index 01c5b9a1..3df9f5e7 100644 --- a/generator/src/main/java/com/reajason/javaweb/memshell/injector/resin/ResinServletInjector.java +++ b/generator/src/main/java/com/reajason/javaweb/memshell/injector/resin/ResinServletInjector.java @@ -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") diff --git a/generator/src/main/java/com/reajason/javaweb/memshell/injector/tomcat/TomcatListenerInjector.java b/generator/src/main/java/com/reajason/javaweb/memshell/injector/tomcat/TomcatListenerInjector.java index 935953a1..a7743815 100644 --- a/generator/src/main/java/com/reajason/javaweb/memshell/injector/tomcat/TomcatListenerInjector.java +++ b/generator/src/main/java/com/reajason/javaweb/memshell/injector/tomcat/TomcatListenerInjector.java @@ -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") diff --git a/generator/src/main/java/com/reajason/javaweb/memshell/injector/tongweb/TongWebFilterInjector.java b/generator/src/main/java/com/reajason/javaweb/memshell/injector/tongweb/TongWebFilterInjector.java index 9bf4b6ad..70921308 100644 --- a/generator/src/main/java/com/reajason/javaweb/memshell/injector/tongweb/TongWebFilterInjector.java +++ b/generator/src/main/java/com/reajason/javaweb/memshell/injector/tongweb/TongWebFilterInjector.java @@ -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); } diff --git a/generator/src/main/java/com/reajason/javaweb/memshell/injector/tongweb/TongWebListenerInjector.java b/generator/src/main/java/com/reajason/javaweb/memshell/injector/tongweb/TongWebListenerInjector.java index 081cee56..d7651aa6 100644 --- a/generator/src/main/java/com/reajason/javaweb/memshell/injector/tongweb/TongWebListenerInjector.java +++ b/generator/src/main/java/com/reajason/javaweb/memshell/injector/tongweb/TongWebListenerInjector.java @@ -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") diff --git a/generator/src/main/java/com/reajason/javaweb/memshell/injector/undertow/UndertowFilterInjector.java b/generator/src/main/java/com/reajason/javaweb/memshell/injector/undertow/UndertowFilterInjector.java index a41f7248..33ae3f17 100644 --- a/generator/src/main/java/com/reajason/javaweb/memshell/injector/undertow/UndertowFilterInjector.java +++ b/generator/src/main/java/com/reajason/javaweb/memshell/injector/undertow/UndertowFilterInjector.java @@ -78,6 +78,7 @@ public class UndertowFilterInjector { return c + "(" + r + ")"; } + @SuppressWarnings("Duplicates") public Set getContext() throws Exception { Set contexts = new HashSet(); Set 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") diff --git a/generator/src/main/java/com/reajason/javaweb/memshell/injector/undertow/UndertowListenerInjector.java b/generator/src/main/java/com/reajason/javaweb/memshell/injector/undertow/UndertowListenerInjector.java index 51cabeca..c0db0840 100644 --- a/generator/src/main/java/com/reajason/javaweb/memshell/injector/undertow/UndertowListenerInjector.java +++ b/generator/src/main/java/com/reajason/javaweb/memshell/injector/undertow/UndertowListenerInjector.java @@ -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") diff --git a/generator/src/main/java/com/reajason/javaweb/memshell/injector/undertow/UndertowServletInjector.java b/generator/src/main/java/com/reajason/javaweb/memshell/injector/undertow/UndertowServletInjector.java index b5acc74b..de7c016b 100644 --- a/generator/src/main/java/com/reajason/javaweb/memshell/injector/undertow/UndertowServletInjector.java +++ b/generator/src/main/java/com/reajason/javaweb/memshell/injector/undertow/UndertowServletInjector.java @@ -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") diff --git a/generator/src/main/java/com/reajason/javaweb/memshell/injector/weblogic/WebLogicFilterInjector.java b/generator/src/main/java/com/reajason/javaweb/memshell/injector/weblogic/WebLogicFilterInjector.java index 53969fef..9b9ee011 100644 --- a/generator/src/main/java/com/reajason/javaweb/memshell/injector/weblogic/WebLogicFilterInjector.java +++ b/generator/src/main/java/com/reajason/javaweb/memshell/injector/weblogic/WebLogicFilterInjector.java @@ -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") diff --git a/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/ApusicFilterProbe.java b/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/ApusicFilterProbe.java index e0d306e8..a8052db8 100644 --- a/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/ApusicFilterProbe.java +++ b/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/ApusicFilterProbe.java @@ -12,9 +12,9 @@ import java.util.*; public class ApusicFilterProbe { @Override + @SuppressWarnings("Duplicates") public String toString() { StringBuilder msg = new StringBuilder(); - Map>> allFiltersData = new LinkedHashMap>>(); Set 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>> allFiltersData = new LinkedHashMap>>(); 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> collectFiltersData(Object context) throws Exception { + // context -> com.apusic.web.container.WebContainer Map> aggregatedData = new LinkedHashMap<>(); + // webModule -> com.apusic.deploy.runtime.WebModule Object webModule = getFieldValue(context, "webapp"); Object[] filterMappings = (Object[]) invokeMethod(webModule, "getAllFilterMappings"); - Map filterClassMap = new HashMap<>(); - for (Object fm : filterMappings) { + // fm -> com.apusic.deploy.runtime.FilterMapping String name = (String) invokeMethod(fm, "getFilterName"); if (!aggregatedData.containsKey(name)) { Map info = new HashMap<>(); @@ -58,15 +60,10 @@ public class ApusicFilterProbe { } Map info = aggregatedData.get(name); String urlPattern = (String) invokeMethod(fm, "getUrlPattern"); - if (urlPattern != null) { - ((Set) info.get("urlPatterns")).add(urlPattern); - } + if (urlPattern != null && !urlPattern.isEmpty()) ((Set) info.get("urlPatterns")).add(urlPattern); String servletName = (String) invokeMethod(fm, "getServletName"); - if (servletName != null) { - ((Set) info.get("servletNames")).add(servletName); - } + if (servletName != null && !servletName.isEmpty()) ((Set) info.get("servletNames")).add(servletName); } - List> result = new ArrayList<>(); for (Map entry : aggregatedData.values()) { Map finalInfo = new HashMap<>(); @@ -92,10 +89,10 @@ public class ApusicFilterProbe { output.append("No filters found\n"); } else { for (Map 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 getContext() throws Exception { Set contexts = new HashSet(); Set threads = Thread.getAllStackTraces().keySet(); diff --git a/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/GlassFishFilterProbe.java b/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/GlassFishFilterProbe.java index 4458a44a..30506f3a 100644 --- a/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/GlassFishFilterProbe.java +++ b/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/GlassFishFilterProbe.java @@ -38,32 +38,24 @@ public class GlassFishFilterProbe { return msg.toString(); } - @SuppressWarnings("unchecked") + @SuppressWarnings({"unchecked", "Duplicates"}) private List> collectFiltersData(Object context) throws Exception { + // context -> org.apache.catalina.core.StandardContext Map> aggregatedData = new LinkedHashMap<>(); - List filterMaps = (List) invokeMethod(context, "findFilterMaps"); - if (filterMaps == null || filterMaps.isEmpty()) return Collections.emptyList(); - - Object[] filterDefs = (Object[]) invokeMethod(context, "findFilterDefs"); - + List filterMaps = (List) 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 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) 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) 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 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 getContext() throws Exception { - Set contexts = new HashSet(); + Set contexts = new HashSet<>(); Set 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") diff --git a/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/JettyFilterProbe.java b/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/JettyFilterProbe.java index cae71a65..5e6b0818 100644 --- a/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/JettyFilterProbe.java +++ b/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/JettyFilterProbe.java @@ -13,9 +13,9 @@ import java.util.*; public class JettyFilterProbe { @Override + @SuppressWarnings("Duplicates") public String toString() { StringBuilder msg = new StringBuilder(); - Map>> allFiltersData = new LinkedHashMap>>(); Set 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>> allFiltersData = new LinkedHashMap>>(); 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> collectFiltersData(Object context) throws Exception { Map> 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 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 getContext() throws Exception { Set contexts = new HashSet(); Set threads = Thread.getAllStackTraces().keySet(); diff --git a/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/ResinFilterProbe.java b/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/ResinFilterProbe.java index 07cb545a..f03190a2 100644 --- a/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/ResinFilterProbe.java +++ b/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/ResinFilterProbe.java @@ -12,9 +12,9 @@ import java.util.*; public class ResinFilterProbe { @Override + @SuppressWarnings("Duplicates") public String toString() { StringBuilder msg = new StringBuilder(); - Map>> allFiltersData = new LinkedHashMap>>(); Set 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>> allFiltersData = new LinkedHashMap>>(); for (Object context : contexts) { String contextRoot = getContextRoot(context); try { @@ -40,14 +41,18 @@ public class ResinFilterProbe { @SuppressWarnings("unchecked") private List> collectFiltersData(Object context) throws Exception { + // context -> com.caucho.server.webapp.Application Map> 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 filterMappings = (ArrayList) 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 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) info.get("urlPatterns")).addAll(urlPatterns); } List servletNames = (List) getFieldValue(filterMapping, "_servletNames"); if (servletNames != null && !servletNames.isEmpty()) { - ((Set) info.get("servletNames")).addAll(servletNames); + ((Set) info.get("servletNames")).addAll(servletNames); } } List> result = new ArrayList<>(); @@ -117,10 +122,10 @@ public class ResinFilterProbe { output.append(filters.get(0).get("error")).append("\n"); } else { for (Map 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") diff --git a/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/TomcatFilterProbe.java b/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/TomcatFilterProbe.java index 8f0d1f4f..2f5750b6 100644 --- a/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/TomcatFilterProbe.java +++ b/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/TomcatFilterProbe.java @@ -12,9 +12,9 @@ import java.util.*; public class TomcatFilterProbe { @Override + @SuppressWarnings("Duplicates") public String toString() { StringBuilder msg = new StringBuilder(); - Map>> allFiltersData = new LinkedHashMap>>(); Set 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>> allFiltersData = new LinkedHashMap>>(); for (Object context : contexts) { String contextRoot = getContextRoot(context); try { @@ -40,26 +41,22 @@ public class TomcatFilterProbe { @SuppressWarnings("unchecked") private List> collectFiltersData(Object context) throws Exception { + // context -> org.apache.catalina.core.StandardContext Map> 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 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 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") diff --git a/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/UndertowFilterProbe.java b/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/UndertowFilterProbe.java index c2ead872..c0033ba0 100644 --- a/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/UndertowFilterProbe.java +++ b/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/UndertowFilterProbe.java @@ -12,9 +12,9 @@ import java.util.*; public class UndertowFilterProbe { @Override + @SuppressWarnings("Duplicates") public String toString() { StringBuilder msg = new StringBuilder(); - Map>> allFiltersData = new LinkedHashMap>>(); Set 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>> allFiltersData = new LinkedHashMap>>(); for (Object context : contexts) { String contextRoot = getContextRoot(context); try { @@ -40,40 +41,24 @@ public class UndertowFilterProbe { @SuppressWarnings("unchecked") private List> collectFiltersData(Object context) throws Exception { + // context -> io.undertow.servlet.spec.ServletContextImpl Map> aggregatedData = new LinkedHashMap<>(); + // deploymentInfo -> io.undertow.servlet.api.DeploymentInfo Object deploymentInfo = getFieldValue(context, "deploymentInfo"); Map filters = (Map) getFieldValue(deploymentInfo, "filters"); List filterUrlMappings = (List) getFieldValue(deploymentInfo, "filterUrlMappings"); List filterServletNameMappings = (List) 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 info = new HashMap<>(); - info.put("filterName", filterName); - info.put("filterClass", filterClass.getName()); - info.put("urlPatterns", new LinkedHashSet()); - info.put("servletNames", new LinkedHashSet()); - aggregatedData.put(filterName, info); - } - Map info = aggregatedData.get(filterName); + // filterUrlMapping -> io.undertow.servlet.api.FilterMappingInfo + Map info = fillFilterInfo(filterUrlMapping, filters, aggregatedData); String urlPattern = (String) getFieldValue(filterUrlMapping, "mapping"); if (urlPattern != null) { ((Set) 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 info = new HashMap<>(); - info.put("filterName", filterName); - info.put("filterClass", filterClass.getName()); - info.put("urlPatterns", new LinkedHashSet()); - info.put("servletNames", new LinkedHashSet()); - aggregatedData.put(filterName, info); - } - Map info = aggregatedData.get(filterName); + // filterServletNameMapping -> io.undertow.servlet.api.FilterMappingInfo + Map info = fillFilterInfo(filterServletNameMapping, filters, aggregatedData); String servletNames = (String) getFieldValue(filterServletNameMapping, "mapping"); if (servletNames != null) { ((Set) info.get("servletNames")).add(servletNames); @@ -93,6 +78,20 @@ public class UndertowFilterProbe { return result; } + private static Map fillFilterInfo(Object filterServletNameMapping, Map filters, Map> aggregatedData) throws NoSuchFieldException, IllegalAccessException { + String filterName = (String) getFieldValue(filterServletNameMapping, "filterName"); + if (!aggregatedData.containsKey(filterName)) { + Map 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()); + info.put("servletNames", new LinkedHashSet()); + aggregatedData.put(filterName, info); + } + return aggregatedData.get(filterName); + } + @SuppressWarnings("all") private String formatFiltersData(Map>> allFiltersData) { StringBuilder output = new StringBuilder(); @@ -106,10 +105,10 @@ public class UndertowFilterProbe { output.append(filters.get(0).get("error")).append("\n"); } else { for (Map 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 getContext() throws Exception { Set contexts = new HashSet(); Set 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") diff --git a/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/WebLogicFilterProbe.java b/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/WebLogicFilterProbe.java index ec058900..c73a2fcb 100644 --- a/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/WebLogicFilterProbe.java +++ b/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/WebLogicFilterProbe.java @@ -14,9 +14,9 @@ import java.util.*; public class WebLogicFilterProbe { @Override + @SuppressWarnings("Duplicates") public String toString() { StringBuilder msg = new StringBuilder(); - Map>> allFiltersData = new LinkedHashMap>>(); Set 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>> allFiltersData = new LinkedHashMap>>(); for (Object context : contexts) { String contextRoot = getContextRoot(context); try { @@ -42,13 +43,15 @@ public class WebLogicFilterProbe { @SuppressWarnings("unchecked") private List> collectFiltersData(Object context) throws Exception { - + // context -> weblogic.servlet.internal.WebAppServletContext + // filterManager -> weblogic.servlet.internal.FilterManager Object filterManager = getFieldValue(context, "filterManager"); Map filters = (Map) getFieldValue(filterManager, "filters"); List filterPatternList = (ArrayList) getFieldValue(filterManager, "filterPatternList"); List filterServletList = (ArrayList) getFieldValue(filterManager, "filterServletList"); Map> 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 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 info = aggregatedData.get(filterName); + Map info = fillFilterInfo(aggregatedData, filterName, filters); String[] urlPatterns = (String[]) invokeMethod(urlMap, "keys", null, null); if (urlPatterns != null) { ((Set) 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 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 info = aggregatedData.get(filterName); + Map info = fillFilterInfo(aggregatedData, filterName, filters); String servletName = (String) getFieldValue(filterInfo, "servletName"); if (servletName != null) { ((Set) info.get("servletNames")).add(servletName); @@ -128,6 +88,33 @@ public class WebLogicFilterProbe { return result; } + private static Map fillFilterInfo(Map> aggregatedData, String filterName, Map 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 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>> allFiltersData) { StringBuilder output = new StringBuilder(); @@ -141,10 +128,10 @@ public class WebLogicFilterProbe { output.append(filters.get(0).get("error")).append("\n"); } else { for (Map 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") diff --git a/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/WebSphereFilterProbe.java b/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/WebSphereFilterProbe.java index bd461a01..ad22d962 100644 --- a/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/WebSphereFilterProbe.java +++ b/generator/src/main/java/com/reajason/javaweb/probe/payload/filter/WebSphereFilterProbe.java @@ -12,9 +12,9 @@ import java.util.*; public class WebSphereFilterProbe { @Override + @SuppressWarnings("Duplicates") public String toString() { StringBuilder msg = new StringBuilder(); - Map>> allFiltersData = new LinkedHashMap>>(); Set 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>> allFiltersData = new LinkedHashMap>>(); for (Object context : contexts) { String contextRoot = getContextRoot(context); try { @@ -38,94 +39,54 @@ public class WebSphereFilterProbe { return msg.toString(); } + @SuppressWarnings("unchecked") private List> collectFiltersData(Object context) throws Exception { + // context -> com.ibm.ws.webcontainer.webapp.WebAppImpl Map> 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 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 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 uriFilterMappingInfos = (List) getFieldValue(webAppConfig, "uriFilterMappingInfos"); + for (Object uriFilterMappingInfo : uriFilterMappingInfos) { + // uriFilterMappingInfo -> com.ibm.ws.webcontainer.filter.FilterMapping + Map info = filterFilterInfo1(uriFilterMappingInfo, aggregatedData); + String urlPattern = (String) invokeMethod(uriFilterMappingInfo, "getUrlPattern", null, null); + if (urlPattern != null && !urlPattern.isEmpty()) { + ((Set) 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 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 info = aggregatedData.get(filterName); - String servletName = (String) invokeMethod(invokeMethod(servletFilterMappingInfo, "getServletConfig"), "getServletName"); - if (servletName != null && !servletName.isEmpty()) { - ((Set) info.get("servletNames")).add(servletName); - } + } + List servletFilterMappingInfos = (List) getFieldValue(webAppConfig, "servletFilterMappingInfos"); + for (Object servletFilterMappingInfo : servletFilterMappingInfos) { + // servletFilterMappingInfo -> com.ibm.ws.webcontainer.filter.FilterMapping + Map info = filterFilterInfo1(servletFilterMappingInfo, aggregatedData); + String servletName = (String) invokeMethod(invokeMethod(servletFilterMappingInfo, "getServletConfig"), "getServletName"); + if (servletName != null && !servletName.isEmpty()) { + ((Set) 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 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 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 uriFilterMappings = (List) getFieldValue(filterManager, "_uriFilterMappings"); + for (Object uriFilterMapping : uriFilterMappings) { + // uriFilterMapping -> com.ibm.ws.webcontainer.filter.WebAppFilterManager$FilterMappingInfo + Map info = fillFilterInfo2(uriFilterMapping, aggregatedData, webAppConfig); + String urlPattern = (String) getFieldValue(uriFilterMapping, "_filterURI"); + if (urlPattern != null && !urlPattern.isEmpty()) { + ((Set) 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 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 info = aggregatedData.get(filterName); - String servletName = (String) getFieldValue(servletFilterMapping, "_filterServlet"); - if (servletName != null && !servletName.isEmpty()) { - ((Set) info.get("servletNames")).add(servletName); - } + } + List servletFilterMappings = (List) getFieldValue(filterManager, "_servletFilterMappings"); + for (Object servletFilterMapping : servletFilterMappings) { + // servletFilterMapping -> com.ibm.ws.webcontainer.filter.WebAppFilterManager$FilterMappingInfo + Map info = fillFilterInfo2(servletFilterMapping, aggregatedData, webAppConfig); + String servletName = (String) getFieldValue(servletFilterMapping, "_filterServlet"); + if (servletName != null && !servletName.isEmpty()) { + ((Set) info.get("servletNames")).add(servletName); } } - } catch (Exception e) { - e.printStackTrace(); } List> result = new ArrayList<>(); for (Map entry : aggregatedData.values()) { @@ -141,6 +102,36 @@ public class WebSphereFilterProbe { return result; } + private static Map filterFilterInfo1(Object uriFilterMappingInfo, Map> 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 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 fillFilterInfo2(Object servletFilterMapping, Map> 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 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>> allFiltersData) { StringBuilder output = new StringBuilder(); @@ -154,10 +145,10 @@ public class WebSphereFilterProbe { output.append(filters.get(0).get("error")).append("\n"); } else { for (Map 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")