org.springframework.core.MethodIntrospector Java Examples

The following examples show how to use org.springframework.core.MethodIntrospector. 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: AbstractMethodMessageHandler.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Detect if the given handler has any methods that can handle messages and if
 * so register it with the extracted mapping information.
 * @param handler the handler to check, either an instance of a Spring bean name
 */
protected final void detectHandlerMethods(final Object handler) {
	Class<?> handlerType;
	if (handler instanceof String) {
		ApplicationContext context = getApplicationContext();
		Assert.state(context != null, "ApplicationContext is required for resolving handler bean names");
		handlerType = context.getType((String) handler);
	}
	else {
		handlerType = handler.getClass();
	}

	if (handlerType != null) {
		final Class<?> userType = ClassUtils.getUserClass(handlerType);
		Map<Method, T> methods = MethodIntrospector.selectMethods(userType,
				(MethodIntrospector.MetadataLookup<T>) method -> getMappingForMethod(method, userType));
		if (logger.isDebugEnabled()) {
			logger.debug(formatMappings(userType, methods));
		}
		methods.forEach((key, value) -> registerHandlerMethod(handler, key, value));
	}
}
 
Example #2
Source File: AbstractMethodMessageHandler.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Detect if the given handler has any methods that can handle messages and if
 * so register it with the extracted mapping information.
 * <p><strong>Note:</strong> This method is protected and can be invoked by
 * sub-classes, but this should be done on startup only as documented in
 * {@link #registerHandlerMethod}.
 * @param handler the handler to check, either an instance of a Spring bean name
 */
protected final void detectHandlerMethods(Object handler) {
	Class<?> handlerType;
	if (handler instanceof String) {
		ApplicationContext context = getApplicationContext();
		Assert.state(context != null, "ApplicationContext is required for resolving handler bean names");
		handlerType = context.getType((String) handler);
	}
	else {
		handlerType = handler.getClass();
	}
	if (handlerType != null) {
		final Class<?> userType = ClassUtils.getUserClass(handlerType);
		Map<Method, T> methods = MethodIntrospector.selectMethods(userType,
				(MethodIntrospector.MetadataLookup<T>) method -> getMappingForMethod(method, userType));
		if (logger.isDebugEnabled()) {
			logger.debug(formatMappings(userType, methods));
		}
		methods.forEach((key, value) -> registerHandlerMethod(handler, key, value));
	}
}
 
Example #3
Source File: AbstractHandlerMethodMapping.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Look for handler methods in the specified handler bean.
 * @param handler either a bean name or an actual handler instance
 * @see #getMappingForMethod
 */
protected void detectHandlerMethods(Object handler) {
	Class<?> handlerType = (handler instanceof String ?
			obtainApplicationContext().getType((String) handler) : handler.getClass());

	if (handlerType != null) {
		Class<?> userType = ClassUtils.getUserClass(handlerType);
		Map<Method, T> methods = MethodIntrospector.selectMethods(userType,
				(MethodIntrospector.MetadataLookup<T>) method -> {
					try {
						return getMappingForMethod(method, userType);
					}
					catch (Throwable ex) {
						throw new IllegalStateException("Invalid mapping on handler class [" +
								userType.getName() + "]: " + method, ex);
					}
				});
		if (logger.isTraceEnabled()) {
			logger.trace(formatMappings(userType, methods));
		}
		methods.forEach((method, mapping) -> {
			Method invocableMethod = AopUtils.selectInvocableMethod(method, userType);
			registerHandlerMethod(handler, invocableMethod, mapping);
		});
	}
}
 
Example #4
Source File: MvcUriComponentsBuilder.java    From java-technology-stack with MIT License 6 votes vote down vote up
private static Method getMethod(Class<?> controllerType, final String methodName, final Object... args) {
	MethodFilter selector = method -> {
		String name = method.getName();
		int argLength = method.getParameterCount();
		return (name.equals(methodName) && argLength == args.length);
	};
	Set<Method> methods = MethodIntrospector.selectMethods(controllerType, selector);
	if (methods.size() == 1) {
		return methods.iterator().next();
	}
	else if (methods.size() > 1) {
		throw new IllegalArgumentException(String.format(
				"Found two methods named '%s' accepting arguments %s in controller %s: [%s]",
				methodName, Arrays.asList(args), controllerType.getName(), methods));
	}
	else {
		throw new IllegalArgumentException("No method named '" + methodName + "' with " + args.length +
				" arguments found in controller " + controllerType.getName());
	}
}
 
Example #5
Source File: ClientFactory.java    From faster-framework-project with Apache License 2.0 6 votes vote down vote up
public Object createClientProxy(Class<?> target) {
    GRpcService grpcService = target.getAnnotation(GRpcService.class);
    ChannelProperty channelProperty = serverChannelMap.get(grpcService.value());
    if (channelProperty == null) {
        throw new GRpcChannelCreateException("GRpcService scheme:{" + grpcService.value() + "} was not found in properties.Please check your configuration.");
    }
    ManageChannelProxy manageChannelProxy = new ManageChannelProxy(channelProperty, marshallerFactory);
    //获取该类下所有包含GrpcMethod的注解,创建call定义
    Map<Method, GRpcMethod> annotatedMethods = MethodIntrospector.selectMethods(target,
            (MethodIntrospector.MetadataLookup<GRpcMethod>) method -> AnnotatedElementUtils.findMergedAnnotation(method, GRpcMethod.class));
    annotatedMethods.forEach((k, v) -> {
        String annotationMethodName = v.value();
        MethodCallProperty methodCallProperty = new MethodCallProperty();
        methodCallProperty.setMethod(k);
        methodCallProperty.setMethodName(StringUtils.isEmpty(annotationMethodName) ? k.getName() : annotationMethodName);
        methodCallProperty.setMethodType(v.type());
        methodCallProperty.setScheme(grpcService.scheme());
        manageChannelProxy.addCall(methodCallProperty);
    });
    return Proxy.newProxyInstance(target.getClassLoader(), new Class[]{target}, manageChannelProxy);
}
 
Example #6
Source File: AbstractHandlerMethodMapping.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Look for handler methods in a handler.
 * @param handler the bean name of a handler or a handler instance
 */
protected void detectHandlerMethods(final Object handler) {
	Class<?> handlerType = (handler instanceof String ?
			obtainApplicationContext().getType((String) handler) : handler.getClass());

	if (handlerType != null) {
		final Class<?> userType = ClassUtils.getUserClass(handlerType);
		Map<Method, T> methods = MethodIntrospector.selectMethods(userType,
				(MethodIntrospector.MetadataLookup<T>) method -> getMappingForMethod(method, userType));
		if (logger.isTraceEnabled()) {
			logger.trace(formatMappings(userType, methods));
		}
		methods.forEach((key, mapping) -> {
			Method invocableMethod = AopUtils.selectInvocableMethod(key, userType);
			registerHandlerMethod(handler, invocableMethod, mapping);
		});
	}
}
 
Example #7
Source File: MvcUriComponentsBuilder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static Method getMethod(Class<?> controllerType, final String methodName, final Object... args) {
	MethodFilter selector = new MethodFilter() {
		@Override
		public boolean matches(Method method) {
			String name = method.getName();
			int argLength = method.getParameterTypes().length;
			return (name.equals(methodName) && argLength == args.length);
		}
	};
	Set<Method> methods = MethodIntrospector.selectMethods(controllerType, selector);
	if (methods.size() == 1) {
		return methods.iterator().next();
	}
	else if (methods.size() > 1) {
		throw new IllegalArgumentException(String.format(
				"Found two methods named '%s' accepting arguments %s in controller %s: [%s]",
				methodName, Arrays.asList(args), controllerType.getName(), methods));
	}
	else {
		throw new IllegalArgumentException("No method named '" + methodName + "' with " + args.length +
				" arguments found in controller " + controllerType.getName());
	}
}
 
Example #8
Source File: AbstractMethodMessageHandler.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Detect if the given handler has any methods that can handle messages and if
 * so register it with the extracted mapping information.
 * @param handler the handler to check, either an instance of a Spring bean name
 */
protected final void detectHandlerMethods(final Object handler) {
	Class<?> handlerType;
	if (handler instanceof String) {
		ApplicationContext context = getApplicationContext();
		Assert.state(context != null, "ApplicationContext is required for resolving handler bean names");
		handlerType = context.getType((String) handler);
	}
	else {
		handlerType = handler.getClass();
	}

	if (handlerType != null) {
		final Class<?> userType = ClassUtils.getUserClass(handlerType);
		Map<Method, T> methods = MethodIntrospector.selectMethods(userType,
				(MethodIntrospector.MetadataLookup<T>) method -> getMappingForMethod(method, userType));
		if (logger.isDebugEnabled()) {
			logger.debug(methods.size() + " message handler methods found on " + userType + ": " + methods);
		}
		methods.forEach((key, value) -> registerHandlerMethod(handler, key, value));
	}
}
 
Example #9
Source File: AbstractMethodMessageHandler.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Detect if the given handler has any methods that can handle messages and if
 * so register it with the extracted mapping information.
 * @param handler the handler to check, either an instance of a Spring bean name
 */
protected final void detectHandlerMethods(final Object handler) {
	Class<?> handlerType = (handler instanceof String ?
			this.applicationContext.getType((String) handler) : handler.getClass());
	final Class<?> userType = ClassUtils.getUserClass(handlerType);

	Map<Method, T> methods = MethodIntrospector.selectMethods(userType,
			new MethodIntrospector.MetadataLookup<T>() {
				@Override
				public T inspect(Method method) {
					return getMappingForMethod(method, userType);
				}
			});

	if (logger.isDebugEnabled()) {
		logger.debug(methods.size() + " message handler methods found on " + userType + ": " + methods);
	}
	for (Map.Entry<Method, T> entry : methods.entrySet()) {
		registerHandlerMethod(handler, entry.getKey(), entry.getValue());
	}
}
 
Example #10
Source File: MvcUriComponentsBuilder.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private static Method getMethod(Class<?> controllerType, final String methodName, final Object... args) {
	MethodFilter selector = method -> {
		String name = method.getName();
		int argLength = method.getParameterCount();
		return (name.equals(methodName) && argLength == args.length);
	};
	Set<Method> methods = MethodIntrospector.selectMethods(controllerType, selector);
	if (methods.size() == 1) {
		return methods.iterator().next();
	}
	else if (methods.size() > 1) {
		throw new IllegalArgumentException(String.format(
				"Found two methods named '%s' accepting arguments %s in controller %s: [%s]",
				methodName, Arrays.asList(args), controllerType.getName(), methods));
	}
	else {
		throw new IllegalArgumentException("No method named '" + methodName + "' with " + args.length +
				" arguments found in controller " + controllerType.getName());
	}
}
 
Example #11
Source File: MvcUriComponentsBuilder.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private static Method getMethod(Class<?> controllerType, final String methodName, final Object... args) {
	MethodFilter selector = new MethodFilter() {
		@Override
		public boolean matches(Method method) {
			String name = method.getName();
			int argLength = method.getParameterTypes().length;
			return (name.equals(methodName) && argLength == args.length);
		}
	};
	Set<Method> methods = MethodIntrospector.selectMethods(controllerType, selector);
	if (methods.size() == 1) {
		return methods.iterator().next();
	}
	else if (methods.size() > 1) {
		throw new IllegalArgumentException(String.format(
				"Found two methods named '%s' accepting arguments %s in controller %s: [%s]",
				methodName, Arrays.asList(args), controllerType.getName(), methods));
	}
	else {
		throw new IllegalArgumentException("No method named '" + methodName + "' with " + args.length +
				" arguments found in controller " + controllerType.getName());
	}
}
 
Example #12
Source File: AbstractHandlerMethodMapping.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Look for handler methods in a handler.
 * @param handler the bean name of a handler or a handler instance
 */
protected void detectHandlerMethods(final Object handler) {
	Class<?> handlerType = (handler instanceof String ?
			obtainApplicationContext().getType((String) handler) : handler.getClass());

	if (handlerType != null) {
		final Class<?> userType = ClassUtils.getUserClass(handlerType);
		Map<Method, T> methods = MethodIntrospector.selectMethods(userType,
				(MethodIntrospector.MetadataLookup<T>) method -> getMappingForMethod(method, userType));
		if (logger.isTraceEnabled()) {
			logger.trace(formatMappings(userType, methods));
		}
		methods.forEach((method, mapping) -> {
			Method invocableMethod = AopUtils.selectInvocableMethod(method, userType);
			registerHandlerMethod(handler, invocableMethod, mapping);
		});
	}
}
 
Example #13
Source File: AbstractHandlerMethodMapping.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Look for handler methods in a handler.
 * @param handler the bean name of a handler or a handler instance
 */
protected void detectHandlerMethods(final Object handler) {
	Class<?> handlerType = (handler instanceof String ?
			getApplicationContext().getType((String) handler) : handler.getClass());
	final Class<?> userType = ClassUtils.getUserClass(handlerType);

	Map<Method, T> methods = MethodIntrospector.selectMethods(userType,
			new MethodIntrospector.MetadataLookup<T>() {
				@Override
				public T inspect(Method method) {
					return getMappingForMethod(method, userType);
				}
			});

	if (logger.isDebugEnabled()) {
		logger.debug(methods.size() + " request handler methods found on " + userType + ": " + methods);
	}
	for (Map.Entry<Method, T> entry : methods.entrySet()) {
		registerHandlerMethod(handler, entry.getKey(), entry.getValue());
	}
}
 
Example #14
Source File: ModelFactoryOrderingTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void runTest(Object controller) throws Exception {
	HandlerMethodArgumentResolverComposite resolvers = new HandlerMethodArgumentResolverComposite();
	resolvers.addResolver(new ModelAttributeMethodProcessor(false));
	resolvers.addResolver(new ModelMethodProcessor());
	WebDataBinderFactory dataBinderFactory = new DefaultDataBinderFactory(null);

	Class<?> type = controller.getClass();
	Set<Method> methods = MethodIntrospector.selectMethods(type, METHOD_FILTER);
	List<InvocableHandlerMethod> modelMethods = new ArrayList<>();
	for (Method method : methods) {
		InvocableHandlerMethod modelMethod = new InvocableHandlerMethod(controller, method);
		modelMethod.setHandlerMethodArgumentResolvers(resolvers);
		modelMethod.setDataBinderFactory(dataBinderFactory);
		modelMethods.add(modelMethod);
	}
	Collections.shuffle(modelMethods);

	SessionAttributesHandler sessionHandler = new SessionAttributesHandler(type, this.sessionAttributeStore);
	ModelFactory factory = new ModelFactory(modelMethods, dataBinderFactory, sessionHandler);
	factory.initModel(this.webRequest, this.mavContainer, new HandlerMethod(controller, "handle"));
	if (logger.isDebugEnabled()) {
		StringBuilder sb = new StringBuilder();
		for (String name : getInvokedMethods()) {
			sb.append(" >> ").append(name);
		}
		logger.debug(sb);
	}
}
 
Example #15
Source File: JmsListenerAnnotationBeanPostProcessor.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
	if (bean instanceof AopInfrastructureBean || bean instanceof JmsListenerContainerFactory ||
			bean instanceof JmsListenerEndpointRegistry) {
		// Ignore AOP infrastructure such as scoped proxies.
		return bean;
	}

	Class<?> targetClass = AopProxyUtils.ultimateTargetClass(bean);
	if (!this.nonAnnotatedClasses.contains(targetClass)) {
		Map<Method, Set<JmsListener>> annotatedMethods = MethodIntrospector.selectMethods(targetClass,
				(MethodIntrospector.MetadataLookup<Set<JmsListener>>) method -> {
					Set<JmsListener> listenerMethods = AnnotatedElementUtils.getMergedRepeatableAnnotations(
							method, JmsListener.class, JmsListeners.class);
					return (!listenerMethods.isEmpty() ? listenerMethods : null);
				});
		if (annotatedMethods.isEmpty()) {
			this.nonAnnotatedClasses.add(targetClass);
			if (logger.isTraceEnabled()) {
				logger.trace("No @JmsListener annotations found on bean type: " + targetClass);
			}
		}
		else {
			// Non-empty set of methods
			annotatedMethods.forEach((method, listeners) ->
					listeners.forEach(listener -> processJmsListener(listener, method, bean)));
			if (logger.isDebugEnabled()) {
				logger.debug(annotatedMethods.size() + " @JmsListener methods processed on bean '" + beanName +
						"': " + annotatedMethods);
			}
		}
	}
	return bean;
}
 
Example #16
Source File: SpringUtils.java    From onetwo with Apache License 2.0 5 votes vote down vote up
public static Set<Method> selectMethodsByParameterTypes(Class<?> targetClass, String targetMethod, Method sourceMethod) {
	Set<Method> methods = MethodIntrospector.selectMethods(targetClass, (MethodFilter)method -> {
		return method.getName().equals(targetMethod) && 
				method.getParameterCount()==sourceMethod.getParameterCount() &&
				Objects.deepEquals(method.getParameterTypes(), sourceMethod.getParameterTypes());
	});
	return methods;
}
 
Example #17
Source File: SimpleListenerFactory.java    From rocketmq-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
void resolveListenerMethod() {
    context.getBeansWithAnnotation(RocketMQListener.class).forEach((beanName, obj) -> {
        Map<Method, RocketMQMessage> annotatedMethods = MethodIntrospector.selectMethods(obj.getClass(),
                (MethodIntrospector.MetadataLookup<RocketMQMessage>) method -> AnnotatedElementUtils
                        .findMergedAnnotation(method, RocketMQMessage.class));
        initSubscriptionGroup(annotatedMethods, obj);
    });
    this.initSubscription = true;
}
 
Example #18
Source File: JmsListenerAnnotationBeanPostProcessor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Process the given {@link JmsListener} annotation on the given method,
 * registering a corresponding endpoint for the given bean instance.
 * @param jmsListener the annotation to process
 * @param mostSpecificMethod the annotated method
 * @param bean the instance to invoke the method on
 * @see #createMethodJmsListenerEndpoint()
 * @see JmsListenerEndpointRegistrar#registerEndpoint
 */
protected void processJmsListener(JmsListener jmsListener, Method mostSpecificMethod, Object bean) {
	Method invocableMethod = MethodIntrospector.selectInvocableMethod(mostSpecificMethod, bean.getClass());

	MethodJmsListenerEndpoint endpoint = createMethodJmsListenerEndpoint();
	endpoint.setBean(bean);
	endpoint.setMethod(invocableMethod);
	endpoint.setMostSpecificMethod(mostSpecificMethod);
	endpoint.setMessageHandlerMethodFactory(this.messageHandlerMethodFactory);
	endpoint.setBeanFactory(this.beanFactory);
	endpoint.setId(getEndpointId(jmsListener));
	endpoint.setDestination(resolve(jmsListener.destination()));
	if (StringUtils.hasText(jmsListener.selector())) {
		endpoint.setSelector(resolve(jmsListener.selector()));
	}
	if (StringUtils.hasText(jmsListener.subscription())) {
		endpoint.setSubscription(resolve(jmsListener.subscription()));
	}
	if (StringUtils.hasText(jmsListener.concurrency())) {
		endpoint.setConcurrency(resolve(jmsListener.concurrency()));
	}

	JmsListenerContainerFactory<?> factory = null;
	String containerFactoryBeanName = resolve(jmsListener.containerFactory());
	if (StringUtils.hasText(containerFactoryBeanName)) {
		Assert.state(this.beanFactory != null, "BeanFactory must be set to obtain container factory by bean name");
		try {
			factory = this.beanFactory.getBean(containerFactoryBeanName, JmsListenerContainerFactory.class);
		}
		catch (NoSuchBeanDefinitionException ex) {
			throw new BeanInitializationException("Could not register JMS listener endpoint on [" +
					mostSpecificMethod + "], no " + JmsListenerContainerFactory.class.getSimpleName() +
					" with id '" + containerFactoryBeanName + "' was found in the application context", ex);
		}
	}

	this.registrar.registerEndpoint(endpoint, factory);
}
 
Example #19
Source File: ModelFactoryOrderingTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void runTest(Object controller) throws Exception {
	HandlerMethodArgumentResolverComposite resolvers = new HandlerMethodArgumentResolverComposite();
	resolvers.addResolver(new ModelAttributeMethodProcessor(false));
	resolvers.addResolver(new ModelMethodProcessor());
	WebDataBinderFactory dataBinderFactory = new DefaultDataBinderFactory(null);

	Class<?> type = controller.getClass();
	Set<Method> methods = MethodIntrospector.selectMethods(type, METHOD_FILTER);
	List<InvocableHandlerMethod> modelMethods = new ArrayList<InvocableHandlerMethod>();
	for (Method method : methods) {
		InvocableHandlerMethod modelMethod = new InvocableHandlerMethod(controller, method);
		modelMethod.setHandlerMethodArgumentResolvers(resolvers);
		modelMethod.setDataBinderFactory(dataBinderFactory);
		modelMethods.add(modelMethod);
	}
	Collections.shuffle(modelMethods);

	SessionAttributesHandler sessionHandler = new SessionAttributesHandler(type, this.sessionAttributeStore);
	ModelFactory factory = new ModelFactory(modelMethods, dataBinderFactory, sessionHandler);
	factory.initModel(this.webRequest, this.mavContainer, new HandlerMethod(controller, "handle"));
	if (logger.isDebugEnabled()) {
		StringBuilder sb = new StringBuilder();
		for (String name : getInvokedMethods()) {
			sb.append(" >> ").append(name);
		}
		logger.debug(sb);
	}
}
 
Example #20
Source File: ExceptionHandlerMethodResolver.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * A constructor that finds {@link ExceptionHandler} methods in the given type.
 * @param handlerType the type to introspect
 */
public ExceptionHandlerMethodResolver(Class<?> handlerType) {
	for (Method method : MethodIntrospector.selectMethods(handlerType, EXCEPTION_HANDLER_METHODS)) {
		for (Class<? extends Throwable> exceptionType : detectExceptionMappings(method)) {
			addExceptionMapping(exceptionType, method);
		}
	}
}
 
Example #21
Source File: GRpcServiceProcessor.java    From faster-framework-project with Apache License 2.0 5 votes vote down vote up
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    GRpcApi grpcApi = bean.getClass().getAnnotation(GRpcApi.class);
    if (grpcApi == null) {
        return bean;
    }
    String scheme = grpcApi.value();
    //检验scheme是否存在
    if (bindServiceAdapterList.stream().anyMatch(item -> item.getScheme().equals(scheme))) {
        throw new GRpcServerCreateException("The scheme " + "[" + scheme + "] is already exist.Please check your configuration.");
    }
    Class<?> targetClass = AopUtils.getTargetClass(bean);
    Map<Method, GRpcMethod> annotatedMethods = MethodIntrospector.selectMethods(targetClass,
            (MethodIntrospector.MetadataLookup<GRpcMethod>) method -> AnnotatedElementUtils.findMergedAnnotation(method, GRpcMethod.class));
    if (annotatedMethods.size() == 0) {
        return bean;
    }
    List<MethodCallProperty> methodCallPropertyList = new ArrayList<>();
    annotatedMethods.forEach((method, v) -> {
        MethodCallProperty methodCallProperty = new MethodCallProperty();
        methodCallProperty.setScheme(scheme);
        methodCallProperty.setMethod(method);
        methodCallProperty.setProxyTarget(bean);
        methodCallProperty.setMethodName(StringUtils.isEmpty(v.value()) ? method.getName() : v.value());
        methodCallProperty.setMethodType(v.type());
        methodCallPropertyList.add(methodCallProperty);
    });
    BindServiceAdapter bindServiceAdapter = new BindServiceAdapter(scheme, methodCallPropertyList, marshallerFactory);
    bindServiceAdapterList.add(bindServiceAdapter);
    return bean;
}
 
Example #22
Source File: RedisListenerProcessor.java    From faster-framework-project with Apache License 2.0 5 votes vote down vote up
@Override
public Object postProcessAfterInitialization(Object bean, final String beanName) {
    Class<?> targetClass = AopUtils.getTargetClass(bean);
    Map<Method, RedisListener> annotatedMethods = MethodIntrospector.selectMethods(targetClass,
            (MethodIntrospector.MetadataLookup<RedisListener>) method -> AnnotatedElementUtils.findMergedAnnotation(method, RedisListener.class));
    annotatedMethods.forEach((method, v) -> {
        MessageListenerAdapter messageListenerAdapter = new MessageListenerAdapter(bean, method.getName());
        messageListenerAdapter.afterPropertiesSet();
        String[] channels = v.value();
        for (String channel : channels) {
            redisMessageListenerContainer.addMessageListener(messageListenerAdapter, channel.contains("*") ? new PatternTopic(channel) : new ChannelTopic(channel));
        }
    });
    return bean;
}
 
Example #23
Source File: RedisGenericCacheProcessor.java    From faster-framework-project with Apache License 2.0 5 votes vote down vote up
@Override
public Object postProcessAfterInitialization(Object bean, final String beanName) {
    Class<?> targetClass = AopUtils.getTargetClass(bean);
    Map<Method, Cacheable> annotatedMethods = MethodIntrospector.selectMethods(targetClass,
            (MethodIntrospector.MetadataLookup<Cacheable>) method -> AnnotatedElementUtils.findMergedAnnotation(method, Cacheable.class));
    annotatedMethods.forEach((method, v) -> {
        for (String cacheName : v.cacheNames()) {
            genericCacheMap.put(cacheName, method.getGenericReturnType());
        }
    });
    return bean;
}
 
Example #24
Source File: AbstractHandlerMethodMapping.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Look for handler methods in a handler.
 * @param handler the bean name of a handler or a handler instance
 */
protected void detectHandlerMethods(final Object handler) {
	Class<?> handlerType = (handler instanceof String ?
			getApplicationContext().getType((String) handler) : handler.getClass());
	final Class<?> userType = ClassUtils.getUserClass(handlerType);

	Map<Method, T> methods = MethodIntrospector.selectMethods(userType,
			new MethodIntrospector.MetadataLookup<T>() {
				@Override
				public T inspect(Method method) {
					try {
						return getMappingForMethod(method, userType);
					}
					catch (Throwable ex) {
						throw new IllegalStateException("Invalid mapping on handler class [" +
								userType.getName() + "]: " + method, ex);
					}
				}
			});

	if (logger.isDebugEnabled()) {
		logger.debug(methods.size() + " request handler methods found on " + userType + ": " + methods);
	}
	for (Map.Entry<Method, T> entry : methods.entrySet()) {
		Method invocableMethod = AopUtils.selectInvocableMethod(entry.getKey(), userType);
		T mapping = entry.getValue();
		registerHandlerMethod(handler, invocableMethod, mapping);
	}
}
 
Example #25
Source File: ExceptionHandlerMethodResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A constructor that finds {@link ExceptionHandler} methods in the given type.
 * @param handlerType the type to introspect
 */
public ExceptionHandlerMethodResolver(Class<?> handlerType) {
	for (Method method : MethodIntrospector.selectMethods(handlerType, EXCEPTION_HANDLER_METHODS)) {
		for (Class<? extends Throwable> exceptionType : detectExceptionMappings(method)) {
			addExceptionMapping(exceptionType, method);
		}
	}
}
 
Example #26
Source File: MessageInterceptorBeanPostProcessor.java    From synapse with Apache License 2.0 5 votes vote down vote up
private Map<Method, Set<MessageInterceptor>> findMethodsAnnotatedWithMessageInterceptor(Class<?> targetClass) {
    return selectMethods(targetClass,
            (MethodIntrospector.MetadataLookup<Set<MessageInterceptor>>) method -> {
                final Set<MessageInterceptor> consumerAnnotations = messageInterceptorAnnotationsOf(method);
                return (!consumerAnnotations.isEmpty() ? consumerAnnotations : null);
            });
}
 
Example #27
Source File: MessageLogConsumerBeanPostProcessor.java    From synapse with Apache License 2.0 5 votes vote down vote up
private Map<Method, Set<MessageLogConsumer>> findMethodsAnnotatedWithMessageLogConsumer(Class<?> targetClass) {
    return selectMethods(targetClass,
            (MethodIntrospector.MetadataLookup<Set<MessageLogConsumer>>) method -> {
                final Set<MessageLogConsumer> consumerAnnotations = consumerAnnotationsOf(method);
                return (!consumerAnnotations.isEmpty() ? consumerAnnotations : null);
            });
}
 
Example #28
Source File: MessageQueueConsumerBeanPostProcessor.java    From synapse with Apache License 2.0 5 votes vote down vote up
private Map<Method, Set<MessageQueueConsumer>> findMethodsAnnotatedWithMessageQueueConsumer(Class<?> targetClass) {
    return selectMethods(targetClass,
            (MethodIntrospector.MetadataLookup<Set<MessageQueueConsumer>>) method -> {
                final Set<MessageQueueConsumer> consumerAnnotations = consumerAnnotationsOf(method);
                return (!consumerAnnotations.isEmpty() ? consumerAnnotations : null);
            });
}
 
Example #29
Source File: EventSourceConsumerBeanPostProcessor.java    From synapse with Apache License 2.0 5 votes vote down vote up
private Map<Method, Set<EventSourceConsumer>> findMethodsAnnotatedWithEventSourceConsumer(Class<?> targetClass) {
    return selectMethods(targetClass,
            (MethodIntrospector.MetadataLookup<Set<EventSourceConsumer>>) method -> {
                final Set<EventSourceConsumer> consumerAnnotations = consumerAnnotationsOf(method);
                return (!consumerAnnotations.isEmpty() ? consumerAnnotations : null);
            });
}
 
Example #30
Source File: MethodMessageHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private static Map<Class<? extends Throwable>, Method> initExceptionMappings(Class<?> handlerType) {
	Map<Class<? extends Throwable>, Method> result = new HashMap<Class<? extends Throwable>, Method>();
	for (Method method : MethodIntrospector.selectMethods(handlerType, EXCEPTION_HANDLER_METHOD_FILTER)) {
		for(Class<? extends Throwable> exception : getExceptionsFromMethodSignature(method)) {
			result.put(exception, method);
		}
	}
	return result;
}