Example usage for org.springframework.messaging.handler.invocation.reactive InvocableHandlerMethod getShortLogMessage

List of usage examples for org.springframework.messaging.handler.invocation.reactive InvocableHandlerMethod getShortLogMessage

Introduction

In this page you can find the example usage for org.springframework.messaging.handler.invocation.reactive InvocableHandlerMethod getShortLogMessage.

Prototype

public String getShortLogMessage() 

Source Link

Document

Return a short representation of this handler method for log message purposes.

Usage

From source file:org.springframework.messaging.handler.invocation.reactive.InvocableHelper.java

/**
 * 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}
 *///from w  ww  .ja  va 2 s .  co m
@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 (Map.Entry<MessagingAdviceBean, AbstractExceptionHandlerMethodResolver> entry : this.exceptionHandlerAdviceCache
                .entrySet()) {
            MessagingAdviceBean advice = entry.getKey();
            if (advice.isApplicableToBeanType(beanType)) {
                resolver = entry.getValue();
                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;
}

From source file:org.springframework.messaging.handler.invocation.reactive.InvocableHelper.java

public Mono<Void> handleMessage(HandlerMethod handlerMethod, Message<?> message) {
    InvocableHandlerMethod invocable = initMessageMappingMethod(handlerMethod);
    if (logger.isDebugEnabled()) {
        logger.debug("Invoking " + invocable.getShortLogMessage());
    }//w  w w.  j  a v a2  s . c o  m
    return invocable.invoke(message)
            .switchIfEmpty(Mono.defer(() -> handleReturnValue(null, invocable, message)))
            .flatMap(returnValue -> handleReturnValue(returnValue, invocable, message)).onErrorResume(ex -> {
                InvocableHandlerMethod exHandler = initExceptionHandlerMethod(handlerMethod, ex);
                if (exHandler == null) {
                    return Mono.error(ex);
                }
                if (logger.isDebugEnabled()) {
                    logger.debug("Invoking " + exHandler.getShortLogMessage());
                }
                return exHandler.invoke(message, ex)
                        .switchIfEmpty(Mono.defer(() -> handleReturnValue(null, exHandler, message)))
                        .flatMap(returnValue -> handleReturnValue(returnValue, exHandler, message));
            });
}