feat: support tongweb 7 embedded shell

This commit is contained in:
ReaJason
2026-08-30 21:19:42 +08:00
parent d4c6473543
commit 9af244408b
6 changed files with 33 additions and 11 deletions
@@ -45,6 +45,7 @@ public class ValveBuilderModifier implements Processor<DynamicType.Builder<?>> {
public static final String TONGWEB6_VALVE_PACKAGE = "com.tongweb.web.thor"; public static final String TONGWEB6_VALVE_PACKAGE = "com.tongweb.web.thor";
public static final String TONGWEB7_VALVE_PACKAGE = "com.tongweb.catalina"; public static final String TONGWEB7_VALVE_PACKAGE = "com.tongweb.catalina";
public static final String TONGWEB8_VALVE_PACKAGE = "com.tongweb.server"; public static final String TONGWEB8_VALVE_PACKAGE = "com.tongweb.server";
public static final String TONGWEB_EMBEDDED_VALVE_PACKAGE = "com.tongweb.container";
public static DynamicType.Builder<?> modifier(DynamicType.Builder<?> builder, AbstractServer shell, String serverVersion) { public static DynamicType.Builder<?> modifier(DynamicType.Builder<?> builder, AbstractServer shell, String serverVersion) {
String packageName = null; String packageName = null;
@@ -53,7 +54,7 @@ public class ValveBuilderModifier implements Processor<DynamicType.Builder<?>> {
} }
if (shell instanceof TongWeb) { if (shell instanceof TongWeb) {
if (serverVersion == null) { if (serverVersion == null) {
throw new GenerationException("serverVersion is needed for TongWeb Valve, please use one of ['6', '7', '8'] for shellConfig.serverVersion"); throw new GenerationException("serverVersion is needed for TongWeb Valve, please use one of ['6', '7', '8', '7.E'] for shellConfig.serverVersion");
} }
switch (serverVersion) { switch (serverVersion) {
case "6": case "6":
@@ -65,8 +66,11 @@ public class ValveBuilderModifier implements Processor<DynamicType.Builder<?>> {
case "8": case "8":
packageName = TONGWEB8_VALVE_PACKAGE; packageName = TONGWEB8_VALVE_PACKAGE;
break; break;
case "7.E":
packageName = TONGWEB_EMBEDDED_VALVE_PACKAGE;
break;
default: default:
throw new GenerationException("TongWeb Valve unknow serverVersion: [" + serverVersion + "], please use one of ['6', '7', '8'] for shellConfig.serverVersion"); throw new GenerationException("TongWeb Valve unknow serverVersion: [" + serverVersion + "], please use one of ['6', '7', '8', '7.E'] for shellConfig.serverVersion");
} }
} }
if (StringUtils.isNotBlank(packageName)) { if (StringUtils.isNotBlank(packageName)) {
@@ -17,7 +17,8 @@ public class TongWebContextValveAgentInjector implements ClassFileTransformer {
private static final String[] TARGET_CLASSES = new String[]{ private static final String[] TARGET_CLASSES = new String[]{
"com/tongweb/web/thor/core/StandardContextValve", "com/tongweb/web/thor/core/StandardContextValve",
"com/tongweb/catalina/core/StandardContextValve", "com/tongweb/catalina/core/StandardContextValve",
"com/tongweb/server/core/StandardContextValve" "com/tongweb/server/core/StandardContextValve",
"com/tongweb/container/core/StandardContextValve"
}; };
private static final String TARGET_METHOD_NAME = "invoke"; private static final String TARGET_METHOD_NAME = "invoke";
@@ -17,7 +17,8 @@ public class TongWebFilterChainAgentInjector implements ClassFileTransformer {
private static final String[] TARGET_CLASSES = new String[]{ private static final String[] TARGET_CLASSES = new String[]{
"com/tongweb/web/thor/core/ApplicationFilterChain", "com/tongweb/web/thor/core/ApplicationFilterChain",
"com/tongweb/catalina/core/ApplicationFilterChain", "com/tongweb/catalina/core/ApplicationFilterChain",
"com/tongweb/server/core/ApplicationFilterChain" "com/tongweb/server/core/ApplicationFilterChain",
"com/tongweb/container/core/ApplicationFilterChain"
}; };
private static final String TARGET_METHOD_NAME = "doFilter"; private static final String TARGET_METHOD_NAME = "doFilter";
@@ -167,11 +167,19 @@ public class TongWebFilterInjector {
filterMapClass = contextClassLoader.loadClass("com.tongweb.web.thor.deploy.FilterMap"); filterMapClass = contextClassLoader.loadClass("com.tongweb.web.thor.deploy.FilterMap");
filterMap = filterMapClass.newInstance(); filterMap = filterMapClass.newInstance();
} catch (Exception e) { } catch (Exception e) {
// tongweb 8 try {
constructor = contextClassLoader.loadClass("com.tongweb.server.core.ApplicationFilterConfig").getDeclaredConstructors()[0]; // tongweb 8
filterDef = contextClassLoader.loadClass("com.tongweb.web.util.descriptor.web.FilterDef").newInstance(); constructor = contextClassLoader.loadClass("com.tongweb.server.core.ApplicationFilterConfig").getDeclaredConstructors()[0];
filterMapClass = contextClassLoader.loadClass("com.tongweb.web.util.descriptor.web.FilterMap"); filterDef = contextClassLoader.loadClass("com.tongweb.web.util.descriptor.web.FilterDef").newInstance();
filterMap = filterMapClass.newInstance(); filterMapClass = contextClassLoader.loadClass("com.tongweb.web.util.descriptor.web.FilterMap");
filterMap = filterMapClass.newInstance();
} catch (Exception e1) {
// tongweb embedded (spring boot)
constructor = contextClassLoader.loadClass("com.tongweb.container.core.ApplicationFilterConfig").getDeclaredConstructors()[0];
filterDef = contextClassLoader.loadClass("com.tongweb.web.util.descriptor.web.FilterDef").newInstance();
filterMapClass = contextClassLoader.loadClass("com.tongweb.web.util.descriptor.web.FilterMap");
filterMap = filterMapClass.newInstance();
}
} }
} }
invokeMethod(filterDef, "setFilterName", new Class[]{String.class}, new Object[]{filterClassName}); invokeMethod(filterDef, "setFilterName", new Class[]{String.class}, new Object[]{filterClassName});
@@ -141,8 +141,13 @@ public class TongWebValveInjector {
// tongweb6 // tongweb6
valveClass = contextClassLoader.loadClass("com.tongweb.web.thor.Valve"); valveClass = contextClassLoader.loadClass("com.tongweb.web.thor.Valve");
} catch (ClassNotFoundException e1) { } catch (ClassNotFoundException e1) {
// tongweb8 try {
valveClass = contextClassLoader.loadClass("com.tongweb.server.Valve"); // tongweb8
valveClass = contextClassLoader.loadClass("com.tongweb.server.Valve");
} catch (ClassNotFoundException e2) {
// tongweb embedded (spring boot)
valveClass = contextClassLoader.loadClass("com.tongweb.container.Valve");
}
} }
} }
invokeMethod(pipeline, "addValve", new Class[]{valveClass}, new Object[]{valve}); invokeMethod(pipeline, "addValve", new Class[]{valveClass}, new Object[]{valve});
@@ -19,8 +19,11 @@ public class TongWeb extends AbstractServer {
public InjectorMapping getShellInjectorMapping() { public InjectorMapping getShellInjectorMapping() {
return InjectorMapping.builder() return InjectorMapping.builder()
.addInjector(LISTENER, TongWebListenerInjector.class) .addInjector(LISTENER, TongWebListenerInjector.class)
.addInjector(JAKARTA_LISTENER, TongWebListenerInjector.class)
.addInjector(FILTER, TongWebFilterInjector.class) .addInjector(FILTER, TongWebFilterInjector.class)
.addInjector(JAKARTA_FILTER, TongWebFilterInjector.class)
.addInjector(VALVE, TongWebValveInjector.class) .addInjector(VALVE, TongWebValveInjector.class)
.addInjector(JAKARTA_VALVE, TongWebValveInjector.class)
.addInjector(AGENT_FILTER_CHAIN, TongWebFilterChainAgentInjector.class) .addInjector(AGENT_FILTER_CHAIN, TongWebFilterChainAgentInjector.class)
.addInjector(CATALINA_AGENT_CONTEXT_VALVE, TongWebContextValveAgentInjector.class) .addInjector(CATALINA_AGENT_CONTEXT_VALVE, TongWebContextValveAgentInjector.class)
.build(); .build();