Java Code Examples for org.springframework.cglib.reflect.FastMethod#invoke()

The following examples show how to use org.springframework.cglib.reflect.FastMethod#invoke() . 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: BeanUtil.java    From BlogManagePlatform with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@SneakyThrows
private static <T> T safeAs(Map<String, Object> map, T bean) {
	List<FastMethod> methods = setters(bean.getClass());
	for (FastMethod fastMethod : methods) {
		String field = StrUtil.lowerFirst(fastMethod.getName().substring(3));
		Object value = map.get(field);
		if (value == null) {
			continue;
		}
		if (PrimitiveUtil.isBaseType(value.getClass())) {
			value = PrimitiveUtil.cast(value, fastMethod.getParameterTypes()[0]);
			fastMethod.invoke(bean, new Object[] { value });
		} else {
			fastMethod.invoke(bean, new Object[] { value });
		}
	}
	return bean;
}
 
Example 2
Source File: RpcServerInvoker.java    From jim-framework with Apache License 2.0 6 votes vote down vote up
@Override
public RpcResponse invoke(RpcInvocation invocation) {
    String className = invocation.getClassName();
    Object serviceBean = handlerMap.get(className);

    Class<?> serviceClass = serviceBean.getClass();
    String methodName = invocation.getMethodName();
    Class<?>[] parameterTypes = invocation.getParameterTypes();
    Object[] parameters = invocation.getParameters();

    FastClass serviceFastClass = FastClass.create(serviceClass);
    FastMethod serviceFastMethod = serviceFastClass.getMethod(methodName, parameterTypes);
    try {
        Object result= serviceFastMethod.invoke(serviceBean, parameters);
        RpcResponse rpcResponse=new RpcResponse();
        rpcResponse.setResult(result);
        rpcResponse.setRequestId(invocation.getRequestId());
        return rpcResponse;
    } catch (InvocationTargetException e) {
        throw new RpcException(e);
    }
}
 
Example 3
Source File: NetComServerFactory.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
public static RpcResponse invokeService(RpcRequest request, Object serviceBean) {
	if (serviceBean==null) {
		serviceBean = serviceMap.get(request.getClassName());
	}
	if (serviceBean == null) {
		// TODO
	}

	RpcResponse response = new RpcResponse();

	if (System.currentTimeMillis() - request.getCreateMillisTime() > 180000) {
		response.setResult(new ReturnT<String>(ReturnT.FAIL_CODE, "The timestamp difference between admin and executor exceeds the limit."));
		return response;
	}
	if (accessToken!=null && accessToken.trim().length()>0 && !accessToken.trim().equals(request.getAccessToken())) {
		response.setResult(new ReturnT<String>(ReturnT.FAIL_CODE, "The access token[" + request.getAccessToken() + "] is wrong."));
		return response;
	}

	try {
		Class<?> serviceClass = serviceBean.getClass();
		String methodName = request.getMethodName();
		Class<?>[] parameterTypes = request.getParameterTypes();
		Object[] parameters = request.getParameters();

		FastClass serviceFastClass = FastClass.create(serviceClass);
		FastMethod serviceFastMethod = serviceFastClass.getMethod(methodName, parameterTypes);

		Object result = serviceFastMethod.invoke(serviceBean, parameters);

		response.setResult(result);
	} catch (Throwable t) {
		t.printStackTrace();
		response.setError(t.getMessage());
	}

	return response;
}
 
Example 4
Source File: NetComServerFactory.java    From xmfcn-spring-cloud with Apache License 2.0 5 votes vote down vote up
public static RpcResponse invokeService(RpcRequest request, Object serviceBean) {
	if (serviceBean==null) {
		serviceBean = serviceMap.get(request.getClassName());
	}
	if (serviceBean == null) {
		// TODO
	}

	RpcResponse response = new RpcResponse();

	if (System.currentTimeMillis() - request.getCreateMillisTime() > 180000) {
		response.setResult(new ReturnT<String>(ReturnT.FAIL_CODE, "The timestamp difference between admin and executor exceeds the limit."));
		return response;
	}
	if (accessToken!=null && accessToken.trim().length()>0 && !accessToken.trim().equals(request.getAccessToken())) {
		response.setResult(new ReturnT<String>(ReturnT.FAIL_CODE, "The access token[" + request.getAccessToken() + "] is wrong."));
		return response;
	}

	try {
		Class<?> serviceClass = serviceBean.getClass();
		String methodName = request.getMethodName();
		Class<?>[] parameterTypes = request.getParameterTypes();
		Object[] parameters = request.getParameters();

		FastClass serviceFastClass = FastClass.create(serviceClass);
		FastMethod serviceFastMethod = serviceFastClass.getMethod(methodName, parameterTypes);

		Object result = serviceFastMethod.invoke(serviceBean, parameters);

		response.setResult(result);
	} catch (Throwable t) {
		t.printStackTrace();
		response.setError(t.getMessage());
	}

	return response;
}