org.springframework.messaging.handler.MessagingAdviceBean Java Examples
The following examples show how to use
org.springframework.messaging.handler.MessagingAdviceBean.
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: WebSocketAnnotationMethodMessageHandler.java From spring-analysis-note with MIT License | 6 votes |
private void initMessagingAdviceCache(@Nullable List<MessagingAdviceBean> beans) { if (beans == null) { return; } for (MessagingAdviceBean bean : beans) { Class<?> type = bean.getBeanType(); if (type != null) { AnnotationExceptionHandlerMethodResolver resolver = new AnnotationExceptionHandlerMethodResolver(type); if (resolver.hasExceptionMappings()) { registerExceptionHandlerAdvice(bean, resolver); if (logger.isTraceEnabled()) { logger.trace("Detected @MessageExceptionHandler methods in " + bean); } } } } }
Example #2
Source File: WebSocketAnnotationMethodMessageHandler.java From java-technology-stack with MIT License | 6 votes |
private void initMessagingAdviceCache(@Nullable List<MessagingAdviceBean> beans) { if (beans == null) { return; } for (MessagingAdviceBean bean : beans) { Class<?> type = bean.getBeanType(); if (type != null) { AnnotationExceptionHandlerMethodResolver resolver = new AnnotationExceptionHandlerMethodResolver(type); if (resolver.hasExceptionMappings()) { registerExceptionHandlerAdvice(bean, resolver); if (logger.isTraceEnabled()) { logger.trace("Detected @MessageExceptionHandler methods in " + bean); } } } } }
Example #3
Source File: AbstractMethodMessageHandler.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Find an {@code @MessageExceptionHandler} method for the given exception. * The default implementation searches methods in the class hierarchy of the * HandlerMethod first and if not found, it continues searching for additional * {@code @MessageExceptionHandler} methods among the configured * {@linkplain org.springframework.messaging.handler.MessagingAdviceBean * MessagingAdviceBean}, if any. * @param handlerMethod the method where the exception was raised * @param exception the raised exception * @return a method to handle the exception, or {@code null} * @since 4.2 */ protected InvocableHandlerMethod getExceptionHandlerMethod(HandlerMethod handlerMethod, Exception exception) { if (logger.isDebugEnabled()) { logger.debug("Searching methods to handle " + exception.getClass().getSimpleName()); } Class<?> beanType = handlerMethod.getBeanType(); AbstractExceptionHandlerMethodResolver resolver = this.exceptionHandlerCache.get(beanType); if (resolver == null) { resolver = createExceptionHandlerMethodResolverFor(beanType); this.exceptionHandlerCache.put(beanType, resolver); } Method method = resolver.resolveMethod(exception); if (method != null) { return new InvocableHandlerMethod(handlerMethod.getBean(), method); } for (MessagingAdviceBean advice : this.exceptionHandlerAdviceCache.keySet()) { if (advice.isApplicableToBeanType(beanType)) { resolver = this.exceptionHandlerAdviceCache.get(advice); method = resolver.resolveMethod(exception); if (method != null) { return new InvocableHandlerMethod(advice.resolveBean(), method); } } } return null; }
Example #4
Source File: InvocableHelper.java From spring-analysis-note with MIT License | 5 votes |
/** * 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 #5
Source File: AbstractMethodMessageHandler.java From spring-analysis-note with MIT License | 5 votes |
/** * Find an {@code @MessageExceptionHandler} method for the given exception. * The default implementation searches methods in the class hierarchy of the * HandlerMethod first and if not found, it continues searching for additional * {@code @MessageExceptionHandler} methods among the configured * {@linkplain org.springframework.messaging.handler.MessagingAdviceBean * MessagingAdviceBean}, if any. * @param handlerMethod the method where the exception was raised * @param exception the raised exception * @return a method to handle the exception, or {@code null} * @since 4.2 */ @Nullable protected InvocableHandlerMethod getExceptionHandlerMethod(HandlerMethod handlerMethod, Exception exception) { if (logger.isDebugEnabled()) { logger.debug("Searching methods to handle " + exception.getClass().getSimpleName()); } Class<?> beanType = handlerMethod.getBeanType(); AbstractExceptionHandlerMethodResolver resolver = this.exceptionHandlerCache.get(beanType); if (resolver == null) { resolver = createExceptionHandlerMethodResolverFor(beanType); this.exceptionHandlerCache.put(beanType, resolver); } Method method = resolver.resolveMethod(exception); if (method != null) { return new InvocableHandlerMethod(handlerMethod.getBean(), method); } for (MessagingAdviceBean advice : this.exceptionHandlerAdviceCache.keySet()) { if (advice.isApplicableToBeanType(beanType)) { resolver = this.exceptionHandlerAdviceCache.get(advice); method = resolver.resolveMethod(exception); if (method != null) { return new InvocableHandlerMethod(advice.resolveBean(), method); } } } return null; }
Example #6
Source File: WebSocketAnnotationMethodMessageHandler.java From spring-analysis-note with MIT License | 5 votes |
public static List<MessagingAdviceBean> createFromList(List<ControllerAdviceBean> beans) { List<MessagingAdviceBean> result = new ArrayList<>(beans.size()); for (ControllerAdviceBean bean : beans) { result.add(new MessagingControllerAdviceBean(bean)); } return result; }
Example #7
Source File: AbstractMethodMessageHandler.java From java-technology-stack with MIT License | 5 votes |
/** * Find an {@code @MessageExceptionHandler} method for the given exception. * The default implementation searches methods in the class hierarchy of the * HandlerMethod first and if not found, it continues searching for additional * {@code @MessageExceptionHandler} methods among the configured * {@linkplain org.springframework.messaging.handler.MessagingAdviceBean * MessagingAdviceBean}, if any. * @param handlerMethod the method where the exception was raised * @param exception the raised exception * @return a method to handle the exception, or {@code null} * @since 4.2 */ @Nullable protected InvocableHandlerMethod getExceptionHandlerMethod(HandlerMethod handlerMethod, Exception exception) { if (logger.isDebugEnabled()) { logger.debug("Searching methods to handle " + exception.getClass().getSimpleName()); } Class<?> beanType = handlerMethod.getBeanType(); AbstractExceptionHandlerMethodResolver resolver = this.exceptionHandlerCache.get(beanType); if (resolver == null) { resolver = createExceptionHandlerMethodResolverFor(beanType); this.exceptionHandlerCache.put(beanType, resolver); } Method method = resolver.resolveMethod(exception); if (method != null) { return new InvocableHandlerMethod(handlerMethod.getBean(), method); } for (MessagingAdviceBean advice : this.exceptionHandlerAdviceCache.keySet()) { if (advice.isApplicableToBeanType(beanType)) { resolver = this.exceptionHandlerAdviceCache.get(advice); method = resolver.resolveMethod(exception); if (method != null) { return new InvocableHandlerMethod(advice.resolveBean(), method); } } } return null; }
Example #8
Source File: WebSocketAnnotationMethodMessageHandler.java From java-technology-stack with MIT License | 5 votes |
public static List<MessagingAdviceBean> createFromList(List<ControllerAdviceBean> beans) { List<MessagingAdviceBean> result = new ArrayList<>(beans.size()); for (ControllerAdviceBean bean : beans) { result.add(new MessagingControllerAdviceBean(bean)); } return result; }
Example #9
Source File: WebSocketAnnotationMethodMessageHandler.java From spring4-understanding with Apache License 2.0 | 5 votes |
private void initMessagingAdviceCache(List<MessagingAdviceBean> beans) { if (beans == null) { return; } for (MessagingAdviceBean bean : beans) { Class<?> beanType = bean.getBeanType(); AnnotationExceptionHandlerMethodResolver resolver = new AnnotationExceptionHandlerMethodResolver(beanType); if (resolver.hasExceptionMappings()) { registerExceptionHandlerAdvice(bean, resolver); logger.info("Detected @MessageExceptionHandler methods in " + bean); } } }
Example #10
Source File: WebSocketAnnotationMethodMessageHandler.java From spring4-understanding with Apache License 2.0 | 5 votes |
public static List<MessagingAdviceBean> createFromList(List<ControllerAdviceBean> controllerAdvice) { List<MessagingAdviceBean> messagingAdvice = new ArrayList<MessagingAdviceBean>(controllerAdvice.size()); for (ControllerAdviceBean bean : controllerAdvice) { messagingAdvice.add(new MessagingControllerAdviceBean(bean)); } return messagingAdvice; }
Example #11
Source File: InvocableHelper.java From spring-analysis-note with MIT License | 4 votes |
/** * 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 #12
Source File: AbstractMethodMessageHandler.java From spring-analysis-note with MIT License | 4 votes |
/** * 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 #13
Source File: AbstractMethodMessageHandler.java From spring-analysis-note with MIT License | 4 votes |
/** * Subclasses can invoke this method to populate the MessagingAdviceBean cache * (e.g. to support "global" {@code @MessageExceptionHandler}). * @since 4.2 */ protected void registerExceptionHandlerAdvice( MessagingAdviceBean bean, AbstractExceptionHandlerMethodResolver resolver) { this.exceptionHandlerAdviceCache.put(bean, resolver); }
Example #14
Source File: AbstractMethodMessageHandler.java From java-technology-stack with MIT License | 4 votes |
/** * Subclasses can invoke this method to populate the MessagingAdviceBean cache * (e.g. to support "global" {@code @MessageExceptionHandler}). * @since 4.2 */ protected void registerExceptionHandlerAdvice( MessagingAdviceBean bean, AbstractExceptionHandlerMethodResolver resolver) { this.exceptionHandlerAdviceCache.put(bean, resolver); }
Example #15
Source File: AbstractMethodMessageHandler.java From spring4-understanding with Apache License 2.0 | 2 votes |
/** * Subclasses can invoke this method to populate the MessagingAdviceBean cache * (e.g. to support "global" {@code @MessageExceptionHandler}). * @since 4.2 */ protected void registerExceptionHandlerAdvice(MessagingAdviceBean bean, AbstractExceptionHandlerMethodResolver resolver) { this.exceptionHandlerAdviceCache.put(bean, resolver); }