|
@@ -4,17 +4,10 @@ import cc.uncarbon.framework.core.context.TenantContext;
|
|
|
import cc.uncarbon.framework.core.context.TenantContextHolder;
|
|
import cc.uncarbon.framework.core.context.TenantContextHolder;
|
|
|
import cc.uncarbon.framework.core.context.UserContext;
|
|
import cc.uncarbon.framework.core.context.UserContext;
|
|
|
import cc.uncarbon.framework.core.context.UserContextHolder;
|
|
import cc.uncarbon.framework.core.context.UserContextHolder;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
|
|
-import cn.hutool.json.JSONUtil;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.common.constants.CommonConstants;
|
|
import org.apache.dubbo.common.constants.CommonConstants;
|
|
|
import org.apache.dubbo.common.extension.Activate;
|
|
import org.apache.dubbo.common.extension.Activate;
|
|
|
-import org.apache.dubbo.rpc.Filter;
|
|
|
|
|
-import org.apache.dubbo.rpc.Invocation;
|
|
|
|
|
-import org.apache.dubbo.rpc.Invoker;
|
|
|
|
|
-import org.apache.dubbo.rpc.Result;
|
|
|
|
|
-import org.apache.dubbo.rpc.RpcContext;
|
|
|
|
|
-import org.apache.dubbo.rpc.RpcException;
|
|
|
|
|
|
|
+import org.apache.dubbo.rpc.*;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 自定义Dubbo提供者上下文
|
|
* 自定义Dubbo提供者上下文
|
|
@@ -28,20 +21,23 @@ public class ProviderContextFilter implements Filter {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
|
|
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
|
|
|
- // 从 Dubbo 附件中,取出用户上下文、租户上下文等业务字段
|
|
|
|
|
|
|
+ /*
|
|
|
|
|
+ 从 Dubbo 附件中,取出用户上下文、租户上下文等业务字段
|
|
|
|
|
+ since 1.6.0 附件内容不再是 JSON 字符串,直接使用可序列化的对象
|
|
|
|
|
+ */
|
|
|
|
|
|
|
|
- String userContextJson = RpcContext.getServerAttachment().getAttachment(UserContext.CAMEL_NAME);
|
|
|
|
|
- if (StrUtil.isNotEmpty(userContextJson)) {
|
|
|
|
|
- UserContext userContext = JSONUtil.parseObj(userContextJson).toBean(UserContext.class);
|
|
|
|
|
|
|
+ Object attachment = RpcContext.getServerAttachment().getObjectAttachment(UserContext.CAMEL_NAME);
|
|
|
|
|
+ if (attachment instanceof UserContext) {
|
|
|
|
|
+ UserContext userContext = (UserContext) attachment;
|
|
|
UserContextHolder.setUserContext(userContext);
|
|
UserContextHolder.setUserContext(userContext);
|
|
|
- log.debug("[Dubbo RPC] 取出当前用户上下文 >> {}", userContextJson);
|
|
|
|
|
|
|
+ log.debug("[Dubbo RPC] 取出当前用户上下文 >> {}", userContext);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- String tenantContextJson = RpcContext.getServerAttachment().getAttachment(TenantContext.CAMEL_NAME);
|
|
|
|
|
- if (StrUtil.isNotEmpty(tenantContextJson)) {
|
|
|
|
|
- TenantContext tenantContext = JSONUtil.parseObj(tenantContextJson).toBean(TenantContext.class);
|
|
|
|
|
|
|
+ attachment = RpcContext.getServerAttachment().getObjectAttachment(TenantContext.CAMEL_NAME);
|
|
|
|
|
+ if (attachment instanceof TenantContext) {
|
|
|
|
|
+ TenantContext tenantContext = (TenantContext) attachment;
|
|
|
TenantContextHolder.setTenantContext(tenantContext);
|
|
TenantContextHolder.setTenantContext(tenantContext);
|
|
|
- log.debug("[Dubbo RPC] 取出当前租户上下文 >> {}", tenantContextJson);
|
|
|
|
|
|
|
+ log.debug("[Dubbo RPC] 取出当前租户上下文 >> {}", tenantContext);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return invoker.invoke(invocation);
|
|
return invoker.invoke(invocation);
|