This is an automated email from the ASF dual-hosted git repository.

jianbin pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-seata.git


The following commit(s) were added to refs/heads/develop by this push:
     new 31399d7ead bugfix: fix hsf ConsumerModel convert error (#6632)
31399d7ead is described below

commit 31399d7ead6e70bf0de06d9a0c8952dbc5f216cd
Author: jimin <[email protected]>
AuthorDate: Wed Jun 26 17:32:41 2024 +0800

    bugfix: fix hsf ConsumerModel convert error (#6632)
---
 changes/en-us/develop.md                           |  1 +
 changes/zh-cn/develop.md                           |  1 +
 .../hsf/HsfTransactionConsumerFilter.java          | 60 ++++++++++++++++++++++
 ...lter.java => HsfTransactionProviderFilter.java} | 41 +++++----------
 .../io.seata/seata-hsf/reflect-config.json         | 14 ++++-
 .../com.taobao.hsf.invocation.filter.RPCFilter     |  3 +-
 6 files changed, 91 insertions(+), 29 deletions(-)

diff --git a/changes/en-us/develop.md b/changes/en-us/develop.md
index ec1e2d83a7..44801bc04e 100644
--- a/changes/en-us/develop.md
+++ b/changes/en-us/develop.md
@@ -14,6 +14,7 @@ Add changes here for all PR submitted to the develop branch.
 - [[#6104](https://github.com/seata/seata/pull/6104)] fix dubbo 3.x consumer 
can't generate TCC proxy in tcc mode.
 - [[#6409](https://github.com/seata/seata/pull/6409)] fix the failure of 
RemotingParser to prevent AT mode from executing.
 - [[#6628](https://github.com/seata/seata/pull/6628)] fix Alibaba Dubbo 
convert error.
+- [[#6632](https://github.com/seata/seata/pull/6632)] fix hsf ConsumerModel 
convert error.
 
 ### optimize:
 - [[#6044](https://github.com/seata/seata/pull/6044)] optimize derivative 
product check base on mysql
diff --git a/changes/zh-cn/develop.md b/changes/zh-cn/develop.md
index ce89801cbe..1320e42f5c 100644
--- a/changes/zh-cn/develop.md
+++ b/changes/zh-cn/develop.md
@@ -14,6 +14,7 @@
 - [[#6104](https://github.com/seata/seata/pull/6104)] 修复在TCC模式下, dubbo 
3.x版本消费者端不能生成TCC代理的问题
 - [[#6409](https://github.com/seata/seata/pull/6409)] 修复 RemotingParser 失败导致 
AT 模式无法执行的问题
 - [[#6628](https://github.com/seata/seata/pull/6628)] 修复 Alibaba Dubbo 转换错误
+- [[#6632](https://github.com/seata/seata/pull/6632)] 修复 hsf ConsumerModel 转换错误
 
 ### optimize:
 - [[#6044](https://github.com/seata/seata/pull/6044)] 优化MySQL衍生数据库判断逻辑
diff --git 
a/integration/hsf/src/main/java/io/seata/integration/hsf/HsfTransactionConsumerFilter.java
 
b/integration/hsf/src/main/java/io/seata/integration/hsf/HsfTransactionConsumerFilter.java
new file mode 100644
index 0000000000..7d17d895e6
--- /dev/null
+++ 
b/integration/hsf/src/main/java/io/seata/integration/hsf/HsfTransactionConsumerFilter.java
@@ -0,0 +1,60 @@
+/*
+ *  Copyright 1999-2019 Seata.io Group.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package io.seata.integration.hsf;
+
+import com.taobao.hsf.context.RPCContext;
+import com.taobao.hsf.invocation.Invocation;
+import com.taobao.hsf.invocation.InvocationHandler;
+import com.taobao.hsf.invocation.RPCResult;
+import com.taobao.hsf.invocation.filter.ClientFilter;
+import com.taobao.hsf.util.concurrent.ListenableFuture;
+import io.seata.core.context.RootContext;
+import io.seata.core.model.BranchType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The type Hsf transaction consumer filter.
+ */
+public class HsfTransactionConsumerFilter implements ClientFilter {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(HsfTransactionConsumerFilter.class);
+
+    @Override
+    public ListenableFuture<RPCResult> invoke(InvocationHandler nextHandler, 
Invocation invocation) throws Throwable {
+        String xid = RootContext.getXID();
+        BranchType branchType = RootContext.getBranchType();
+
+        if (LOGGER.isDebugEnabled()) {
+            LOGGER.debug("xid in RootContext[{}], branchType in 
RootContext[{}]", xid, branchType);
+        }
+        if (xid != null) {
+            RPCContext.getClientContext().putAttachment(RootContext.KEY_XID, 
xid);
+            
RPCContext.getClientContext().putAttachment(RootContext.KEY_BRANCH_TYPE, 
branchType.name());
+        }
+        try {
+            return nextHandler.invoke(invocation);
+        } finally {
+            
RPCContext.getClientContext().removeAttachment(RootContext.KEY_XID);
+            
RPCContext.getClientContext().removeAttachment(RootContext.KEY_BRANCH_TYPE);
+        }
+    }
+
+    @Override
+    public void onResponse(Invocation invocation, RPCResult rpcResult) {
+
+    }
+}
diff --git 
a/integration/hsf/src/main/java/io/seata/integration/hsf/HsfTransactionFilter.java
 
b/integration/hsf/src/main/java/io/seata/integration/hsf/HsfTransactionProviderFilter.java
similarity index 69%
rename from 
integration/hsf/src/main/java/io/seata/integration/hsf/HsfTransactionFilter.java
rename to 
integration/hsf/src/main/java/io/seata/integration/hsf/HsfTransactionProviderFilter.java
index cfd86db79b..99e3b1f5dc 100644
--- 
a/integration/hsf/src/main/java/io/seata/integration/hsf/HsfTransactionFilter.java
+++ 
b/integration/hsf/src/main/java/io/seata/integration/hsf/HsfTransactionProviderFilter.java
@@ -19,7 +19,6 @@ import com.taobao.hsf.context.RPCContext;
 import com.taobao.hsf.invocation.Invocation;
 import com.taobao.hsf.invocation.InvocationHandler;
 import com.taobao.hsf.invocation.RPCResult;
-import com.taobao.hsf.invocation.filter.ClientFilter;
 import com.taobao.hsf.invocation.filter.ServerFilter;
 import com.taobao.hsf.util.concurrent.ListenableFuture;
 import io.seata.common.util.StringUtils;
@@ -29,43 +28,33 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * The type Transaction propagation filter.
- *
- * @author slievrly
+ * The type Hsf transaction provider filter.
  */
-public class HsfTransactionFilter implements ClientFilter, ServerFilter {
+public class HsfTransactionProviderFilter implements ServerFilter {
 
-    private static final Logger LOGGER = 
LoggerFactory.getLogger(HsfTransactionFilter.class);
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(HsfTransactionProviderFilter.class);
 
     @Override
-    public ListenableFuture<RPCResult> invoke(InvocationHandler 
invocationHandler, Invocation invocation)
-        throws Throwable {
-        String xid = RootContext.getXID();
-        BranchType branchType = RootContext.getBranchType();
+    public ListenableFuture<RPCResult> invoke(InvocationHandler nextHandler, 
Invocation invocation) throws Throwable {
 
         Object rpcXid = 
RPCContext.getServerContext().getAttachment(RootContext.KEY_XID);
         Object rpcBranchType = 
RPCContext.getServerContext().getAttachment(RootContext.KEY_BRANCH_TYPE);
         if (LOGGER.isDebugEnabled()) {
-            LOGGER.debug("xid in RootContext[{}] xid in RpcContext[{}]", xid, 
rpcXid);
+            LOGGER.debug("xid in RpcContext[{}], branchType in 
RpcContext[{}]", rpcXid, rpcBranchType);
         }
         boolean bind = false;
-        if (xid != null) {
-            RPCContext.getClientContext().putAttachment(RootContext.KEY_XID, 
xid);
-            
RPCContext.getClientContext().putAttachment(RootContext.KEY_BRANCH_TYPE, 
branchType.name());
-        } else {
-            if (rpcXid != null) {
-                RootContext.bind(rpcXid.toString());
-                if (StringUtils.equals(BranchType.TCC.name(), 
rpcBranchType.toString())) {
-                    RootContext.bindBranchType(BranchType.TCC);
-                }
-                bind = true;
-                if (LOGGER.isDebugEnabled()) {
-                    LOGGER.debug("bind xid [{}] branchType [{}] to 
RootContext", rpcXid, rpcBranchType);
-                }
+        if (rpcXid != null) {
+            RootContext.bind(rpcXid.toString());
+            if (StringUtils.equals(BranchType.TCC.name(), 
rpcBranchType.toString())) {
+                RootContext.bindBranchType(BranchType.TCC);
+            }
+            bind = true;
+            if (LOGGER.isDebugEnabled()) {
+                LOGGER.debug("bind xid [{}] branchType [{}] to RootContext", 
rpcXid, rpcBranchType);
             }
         }
         try {
-            return invocationHandler.invoke(invocation);
+            return nextHandler.invoke(invocation);
         } finally {
             if (bind) {
                 BranchType previousBranchType = RootContext.getBranchType();
@@ -89,8 +78,6 @@ public class HsfTransactionFilter implements ClientFilter, 
ServerFilter {
                     }
                 }
             }
-            
RPCContext.getClientContext().removeAttachment(RootContext.KEY_XID);
-            
RPCContext.getClientContext().removeAttachment(RootContext.KEY_BRANCH_TYPE);
             
RPCContext.getServerContext().removeAttachment(RootContext.KEY_XID);
             
RPCContext.getServerContext().removeAttachment(RootContext.KEY_BRANCH_TYPE);
         }
diff --git 
a/integration/hsf/src/main/resources/META-INF/native-image/io.seata/seata-hsf/reflect-config.json
 
b/integration/hsf/src/main/resources/META-INF/native-image/io.seata/seata-hsf/reflect-config.json
index ec2ca59dbd..f7ef101237 100644
--- 
a/integration/hsf/src/main/resources/META-INF/native-image/io.seata/seata-hsf/reflect-config.json
+++ 
b/integration/hsf/src/main/resources/META-INF/native-image/io.seata/seata-hsf/reflect-config.json
@@ -3,7 +3,19 @@
     "condition": {
       "typeReachable": "com.taobao.hsf.invocation.filter.RPCFilter"
     },
-    "name": "io.seata.integration.hsf.HsfTransactionFilter",
+    "name": "io.seata.integration.hsf.HsfTransactionConsumerFilter",
+    "methods": [
+      {
+        "name": "<init>",
+        "parameterTypes": []
+      }
+    ]
+  },
+  {
+    "condition": {
+      "typeReachable": "com.taobao.hsf.invocation.filter.RPCFilter"
+    },
+    "name": "io.seata.integration.hsf.HsfTransactionProviderFilter",
     "methods": [
       {
         "name": "<init>",
diff --git 
a/integration/hsf/src/main/resources/META-INF/services/com.taobao.hsf.invocation.filter.RPCFilter
 
b/integration/hsf/src/main/resources/META-INF/services/com.taobao.hsf.invocation.filter.RPCFilter
index 6938cc1a55..a4cd6b8c35 100644
--- 
a/integration/hsf/src/main/resources/META-INF/services/com.taobao.hsf.invocation.filter.RPCFilter
+++ 
b/integration/hsf/src/main/resources/META-INF/services/com.taobao.hsf.invocation.filter.RPCFilter
@@ -1 +1,2 @@
-io.seata.integration.hsf.HsfTransactionFilter
\ No newline at end of file
+io.seata.integration.hsf.HsfTransactionConsumerFilter
+io.seata.integration.hsf.HsfTransactionProviderFilter
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to