Java Code Examples for org.springframework.web.method.HandlerMethod#getBeanType()

The following examples show how to use org.springframework.web.method.HandlerMethod#getBeanType() . 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: ApisController.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@PostConstruct
private void initApiMappings() {
    Map<RequestMappingInfo, HandlerMethod> requestMappedHandlers = this.handlerMapping.getHandlerMethods();
    for (Map.Entry<RequestMappingInfo, HandlerMethod> requestMappedHandlerEntry : requestMappedHandlers.entrySet()) {
        RequestMappingInfo requestMappingInfo = requestMappedHandlerEntry.getKey();
        HandlerMethod handlerMethod = requestMappedHandlerEntry.getValue();

        Class<?> handlerMethodBeanClazz = handlerMethod.getBeanType();
        if (handlerMethodBeanClazz == this.getClass()) {
            continue;
        }

        String controllerName = handlerMethodBeanClazz.getSimpleName();
        Set<String> mappedRequests = requestMappingInfo.getPatternsCondition().getPatterns();

        SortedSet<RequestMappedUri> alreadyMappedRequests = this.apiMappings.get(controllerName);
        if (alreadyMappedRequests == null) {
            alreadyMappedRequests = new TreeSet<RequestMappedUri>(RequestMappedUri.MAPPED_URI_ORDER);
            this.apiMappings.put(controllerName, alreadyMappedRequests);
        }
        alreadyMappedRequests.addAll(createRequestMappedApis(handlerMethod, mappedRequests));
    }
}
 
Example 2
Source File: MvcUriComponentsBuilder.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * An alternative to {@link #fromMappingName(String)} that accepts a
 * {@code UriComponentsBuilder} representing the base URL. This is useful
 * when using MvcUriComponentsBuilder outside the context of processing a
 * request or to apply a custom baseUrl not matching the current request.
 * @param builder the builder for the base URL; the builder will be cloned
 * and therefore not modified and may be re-used for further calls.
 * @param name the mapping name
 * @return a builder to to prepare the URI String
 * @throws IllegalArgumentException if the mapping name is not found or
 * if there is no unique match
 * @since 4.2
 */
public static MethodArgumentBuilder fromMappingName(UriComponentsBuilder builder, String name) {
	RequestMappingInfoHandlerMapping handlerMapping = getRequestMappingInfoHandlerMapping();
	List<HandlerMethod> handlerMethods = handlerMapping.getHandlerMethodsForMappingName(name);
	if (handlerMethods == null) {
		throw new IllegalArgumentException("Mapping mappingName not found: " + name);
	}
	if (handlerMethods.size() != 1) {
		throw new IllegalArgumentException("No unique match for mapping mappingName " +
				name + ": " + handlerMethods);
	}
	HandlerMethod handlerMethod = handlerMethods.get(0);
	Class<?> controllerType = handlerMethod.getBeanType();
	Method method = handlerMethod.getMethod();
	return new MethodArgumentBuilder(builder, controllerType, method);
}
 
Example 3
Source File: MvcUriComponentsBuilder.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * An alternative to {@link #fromMappingName(String)} that accepts a
 * {@code UriComponentsBuilder} representing the base URL. This is useful
 * when using MvcUriComponentsBuilder outside the context of processing a
 * request or to apply a custom baseUrl not matching the current request.
 * <p><strong>Note:</strong> This method extracts values from "Forwarded"
 * and "X-Forwarded-*" headers if found. See class-level docs.
 * @param builder the builder for the base URL; the builder will be cloned
 * and therefore not modified and may be re-used for further calls.
 * @param name the mapping name
 * @return a builder to prepare the URI String
 * @throws IllegalArgumentException if the mapping name is not found or
 * if there is no unique match
 * @since 4.2
 */
public static MethodArgumentBuilder fromMappingName(@Nullable UriComponentsBuilder builder, String name) {
	WebApplicationContext wac = getWebApplicationContext();
	Assert.notNull(wac, "No WebApplicationContext. ");
	Map<String, RequestMappingInfoHandlerMapping> map = wac.getBeansOfType(RequestMappingInfoHandlerMapping.class);
	List<HandlerMethod> handlerMethods = null;
	for (RequestMappingInfoHandlerMapping mapping : map.values()) {
		handlerMethods = mapping.getHandlerMethodsForMappingName(name);
		if (handlerMethods != null) {
			break;
		}
	}
	if (handlerMethods == null) {
		throw new IllegalArgumentException("Mapping not found: " + name);
	}
	else if (handlerMethods.size() != 1) {
		throw new IllegalArgumentException("No unique match for mapping " + name + ": " + handlerMethods);
	}
	else {
		HandlerMethod handlerMethod = handlerMethods.get(0);
		Class<?> controllerType = handlerMethod.getBeanType();
		Method method = handlerMethod.getMethod();
		return new MethodArgumentBuilder(builder, controllerType, method);
	}
}
 
Example 4
Source File: RequestMappingHandlerMapping.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) {
	HandlerMethod handlerMethod = createHandlerMethod(handler, method);
	Class<?> beanType = handlerMethod.getBeanType();
	CrossOrigin typeAnnotation = AnnotatedElementUtils.findMergedAnnotation(beanType, CrossOrigin.class);
	CrossOrigin methodAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, CrossOrigin.class);

	if (typeAnnotation == null && methodAnnotation == null) {
		return null;
	}

	CorsConfiguration config = new CorsConfiguration();
	updateCorsConfig(config, typeAnnotation);
	updateCorsConfig(config, methodAnnotation);

	if (CollectionUtils.isEmpty(config.getAllowedMethods())) {
		for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) {
			config.addAllowedMethod(allowedMethod.name());
		}
	}
	return config.applyPermitDefaultValues();
}
 
Example 5
Source File: RequestMappingHandlerMapping.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) {
	HandlerMethod handlerMethod = createHandlerMethod(handler, method);
	Class<?> beanType = handlerMethod.getBeanType();
	CrossOrigin typeAnnotation = AnnotatedElementUtils.findMergedAnnotation(beanType, CrossOrigin.class);
	CrossOrigin methodAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, CrossOrigin.class);

	if (typeAnnotation == null && methodAnnotation == null) {
		return null;
	}

	CorsConfiguration config = new CorsConfiguration();
	updateCorsConfig(config, typeAnnotation);
	updateCorsConfig(config, methodAnnotation);

	if (CollectionUtils.isEmpty(config.getAllowedMethods())) {
		for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) {
			config.addAllowedMethod(allowedMethod.name());
		}
	}
	return config.applyPermitDefaultValues();
}
 
Example 6
Source File: AuthorizationInterceptor.java    From shepher with Apache License 2.0 5 votes vote down vote up
private Auth getAnnotation(HandlerMethod handlerMethod) {
    Auth annotation = handlerMethod.getMethodAnnotation(Auth.class);

    Class<?> beanType = handlerMethod.getBeanType();
    if (beanType.isAnnotationPresent(Auth.class)) {
        annotation = beanType.getAnnotation(Auth.class);
    }
    return annotation;
}
 
Example 7
Source File: LoginAuthInterceptor.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){
    if (handler instanceof HandlerMethod) {
        final HandlerMethod handlerMethod = (HandlerMethod) handler;
        final Class<?> clazz = handlerMethod.getBeanType();
        final Method method = handlerMethod.getMethod();

        if (clazz.isAnnotationPresent(LoginAuth.class) || method.isAnnotationPresent(LoginAuth.class)) {
            SysUser loginUser = ShiroUtils.getSysUser();
            return ObjectUtil.isNotNull(loginUser);
        }
    }
    return true;
}
 
Example 8
Source File: ResponseResultInterceptor.java    From spring-boot-api-project-seed with Apache License 2.0 5 votes vote down vote up
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    if (handler instanceof HandlerMethod) {
        final HandlerMethod handlerMethod = (HandlerMethod) handler;
        final Class<?> clazz = handlerMethod.getBeanType();
        final Method method = handlerMethod.getMethod();
        if (clazz.isAnnotationPresent(ResponseResult.class)) {
            request.setAttribute(RESPONSE_RESULT, clazz.getAnnotation(ResponseResult.class));
        } else if (method.isAnnotationPresent(ResponseResult.class)) {
            request.setAttribute(RESPONSE_RESULT, method.getAnnotation(ResponseResult.class));
        }
    }

    return true;
}
 
Example 9
Source File: GlobalDefaultExceptionHandler.java    From unified-dispose-springboot with Apache License 2.0 5 votes vote down vote up
/**
 * 校验是否进行异常处理
 *
 * @param e   异常
 * @param <T> extends Throwable
 * @throws Throwable 异常
 */
private <T extends Throwable> void errorDispose(T e) throws Throwable {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    HandlerMethod handlerMethod = (HandlerMethod) request.getAttribute("org.springframework.web.servlet.HandlerMapping.bestMatchingHandler");

    // 获取异常 Controller
    Class<?> beanType = handlerMethod.getBeanType();
    // 获取异常方法
    Method method = handlerMethod.getMethod();

    // 判断方法是否存在 IgnoreResponseAdvice 注解
    IgnoreResponseAdvice methodAnnotation = method.getAnnotation(IgnoreResponseAdvice.class);
    if (methodAnnotation != null) {
        // 是否使用异常处理
        if (!methodAnnotation.errorDispose()) {
            throw e;
        } else {
            return;
        }
    }
    // 判类是否存在 IgnoreResponseAdvice 注解
    IgnoreResponseAdvice classAnnotation = beanType.getAnnotation(IgnoreResponseAdvice.class);
    if (classAnnotation != null) {
        if (!classAnnotation.errorDispose()) {
            throw e;
        }
    }
}
 
Example 10
Source File: JsonHandlerExceptionResolver.java    From everyone-java-blog with Apache License 2.0 5 votes vote down vote up
private void logException(Object handler, Exception exception, Map<String, String[]> parameterMap) {
    if (handler != null && HandlerMethod.class.isAssignableFrom(handler.getClass())) {
        try {
            HandlerMethod handlerMethod = (HandlerMethod) handler;
            Class<?> beanType = handlerMethod.getBeanType();
            String methodName = handlerMethod.getMethod().getName();
            RequestMapping controllerRequestMapping = beanType.getDeclaredAnnotation(RequestMapping.class);
            String classMapping = "";
            if (controllerRequestMapping != null) {
                classMapping = controllerRequestMapping.value()[0];
            }
            RequestMapping methodRequestMapping = handlerMethod.getMethodAnnotation(RequestMapping.class);
            String methodMapping = "";
            if (methodRequestMapping != null) {
                methodMapping = methodRequestMapping.value()[0];
            }
            if (!methodMapping.startsWith("/")) {
                methodMapping = "/" + methodMapping;
            }
            Logger logger = LoggerFactory.getLogger(beanType);
            logger.error("RequestMapping is:");
            logger.error(classMapping + methodMapping);
            logger.error("HandlerMethod is:");
            logger.error(beanType.getSimpleName() + "." + methodName + "()");
            logger.error("ParameterMap is:");
            logger.error(JsonUtils.toJson(parameterMap), exception);
        } catch (Exception e) {
            LOGGER.error(handler + " execute failed.", exception);
        }
    } else {
        LOGGER.error(handler + " execute failed.", exception);
    }
}
 
Example 11
Source File: ControllerMethodResolver.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Return the handler for the type-level {@code @SessionAttributes} annotation
 * based on the given controller method.
 */
public SessionAttributesHandler getSessionAttributesHandler(HandlerMethod handlerMethod) {
	Class<?> handlerType = handlerMethod.getBeanType();
	SessionAttributesHandler result = this.sessionAttributesHandlerCache.get(handlerType);
	if (result == null) {
		synchronized (this.sessionAttributesHandlerCache) {
			result = this.sessionAttributesHandlerCache.get(handlerType);
			if (result == null) {
				result = new SessionAttributesHandler(handlerType);
				this.sessionAttributesHandlerCache.put(handlerType, result);
			}
		}
	}
	return result;
}
 
Example 12
Source File: ControllerMethodResolver.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Find an {@code @ExceptionHandler} method in {@code @ControllerAdvice}
 * components or in the controller of the given {@code @RequestMapping} method.
 */
@Nullable
public InvocableHandlerMethod getExceptionHandlerMethod(Throwable ex, HandlerMethod handlerMethod) {

	Class<?> handlerType = handlerMethod.getBeanType();

	// Controller-local first...
	Object targetBean = handlerMethod.getBean();
	Method targetMethod = this.exceptionHandlerCache
			.computeIfAbsent(handlerType, ExceptionHandlerMethodResolver::new)
			.resolveMethodByThrowable(ex);

	if (targetMethod == null) {
		// Global exception handlers...
		for (ControllerAdviceBean advice : this.exceptionHandlerAdviceCache.keySet()) {
			if (advice.isApplicableToBeanType(handlerType)) {
				targetBean = advice.resolveBean();
				targetMethod = this.exceptionHandlerAdviceCache.get(advice).resolveMethodByThrowable(ex);
				if (targetMethod != null) {
					break;
				}
			}
		}
	}

	if (targetMethod == null) {
		return null;
	}

	InvocableHandlerMethod invocable = new InvocableHandlerMethod(targetBean, targetMethod);
	invocable.setArgumentResolvers(this.exceptionHandlerResolvers);
	return invocable;
}
 
Example 13
Source File: ClassUtil.java    From mica with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 获取Annotation
 *
 * @param handlerMethod  HandlerMethod
 * @param annotationType 注解类
 * @param <A>            泛型标记
 * @return {Annotation}
 */
@Nullable
public static <A extends Annotation> A getAnnotation(HandlerMethod handlerMethod, Class<A> annotationType) {
	// 先找方法,再找方法上的类
	A annotation = handlerMethod.getMethodAnnotation(annotationType);
	if (null != annotation) {
		return annotation;
	}
	// 获取类上面的Annotation,可能包含组合注解,故采用spring的工具类
	Class<?> beanType = handlerMethod.getBeanType();
	return AnnotatedElementUtils.findMergedAnnotation(beanType, annotationType);
}
 
Example 14
Source File: ClassUtil.java    From albedo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 获取Annotation
 *
 * @param handlerMethod  HandlerMethod
 * @param annotationType 注解类
 * @param <A>            泛型标记
 * @return {Annotation}
 */
public <A extends Annotation> A getAnnotation(HandlerMethod handlerMethod, Class<A> annotationType) {
	// 先找方法,再找方法上的类
	A annotation = handlerMethod.getMethodAnnotation(annotationType);
	if (null != annotation) {
		return annotation;
	}
	// 获取类上面的Annotation,可能包含组合注解,故采用spring的工具类
	Class<?> beanType = handlerMethod.getBeanType();
	return AnnotatedElementUtils.findMergedAnnotation(beanType, annotationType);
}
 
Example 15
Source File: ControllerMethodResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Find an {@code @ExceptionHandler} method in {@code @ControllerAdvice}
 * components or in the controller of the given {@code @RequestMapping} method.
 */
@Nullable
public InvocableHandlerMethod getExceptionHandlerMethod(Throwable ex, HandlerMethod handlerMethod) {
	Class<?> handlerType = handlerMethod.getBeanType();

	// Controller-local first...
	Object targetBean = handlerMethod.getBean();
	Method targetMethod = this.exceptionHandlerCache
			.computeIfAbsent(handlerType, ExceptionHandlerMethodResolver::new)
			.resolveMethodByThrowable(ex);

	if (targetMethod == null) {
		// Global exception handlers...
		for (ControllerAdviceBean advice : this.exceptionHandlerAdviceCache.keySet()) {
			if (advice.isApplicableToBeanType(handlerType)) {
				targetBean = advice.resolveBean();
				targetMethod = this.exceptionHandlerAdviceCache.get(advice).resolveMethodByThrowable(ex);
				if (targetMethod != null) {
					break;
				}
			}
		}
	}

	if (targetMethod == null) {
		return null;
	}

	InvocableHandlerMethod invocable = new InvocableHandlerMethod(targetBean, targetMethod);
	invocable.setArgumentResolvers(this.exceptionHandlerResolvers);
	return invocable;
}
 
Example 16
Source File: TransactionHandlerInterceptor.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
		throws Exception {
	if (HandlerMethod.class.isInstance(handler) == false) {
		return;
	}

	HandlerMethod hm = (HandlerMethod) handler;
	Class<?> clazz = hm.getBeanType();
	if (TransactionCoordinatorController.class.equals(clazz)) {
		return;
	} else if (ErrorController.class.isInstance(hm.getBean())) {
		return;
	}

	String transactionText = request.getHeader(HEADER_TRANCACTION_KEY);
	if (StringUtils.isBlank(transactionText)) {
		return;
	}

	SpringCloudBeanRegistry beanRegistry = SpringCloudBeanRegistry.getInstance();
	TransactionBeanFactory beanFactory = beanRegistry.getBeanFactory();
	TransactionManager transactionManager = beanFactory.getTransactionManager();
	TransactionInterceptor transactionInterceptor = beanFactory.getTransactionInterceptor();

	Transaction transaction = transactionManager.getTransactionQuietly();
	TransactionContext transactionContext = transaction.getTransactionContext();

	// byte[] byteArray = SerializeUtils.serializeObject(transactionContext);
	// String transactionStr = ByteUtils.byteArrayToString(byteArray);
	// response.setHeader(HEADER_TRANCACTION_KEY, transactionStr);
	// response.setHeader(HEADER_PROPAGATION_KEY, this.identifier);

	TransactionResponseImpl resp = new TransactionResponseImpl();
	resp.setTransactionContext(transactionContext);
	resp.setSourceTransactionCoordinator(beanRegistry.getConsumeCoordinator(null));

	transactionInterceptor.beforeSendResponse(resp);

}
 
Example 17
Source File: CommonHandlerExceptionResolver.java    From everyone-java-blog with Apache License 2.0 5 votes vote down vote up
private void logException(Object handler, Exception exception, Map<String, String[]> parameterMap) {
    if (handler != null && HandlerMethod.class.isAssignableFrom(handler.getClass())) {
        try {
            HandlerMethod handlerMethod = (HandlerMethod) handler;
            Class<?> beanType = handlerMethod.getBeanType();
            String methodName = handlerMethod.getMethod().getName();
            RequestMapping controllerRequestMapping = beanType.getDeclaredAnnotation(RequestMapping.class);
            String classMapping = "";
            if (controllerRequestMapping != null) {
                classMapping = controllerRequestMapping.value()[0];
            }
            RequestMapping methodRequestMapping = handlerMethod.getMethodAnnotation(RequestMapping.class);
            String methodMapping = "";
            if (methodRequestMapping != null) {
                methodMapping = methodRequestMapping.value()[0];
            }
            if (!methodMapping.startsWith("/")) {
                methodMapping = "/" + methodMapping;
            }
            Logger logger = LoggerFactory.getLogger(beanType);
            logger.error("RequestMapping is:");
            logger.error(classMapping + methodMapping);
            logger.error("HandlerMethod is:");
            logger.error(beanType.getSimpleName() + "." + methodName + "()");
            logger.error("ParameterMap is:");
            logger.error(JsonUtils.toJson(parameterMap), exception);
        } catch (Exception e) {
            LOGGER.error(handler + " execute failed.", exception);
        }
    } else {
        LOGGER.error(handler + " execute failed.", exception);
    }
}
 
Example 18
Source File: ClassUtils.java    From smaker with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 获取Annotation
 *
 * @param handlerMethod  HandlerMethod
 * @param annotationType 注解类
 * @param <A>            泛型标记
 * @return {Annotation}
 */
public static <A extends Annotation> A getAnnotation(HandlerMethod handlerMethod, Class<A> annotationType) {
	// 先找方法,再找方法上的类
	A annotation = handlerMethod.getMethodAnnotation(annotationType);
	if (null != annotation) {
		return annotation;
	}
	// 获取类上面的Annotation,可能包含组合注解,故采用spring的工具类
	Class<?> beanType = handlerMethod.getBeanType();
	return AnnotatedElementUtils.findMergedAnnotation(beanType, annotationType);
}
 
Example 19
Source File: CompensableHandlerInterceptor.java    From ByteTCC with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
		throws Exception {
	String transactionStr = request.getHeader(HEADER_TRANCACTION_KEY);
	if (StringUtils.isBlank(transactionStr)) {
		return;
	}

	if (HandlerMethod.class.isInstance(handler) == false) {
		return;
	}

	HandlerMethod hm = (HandlerMethod) handler;
	Class<?> clazz = hm.getBeanType();
	Method method = hm.getMethod();
	if (CompensableCoordinatorController.class.equals(clazz)) {
		return;
	} else if (ErrorController.class.isInstance(hm.getBean())) {
		return;
	}

	Transactional globalTransactional = clazz.getAnnotation(Transactional.class);
	Transactional methodTransactional = method.getAnnotation(Transactional.class);
	boolean transactionalDefined = globalTransactional != null || methodTransactional != null;
	Compensable annotation = clazz.getAnnotation(Compensable.class);
	if (transactionalDefined && annotation == null) {
		return;
	}

	SpringCloudBeanRegistry beanRegistry = SpringCloudBeanRegistry.getInstance();
	CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory();
	CompensableManager compensableManager = beanFactory.getCompensableManager();
	TransactionInterceptor transactionInterceptor = beanFactory.getTransactionInterceptor();

	CompensableTransaction compensable = compensableManager.getCompensableTransactionQuietly();
	TransactionContext transactionContext = compensable.getTransactionContext();

	// byte[] byteArray = SerializeUtils.serializeObject(transactionContext);
	// String compensableStr = ByteUtils.byteArrayToString(byteArray);
	// response.setHeader(HEADER_TRANCACTION_KEY, compensableStr);
	// response.setHeader(HEADER_PROPAGATION_KEY, this.identifier);

	TransactionResponseImpl resp = new TransactionResponseImpl();
	resp.setTransactionContext(transactionContext);
	resp.setSourceTransactionCoordinator(beanRegistry.getConsumeCoordinator(null));

	transactionInterceptor.beforeSendResponse(resp);

}
 
Example 20
Source File: CompensableHandlerInterceptor.java    From ByteTCC with GNU Lesser General Public License v3.0 4 votes vote down vote up
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
	String transactionStr = request.getHeader(HEADER_TRANCACTION_KEY);
	if (StringUtils.isBlank(transactionStr)) {
		return true;
	}

	if (HandlerMethod.class.isInstance(handler) == false) {
		logger.warn("CompensableHandlerInterceptor cannot handle current request(uri= {}, handler= {}) correctly.",
				request.getRequestURI(), handler);
		return true;
	}

	HandlerMethod hm = (HandlerMethod) handler;
	Class<?> clazz = hm.getBeanType();
	Method method = hm.getMethod();
	if (CompensableCoordinatorController.class.equals(clazz)) {
		return true;
	} else if (ErrorController.class.isInstance(hm.getBean())) {
		return true;
	}

	String propagationStr = request.getHeader(HEADER_PROPAGATION_KEY);

	String transactionText = StringUtils.trimToNull(transactionStr);
	String propagationText = StringUtils.trimToNull(propagationStr);

	Transactional globalTransactional = clazz.getAnnotation(Transactional.class);
	Transactional methodTransactional = method.getAnnotation(Transactional.class);
	boolean transactionalDefined = globalTransactional != null || methodTransactional != null;
	Compensable annotation = clazz.getAnnotation(Compensable.class);
	if (transactionalDefined && annotation == null) {
		logger.warn("Invalid transaction definition(uri={}, handler= {})!", request.getRequestURI(), handler,
				new IllegalStateException());
		return true;
	}

	SpringCloudBeanRegistry beanRegistry = SpringCloudBeanRegistry.getInstance();
	CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory();
	TransactionInterceptor transactionInterceptor = beanFactory.getTransactionInterceptor();

	byte[] byteArray = transactionText == null ? new byte[0] : Base64.getDecoder().decode(transactionText);

	TransactionContext transactionContext = null;
	if (byteArray != null && byteArray.length > 0) {
		transactionContext = (TransactionContext) SerializeUtils.deserializeObject(byteArray);
		transactionContext.setPropagated(true);
		transactionContext.setPropagatedBy(propagationText);
	}

	TransactionRequestImpl req = new TransactionRequestImpl();
	req.setTransactionContext(transactionContext);
	req.setTargetTransactionCoordinator(beanRegistry.getConsumeCoordinator(propagationText));

	transactionInterceptor.afterReceiveRequest(req);

	CompensableManager compensableManager = beanFactory.getCompensableManager();
	CompensableTransaction compensable = compensableManager.getCompensableTransactionQuietly();
	String propagatedBy = (String) compensable.getTransactionContext().getPropagatedBy();

	byte[] responseByteArray = SerializeUtils.serializeObject(compensable.getTransactionContext());
	String compensableStr = Base64.getEncoder().encodeToString(responseByteArray);
	response.setHeader(HEADER_TRANCACTION_KEY, compensableStr);
	response.setHeader(HEADER_PROPAGATION_KEY, this.identifier);

	String sourceApplication = CommonUtils.getApplication(propagatedBy);
	String targetApplication = CommonUtils.getApplication(propagationText);
	if (StringUtils.isNotBlank(sourceApplication) && StringUtils.isNotBlank(targetApplication)) {
		response.setHeader(HEADER_RECURSIVELY_KEY,
				String.valueOf(StringUtils.equalsIgnoreCase(sourceApplication, targetApplication) == false));
	}

	return true;
}