com.wl4g.infra.common.bridge.RpcContextProviderInterceptorBridges Maven / Gradle / Ivy
/*
* Copyright (C) 2017 ~ 2025 the original author or authors.
* James Wong Technology CO.LTD.
* All rights reserved.
*
* 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.
*
* Reference to website: https://wl4g.github.io
*/
package com.wl4g.infra.common.bridge;
import static com.wl4g.infra.common.lang.ClassUtils2.resolveClassNameNullable;
import static com.wl4g.infra.common.reflect.ReflectionUtils2.findFieldNullable;
import static com.wl4g.infra.common.reflect.ReflectionUtils2.findMethodNullable;
import static com.wl4g.infra.common.reflect.ReflectionUtils2.getField;
import static com.wl4g.infra.common.reflect.ReflectionUtils2.invokeMethod;
import static com.wl4g.infra.common.reflect.ReflectionUtils2.makeAccessible;
import static java.util.Objects.nonNull;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
* {@link RpcContextProviderInterceptorBridges}
*
* @author James Wong <[email protected]>
* @version v1.0 2021-01-29
* @since v2.0
* @see https://blog.csdn.net/zoinsung_lee/article/details/82529624
*/
public abstract class RpcContextProviderInterceptorBridges {
public static int invokeFieldOrder() {
if (nonNull(ORDER_FIELD)) {
return (int) getField(ORDER_FIELD, null, true);
}
return 0;
}
public static boolean invokeCheckSupportTypeProxy(Object target, Class> actualOriginalTargetClass) {
if (nonNull(checkSupportTypeProxyMethod)) {
makeAccessible(checkSupportTypeProxyMethod);
return (boolean) invokeMethod(checkSupportTypeProxyMethod, null, new Object[] { target, actualOriginalTargetClass });
}
return false;
}
public static boolean invokeCheckSupportMethodProxy(
Object target,
Method method,
Class> actualOriginalTargetClass,
Object... args) {
if (nonNull(checkSupportMethodProxyMethod)) {
makeAccessible(checkSupportMethodProxyMethod);
return (boolean) invokeMethod(checkSupportMethodProxyMethod, null,
new Object[] { target, method, actualOriginalTargetClass, args });
}
return false;
}
public static boolean hasProviderFeignRpcContextClass() {
return nonNull(providerRpcContextFilterClass);
}
public static final String providerRpcContextFilterClassName = "com.wl4g.infra.integration.feign.core.context.internal.ProviderFeignContextFilter";
private static final Class> providerRpcContextFilterClass = resolveClassNameNullable(providerRpcContextFilterClassName);
private static final Method checkSupportTypeProxyMethod = findMethodNullable(providerRpcContextFilterClass,
"checkSupportTypeProxy", Object.class, Class.class);
private static final Method checkSupportMethodProxyMethod = findMethodNullable(providerRpcContextFilterClass,
"checkSupportMethodProxy", Object.class, Method.class, Class.class, Object[].class);
private static final Field ORDER_FIELD = findFieldNullable(providerRpcContextFilterClass, "ORDER", int.class);
}