org.springframework.messaging.handler.invocation.AbstractExceptionHandlerMethodResolver Java Examples

The following examples show how to use org.springframework.messaging.handler.invocation.AbstractExceptionHandlerMethodResolver. 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: InvocableHelper.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Find an exception handling method for the given exception.
 * <p>The default implementation searches methods in the class hierarchy of
 * the HandlerMethod first and if not found, it continues searching for
 * additional handling methods registered via
 * {@link #registerExceptionHandlerAdvice}.
 * @param handlerMethod the method where the exception was raised
 * @param ex the exception raised or signaled
 * @return a method to handle the exception, or {@code null}
 */
@Nullable
public InvocableHandlerMethod initExceptionHandlerMethod(HandlerMethod handlerMethod, Throwable ex) {
	if (logger.isDebugEnabled()) {
		logger.debug("Searching for methods to handle " + ex.getClass().getSimpleName());
	}
	Class<?> beanType = handlerMethod.getBeanType();
	AbstractExceptionHandlerMethodResolver resolver = this.exceptionHandlerCache.get(beanType);
	if (resolver == null) {
		resolver = this.exceptionMethodResolverFactory.apply(beanType);
		this.exceptionHandlerCache.put(beanType, resolver);
	}
	InvocableHandlerMethod exceptionHandlerMethod = null;
	Method method = resolver.resolveMethod(ex);
	if (method != null) {
		exceptionHandlerMethod = new InvocableHandlerMethod(handlerMethod.getBean(), method);
	}
	else {
		for (MessagingAdviceBean advice : this.exceptionHandlerAdviceCache.keySet()) {
			if (advice.isApplicableToBeanType(beanType)) {
				resolver = this.exceptionHandlerAdviceCache.get(advice);
				method = resolver.resolveMethod(ex);
				if (method != null) {
					exceptionHandlerMethod = new InvocableHandlerMethod(advice.resolveBean(), method);
					break;
				}
			}
		}
	}
	if (exceptionHandlerMethod != null) {
		logger.debug("Found exception handler " + exceptionHandlerMethod.getShortLogMessage());
		exceptionHandlerMethod.setArgumentResolvers(this.argumentResolvers.getResolvers());
	}
	else {
		logger.error("No exception handling method", ex);
	}
	return exceptionHandlerMethod;
}
 
Example #2
Source File: RqueueMessageHandler.java    From rqueue with Apache License 2.0 4 votes vote down vote up
@Override
protected AbstractExceptionHandlerMethodResolver createExceptionHandlerMethodResolverFor(
    Class<?> beanType) {
  return new AnnotationExceptionHandlerMethodResolver(beanType);
}
 
Example #3
Source File: SimpAnnotationMethodMessageHandler.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
protected AbstractExceptionHandlerMethodResolver createExceptionHandlerMethodResolverFor(Class<?> beanType) {
	return new AnnotationExceptionHandlerMethodResolver(beanType);
}
 
Example #4
Source File: MessageMappingMessageHandler.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
protected AbstractExceptionHandlerMethodResolver createExceptionMethodResolverFor(Class<?> beanType) {
	return new AnnotationExceptionHandlerMethodResolver(beanType);
}
 
Example #5
Source File: InvocableHelper.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public InvocableHelper(
		Function<Class<?>, AbstractExceptionHandlerMethodResolver> exceptionMethodResolverFactory) {

	this.exceptionMethodResolverFactory = exceptionMethodResolverFactory;
}
 
Example #6
Source File: InvocableHelper.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Method to populate the MessagingAdviceBean cache (e.g. to support "global"
 * {@code @MessageExceptionHandler}).
 */
public void registerExceptionHandlerAdvice(
		MessagingAdviceBean bean, AbstractExceptionHandlerMethodResolver resolver) {

	this.exceptionHandlerAdviceCache.put(bean, resolver);
}
 
Example #7
Source File: AbstractMethodMessageHandler.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Subclasses can invoke this method to populate the MessagingAdviceBean cache
 * (e.g. to support "global" {@code @MessageExceptionHandler}).
 */
protected void registerExceptionHandlerAdvice(
		MessagingAdviceBean bean, AbstractExceptionHandlerMethodResolver resolver) {

	this.invocableHelper.registerExceptionHandlerAdvice(bean, resolver);
}
 
Example #8
Source File: MethodMessageHandlerTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
protected AbstractExceptionHandlerMethodResolver createExceptionMethodResolverFor(Class<?> beanType) {
	return new TestExceptionResolver(beanType);
}
 
Example #9
Source File: SimpAnnotationMethodMessageHandler.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
protected AbstractExceptionHandlerMethodResolver createExceptionHandlerMethodResolverFor(Class<?> beanType) {
	return new AnnotationExceptionHandlerMethodResolver(beanType);
}
 
Example #10
Source File: SimpAnnotationMethodMessageHandler.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
protected AbstractExceptionHandlerMethodResolver createExceptionHandlerMethodResolverFor(Class<?> beanType) {
	return new AnnotationExceptionHandlerMethodResolver(beanType);
}
 
Example #11
Source File: QueueMessageHandler.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
@Override
protected AbstractExceptionHandlerMethodResolver createExceptionHandlerMethodResolverFor(
		Class<?> beanType) {
	return new AnnotationExceptionHandlerMethodResolver(beanType);
}
 
Example #12
Source File: AbstractMethodMessageHandler.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Create a concrete instance of {@link AbstractExceptionHandlerMethodResolver}
 * that finds exception handling methods based on some criteria, e.g. based
 * on the presence of {@code @MessageExceptionHandler}.
 * @param beanType the class in which an exception occurred during handling
 * @return the resolver to use
 */
protected abstract AbstractExceptionHandlerMethodResolver createExceptionMethodResolverFor(Class<?> beanType);