Skip to content

Commit

Permalink
fix the failure of @BusinessActionContextParamete annotation to set p…
Browse files Browse the repository at this point in the history
…arameters into BusinessActionContext
  • Loading branch information
TakeActionNow2019 committed Apr 8, 2024
1 parent f43e2a9 commit 15014ad
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package io.seata.spring;

import io.seata.integration.tx.api.interceptor.parser.TargetClassParser;
import io.seata.spring.util.SpringProxyUtils;
import io.seata.rm.tcc.util.SpringProxyUtils;

/**
* @author leezongjie
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import io.seata.spring.annotation.scannercheckers.PackageScannerChecker;
import io.seata.spring.remoting.parser.RemotingFactoryBeanParser;
import io.seata.spring.util.OrderUtil;
import io.seata.spring.util.SpringProxyUtils;
import io.seata.rm.tcc.util.SpringProxyUtils;
import io.seata.tm.TMClient;
import io.seata.tm.api.FailureHandler;
import io.seata.tm.api.FailureHandlerHolder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import io.seata.integration.tx.api.remoting.RemotingDesc;
import io.seata.integration.tx.api.remoting.parser.AbstractedRemotingParser;
import io.seata.integration.tx.api.remoting.parser.DefaultRemotingParser;
import io.seata.spring.util.SpringProxyUtils;
import io.seata.rm.tcc.util.SpringProxyUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.util.Assert;

Expand Down Expand Up @@ -91,4 +91,4 @@ public short getProtocol() {
return 0;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
import io.seata.integration.tx.api.interceptor.TwoPhaseBusinessActionParam;
import io.seata.integration.tx.api.interceptor.handler.AbstractProxyInvocationHandler;
import io.seata.integration.tx.api.remoting.RemotingDesc;
import io.seata.integration.tx.api.util.DubboUtil;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;
import io.seata.rm.tcc.util.SpringProxyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import static io.seata.common.ConfigurationKeys.TCC_ACTION_INTERCEPTOR_ORDER;
Expand All @@ -46,6 +50,8 @@
*/
public class TccActionInterceptorHandler extends AbstractProxyInvocationHandler {

private static final Logger LOGGER = LoggerFactory.getLogger(TccActionInterceptorHandler.class);

private static final int ORDER_NUM = ConfigurationFactory.getInstance().getInt(TCC_ACTION_INTERCEPTOR_ORDER,
DefaultValues.TCC_ACTION_INTERCEPTOR_ORDER);

Expand All @@ -67,7 +73,7 @@ protected Object doInvoke(InvocationWrapper invocation) throws Throwable {
//not in transaction, or this interceptor is disabled
return invocation.proceed();
}
Method method = invocation.getMethod();
Method method = getActionInterfaceMethod(invocation);
TwoPhaseBusinessAction businessAction = parseAnnotation(method);

//try method
Expand Down Expand Up @@ -110,6 +116,57 @@ protected Object doInvoke(InvocationWrapper invocation) throws Throwable {
return invocation.proceed();
}

/**
* get the method from interface
*
* @param invocation the invocation
* @return the action interface method
*/
protected Method getActionInterfaceMethod(InvocationWrapper invocation) {
Class<?> interfaceType = null;
try {
if (remotingDesc == null) {
interfaceType = getProxyInterface(invocation.getTarget());
} else {
interfaceType = remotingDesc.getServiceClass();
}
if (interfaceType == null && remotingDesc.getServiceClassName() != null) {
interfaceType = Class.forName(remotingDesc.getServiceClassName(), true,
Thread.currentThread().getContextClassLoader());
}
if (interfaceType == null) {
return invocation.getMethod();
}
return interfaceType.getMethod(invocation.getMethod().getName(),
invocation.getMethod().getParameterTypes());
} catch (NoSuchMethodException e) {
if (interfaceType != null && !invocation.getMethod().getName().equals("toString")) {
LOGGER.warn("no such method '{}' from interface {}", invocation.getMethod().getName(), interfaceType.getName());
}
return invocation.getMethod();
} catch (Exception e) {
LOGGER.warn("get Method from interface failed", e);
return invocation.getMethod();
}
}

/**
* get the interface of proxy
*
* @param proxyBean the proxy bean
* @return proxy interface
* @throws Exception the exception
*/
protected Class<?> getProxyInterface(Object proxyBean) throws Exception {
if (DubboUtil.isDubboProxyName(proxyBean.getClass().getName())) {
//dubbo javaassist proxy
return DubboUtil.getAssistInterface(proxyBean);
} else {
//jdk/cglib proxy
return SpringProxyUtils.getTargetInterface(proxyBean);
}
}

private TwoPhaseBusinessAction parseAnnotation(Method methodKey) throws NoSuchMethodException {
TwoPhaseBusinessAction result = parseAnnotationCache.computeIfAbsent(methodKey, method -> {
TwoPhaseBusinessAction businessAction = method.getAnnotation(TwoPhaseBusinessAction.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.seata.spring.util;
package io.seata.rm.tcc.util;

import java.lang.reflect.Field;
import java.lang.reflect.Proxy;
Expand Down

0 comments on commit 15014ad

Please sign in to comment.