- I have searched the issues of this repository and believe that this is not a duplicate.
- I have searched the release notes of this repository and believe that this is not a duplicate.
Describe the feature
代码原因导致WireProtocl 无法被Wrapper机制封装.
背景
应用与应用之间有权限拦截的诉求, 身份认证这块采用了mTLS认证. 应用身份通过tls证书获取, 因此需要将TLS上下文里的身份信息传递到Protocol层. 目前对于Triple协议, 找到了WireProtocol作为切入点, 使用Wrapper机制覆写ChannelHandler配置逻辑.
@Wrapper(mismatches = {"qos"})
public class WireProtocolWrapper implements WireProtocol {
}
项目测试时 发现此方法会导致NPE. 原因如下:
问题代码块
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out)
throws Exception {
....
if (providerConnectionConfig != null && isSsl(in)) {
enableSsl(ctx, providerConnectionConfig);
} else {
for (final WireProtocol protocol : protocols) {
...
switch (result) {
case UNRECOGNIZED:
continue;
case RECOGNIZED:
// 这里通过getExtensionName获取protocolName. 由于我对WireProtocol进行了Wrapper, protocol#getClass返回的是WireProtocolWrapper类, 导致无法获取的protocolName为空.
String protocolName = url.getOrDefaultFrameworkModel().getExtensionLoader(WireProtocol.class)
.getExtensionName(protocol);
// 这里因为protocolName为空, 导致ConcurrentHashMap抛出NPE
hannelHandler localHandler = this.handlerMapper.getOrDefault(protocolName, handler);
....
}
}
....
}
}
建议:
- 出于扩展性需要, 是不是可以对WireProtocol协议暴露getName方法, 改为WireProtocol#getName 获取ProtocolName.
2条答案
按热度按时间mcdcgff01#
Could u pls submit a PR?
jc3wubiy2#
@CrazyHZM@icodening@EarthChen PTAL