Java Code Examples for org.springframework.util.ReflectionUtils#isObjectMethod()

The following examples show how to use org.springframework.util.ReflectionUtils#isObjectMethod() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MvcUriComponentsBuilder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) {
	if (getControllerMethod.equals(method)) {
		return this.controllerMethod;
	}
	else if (getArgumentValues.equals(method)) {
		return this.argumentValues;
	}
	else if (getControllerType.equals(method)) {
		return this.controllerType;
	}
	else if (ReflectionUtils.isObjectMethod(method)) {
		return ReflectionUtils.invokeMethod(method, obj, args);
	}
	else {
		this.controllerMethod = method;
		this.argumentValues = args;
		Class<?> returnType = method.getReturnType();
		return (void.class == returnType ? null : returnType.cast(initProxy(returnType, this)));
	}
}
 
Example 2
Source File: WxAsyncMethodInterceptor.java    From FastBootWeixin with Apache License 2.0 6 votes vote down vote up
/**
 * 关于这个方法,还发现了一个很神奇的现象。。。
 * 当我调试时,偶尔会发现微信会收到消息,消息内容是被代理的对象的toString(),这就奇怪了,从哪里来的呢?
 * 而且不调试时没这个问题。。。仔细分析发现,应该就是和调试时调试器会调用对象的toString方法导致的
 * 因为调用了代理对象的toString,进入这个拦截器,只要进入这个拦截器,最终就会调用send。因为toString()最终返回string,故会发出那个消息。。。
 * 又一次被调试时toString坑了。添加方法过滤解决此问题。
 *
 * @param invocation
 * @return
 * @throws Throwable
 */
@Override
public Object invoke(final MethodInvocation invocation) throws Throwable {
    if (ReflectionUtils.isObjectMethod(invocation.getMethod())) {
        return ReflectionUtils.invokeMethod(invocation.getMethod(), invocation.getThis(), invocation.getArguments());
    }
    WxRequest wxRequest = WxWebUtils.getWxRequestFromRequest();
    wxAsyncMessageTemplate.send(wxRequest, () -> {
        try {
            return invocation.proceed();
        } catch (Throwable e) {
            throw new WxApiException(e.getMessage(), e);
        }
    });
    return null;
}
 
Example 3
Source File: WxInvokerProxyFactoryBean.java    From FastBootWeixin with Apache License 2.0 6 votes vote down vote up
/**
 * 后续加上缓存,一定要加
 *
 * @param inv
 * @return the result
 * @throws Throwable
 */
@Override
public Object invoke(MethodInvocation inv) throws Throwable {
    if (ReflectionUtils.isObjectMethod(inv.getMethod())) {
        if (ReflectionUtils.isToStringMethod(inv.getMethod())) {
            return clazz.getName();
        }
        return ReflectionUtils.invokeMethod(inv.getMethod(), inv.getThis(), inv.getArguments());
    }
    WxApiMethodInfo wxApiMethodInfo = methodCache.get(inv.getMethod());
    if (wxApiMethodInfo == null) {
        wxApiMethodInfo = new WxApiMethodInfo(inv.getMethod(), wxApiTypeInfo);
        methodCache.put(inv.getMethod(), wxApiMethodInfo);
    }
    return wxApiExecutor.execute(wxApiMethodInfo, inv.getArguments());
}
 
Example 4
Source File: MvcUriComponentsBuilder.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) {
	if (getControllerMethod.equals(method)) {
		return this.controllerMethod;
	}
	else if (getArgumentValues.equals(method)) {
		return this.argumentValues;
	}
	else if (getControllerType.equals(method)) {
		return this.controllerType;
	}
	else if (ReflectionUtils.isObjectMethod(method)) {
		return ReflectionUtils.invokeMethod(method, obj, args);
	}
	else {
		this.controllerMethod = method;
		this.argumentValues = args;
		Class<?> returnType = method.getReturnType();
		return (void.class == returnType ? null : returnType.cast(initProxy(returnType, this)));
	}
}
 
Example 5
Source File: ResolvableMethod.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
@Nullable
public Object intercept(Object object, Method method, Object[] args, MethodProxy proxy) {
	if (ReflectionUtils.isObjectMethod(method)) {
		return ReflectionUtils.invokeMethod(method, object, args);
	}
	else {
		this.invokedMethod = method;
		return null;
	}
}
 
Example 6
Source File: MvcUriComponentsBuilder.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
@Nullable
public Object intercept(Object obj, Method method, Object[] args, @Nullable MethodProxy proxy) {
	if (method.getName().equals("getControllerType")) {
		return this.controllerType;
	}
	else if (method.getName().equals("getControllerMethod")) {
		return this.controllerMethod;
	}
	else if (method.getName().equals("getArgumentValues")) {
		return this.argumentValues;
	}
	else if (ReflectionUtils.isObjectMethod(method)) {
		return ReflectionUtils.invokeMethod(method, obj, args);
	}
	else {
		this.controllerMethod = method;
		this.argumentValues = args;
		Class<?> returnType = method.getReturnType();
		try {
			return (returnType == void.class ? null : returnType.cast(initProxy(returnType, this)));
		}
		catch (Throwable ex) {
			throw new IllegalStateException(
					"Failed to create proxy for controller method return type: " + method, ex);
		}
	}
}
 
Example 7
Source File: ResolvableMethod.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
@Nullable
public Object intercept(Object object, Method method, Object[] args, MethodProxy proxy) {
	if (ReflectionUtils.isObjectMethod(method)) {
		return ReflectionUtils.invokeMethod(method, object, args);
	}
	else {
		this.invokedMethod = method;
		return null;
	}
}
 
Example 8
Source File: ResolvableMethod.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
@Nullable
public Object intercept(Object object, Method method, Object[] args, MethodProxy proxy) {
	if (ReflectionUtils.isObjectMethod(method)) {
		return ReflectionUtils.invokeMethod(method, object, args);
	}
	else {
		this.invokedMethod = method;
		return null;
	}
}
 
Example 9
Source File: MvcUriComponentsBuilder.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
@Nullable
public Object intercept(Object obj, Method method, Object[] args, @Nullable MethodProxy proxy) {
	if (method.getName().equals("getControllerType")) {
		return this.controllerType;
	}
	else if (method.getName().equals("getControllerMethod")) {
		return this.controllerMethod;
	}
	else if (method.getName().equals("getArgumentValues")) {
		return this.argumentValues;
	}
	else if (ReflectionUtils.isObjectMethod(method)) {
		return ReflectionUtils.invokeMethod(method, obj, args);
	}
	else {
		this.controllerMethod = method;
		this.argumentValues = args;
		Class<?> returnType = method.getReturnType();
		try {
			return (returnType == void.class ? null : returnType.cast(initProxy(returnType, this)));
		}
		catch (Throwable ex) {
			throw new IllegalStateException(
					"Failed to create proxy for controller method return type: " + method, ex);
		}
	}
}
 
Example 10
Source File: ResolvableMethod.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
@Nullable
public Object intercept(Object object, Method method, Object[] args, MethodProxy proxy) {
	if (ReflectionUtils.isObjectMethod(method)) {
		return ReflectionUtils.invokeMethod(method, object, args);
	}
	else {
		this.invokedMethod = method;
		return null;
	}
}
 
Example 11
Source File: AbstractResolver.java    From spring-data with Apache License 2.0 5 votes vote down vote up
@Override
public Object intercept(final Object obj, final Method method, final Object[] args, final MethodProxy proxy)
		throws Throwable {

	if (GET_ENTITY_METHOD.equals(method)) {
		return ensureResolved();
	}

	if (GET_REF_ID_METHOD.equals(method)) {
		return id;
	}

	if (ReflectionUtils.isObjectMethod(method)) {
		if (ReflectionUtils.isToStringMethod(method)) {
			return proxyToString();
		}

		else if (ReflectionUtils.isEqualsMethod(method)) {
			return proxyEquals(proxy, args[0]);
		}

		else if (ReflectionUtils.isHashCodeMethod(method)) {
			return proxyHashCode();
		}
	}

	final Object result = ensureResolved();
	return result == null ? null : method.invoke(result, args);
}
 
Example 12
Source File: CssQueryMethodInterceptor.java    From mica with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Nullable
@Override
public Object intercept(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
	// 如果是 toString eq 等方法都不准确,故直接返回死值
	if (ReflectionUtils.isObjectMethod(method)) {
		return methodProxy.invokeSuper(object, args);
	}
	// 非 bean 方法
	PropertyDescriptor propertyDescriptor = BeanUtils.findPropertyForMethod(method, clazz);
	if (propertyDescriptor == null) {
		return methodProxy.invokeSuper(object, args);
	}
	// 非 read 的方法,只处理 get 方法 is
	if (!method.equals(propertyDescriptor.getReadMethod())) {
		return methodProxy.invokeSuper(object, args);
	}
	// 兼容 lombok bug 强制首字母小写: https://github.com/rzwitserloot/lombok/issues/1861
	String fieldName = StringUtil.firstCharToLower(propertyDescriptor.getDisplayName());
	Field field = clazz.getDeclaredField(fieldName);
	if (field == null) {
		return methodProxy.invokeSuper(object, args);
	}
	CssQuery cssQuery = field.getAnnotation(CssQuery.class);
	// 没有注解,不代理
	if (cssQuery == null) {
		return methodProxy.invokeSuper(object, args);
	}
	Class<?> returnType = method.getReturnType();
	boolean isColl = Collection.class.isAssignableFrom(returnType);
	String cssQueryValue = cssQuery.value();
	// 是否为 bean 中 bean
	boolean isInner = cssQuery.inner();
	if (isInner) {
		return proxyInner(cssQueryValue, method, returnType, isColl);
	}
	Object proxyValue = proxyValue(cssQueryValue, cssQuery, returnType, isColl);
	if (String.class.isAssignableFrom(returnType)) {
		return proxyValue;
	}
	// 用于读取 field 上的注解
	TypeDescriptor typeDescriptor = new TypeDescriptor(field);
	return ConvertUtil.convert(proxyValue, typeDescriptor);
}