基于 ja-netfilter 框架的 Java 方法拦截插件完整使用指南
支持类级别和方法级别的精确拦截
支持所有 Java 数据类型和异常
三层推断机制,自动识别返回类型
热配置更新,无需重新编译
延迟推断、缓存机制、线程安全
完全兼容传统配置格式
在首页下载最新版本的 method-result-modify.jar 文件
将下载的 method-result-modify.jar 文件放入 ja-netfilter 的 plugins 目录
在 ja-netfilter 的 config 目录下创建 MethodResultModify.conf 配置文件
支持所有 Java 基础类型和包装类型,包括布尔值、数值、字符串等
[RESULTS]
# 布尔值
EQUAL,com.example.LicenseChecker.isValid,true
EQUAL,com.example.LicenseChecker.isExpired,false
# 数值类型
EQUAL,com.example.Calculator.getIntValue,42
EQUAL,com.example.Calculator.getLongValue,9223372036854775807
EQUAL,com.example.Calculator.getDoubleValue,3.14159
# 字符串(需要双引号)
EQUAL,com.example.UserManager.getUserLevel,"Premium"
EQUAL,com.example.UserManager.getUserName,"Administrator"
# 特殊值
EQUAL,com.example.DataProvider.getNullValue,null展示基础类型返回值修改和字符串处理
[RESULTS]
EQUAL,com.company.license.LicenseValidator.isValid,true
EQUAL,com.company.license.LicenseValidator.isExpired,false
EQUAL,com.company.license.LicenseValidator.getLicenseType,"Professional"
EQUAL,com.company.license.LicenseValidator.getRemainingDays,365展示重载方法的精确匹配和方法签名指定
[RESULTS]
EQUAL,com.example.Calculator.calculate(I)I,100
EQUAL,com.example.Calculator.calculate(D)D,3.14159
EQUAL,com.example.Calculator.calculate(Ljava/lang/String;)Ljava/lang/String;,"Calculated"展示 v2.0.0 的复杂对象构造能力
[RESULTS]
# 用户对象构造
EQUAL,com.example.UserService.getUser,new com.example.dto.UserDto(1, "admin", true)
# 订单对象构造
EQUAL,com.example.OrderService.createOrder,new com.example.dto.OrderDto(12345, "PENDING", 99.99, new java.util.Date())
# 配置对象构造
EQUAL,com.example.ConfigService.getConfig,new com.example.config.AppConfig("production", true, 8080)展示静态方法调用和单例模式支持
[RESULTS]
# 静态方法创建对象
EQUAL,com.example.UserService.createUser,com.example.factory.UserFactory.createUser(1, "admin")
# 单例模式
EQUAL,com.example.ConfigService.getInstance,com.example.config.ConfigManager.getInstance()展示多层嵌套和混合构造模式
[RESULTS]
# 嵌套对象构造
EQUAL,com.example.OrderService.getOrder,new com.example.dto.OrderDto(new com.example.dto.UserDto(1, "admin", true), 2)
# 混合构造模式(构造函数+静态方法)
EQUAL,com.example.MixedService.getObject,new com.example.dto.OrderDto(com.example.factory.UserFactory.createUser(1, true), 2)
# 复杂嵌套
EQUAL,com.example.ComplexService.getComplexObject,new com.example.dto.ComplexDto(new com.example.dto.UserDto(1, true), new com.example.dto.ProductDto("product", 99.99))