1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

Polish alibaba/spring-cloud-alibaba#1758 : [CodeBase] Sync the source code from greenwich to finichley

This commit is contained in:
mercyblitz 2020-09-21 14:13:17 +08:00
parent 20270c975e
commit 4252051ec6
7 changed files with 32 additions and 30 deletions

View File

@ -44,7 +44,7 @@ public class SeataFeignClient implements Client {
SeataFeignClient(BeanFactory beanFactory) { SeataFeignClient(BeanFactory beanFactory) {
this.beanFactory = beanFactory; this.beanFactory = beanFactory;
this.delegate = new Client.Default(null, null); this.delegate = new Default(null, null);
} }
SeataFeignClient(BeanFactory beanFactory, Client delegate) { SeataFeignClient(BeanFactory beanFactory, Client delegate) {

View File

@ -65,19 +65,19 @@ public class SeataFeignClientAutoConfiguration {
protected static class FeignBeanPostProcessorConfiguration { protected static class FeignBeanPostProcessorConfiguration {
@Bean @Bean
SeataBeanPostProcessor seataBeanPostProcessor( SeataBeanPostProcessor seataBeanPostProcessor(
SeataFeignObjectWrapper seataFeignObjectWrapper) { SeataFeignObjectWrapper seataFeignObjectWrapper) {
return new SeataBeanPostProcessor(seataFeignObjectWrapper); return new SeataBeanPostProcessor(seataFeignObjectWrapper);
} }
@Bean @Bean
SeataContextBeanPostProcessor seataContextBeanPostProcessor( SeataContextBeanPostProcessor seataContextBeanPostProcessor(
BeanFactory beanFactory) { BeanFactory beanFactory) {
return new SeataContextBeanPostProcessor(beanFactory); return new SeataContextBeanPostProcessor(beanFactory);
} }
@Bean @Bean
SeataFeignObjectWrapper seataFeignObjectWrapper(BeanFactory beanFactory) { SeataFeignObjectWrapper seataFeignObjectWrapper(BeanFactory beanFactory) {
return new SeataFeignObjectWrapper(beanFactory); return new SeataFeignObjectWrapper(beanFactory);
} }

View File

@ -33,9 +33,9 @@ import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
public class SeataLoadBalancerFeignClient extends LoadBalancerFeignClient { public class SeataLoadBalancerFeignClient extends LoadBalancerFeignClient {
SeataLoadBalancerFeignClient(Client delegate, SeataLoadBalancerFeignClient(Client delegate,
CachingSpringLoadBalancerFactory lbClientFactory, CachingSpringLoadBalancerFactory lbClientFactory,
SpringClientFactory clientFactory, SpringClientFactory clientFactory,
SeataFeignObjectWrapper seataFeignObjectWrapper) { SeataFeignObjectWrapper seataFeignObjectWrapper) {
super((Client) seataFeignObjectWrapper.wrap(delegate), lbClientFactory, super((Client) seataFeignObjectWrapper.wrap(delegate), lbClientFactory,
clientFactory); clientFactory);
} }

View File

@ -30,7 +30,7 @@ import org.springframework.context.annotation.Configuration;
public class SeataHystrixAutoConfiguration { public class SeataHystrixAutoConfiguration {
@Bean @Bean
SeataHystrixConcurrencyStrategy seataHystrixConcurrencyStrategy() { SeataHystrixConcurrencyStrategy seataHystrixConcurrencyStrategy() {
return new SeataHystrixConcurrencyStrategy(); return new SeataHystrixConcurrencyStrategy();
} }

View File

@ -46,6 +46,7 @@ public class SeataHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy
private final Logger logger = LoggerFactory private final Logger logger = LoggerFactory
.getLogger(SeataHystrixConcurrencyStrategy.class); .getLogger(SeataHystrixConcurrencyStrategy.class);
private HystrixConcurrencyStrategy delegate; private HystrixConcurrencyStrategy delegate;
public SeataHystrixConcurrencyStrategy() { public SeataHystrixConcurrencyStrategy() {

View File

@ -34,7 +34,7 @@ public class SeataRestTemplateInterceptor implements ClientHttpRequestIntercepto
@Override @Override
public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes, public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes,
ClientHttpRequestExecution clientHttpRequestExecution) throws IOException { ClientHttpRequestExecution clientHttpRequestExecution) throws IOException {
HttpRequestWrapper requestWrapper = new HttpRequestWrapper(httpRequest); HttpRequestWrapper requestWrapper = new HttpRequestWrapper(httpRequest);
String xid = RootContext.getXID(); String xid = RootContext.getXID();

View File

@ -19,21 +19,21 @@ package com.alibaba.cloud.seata.web;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import io.seata.common.util.StringUtils;
import io.seata.core.context.RootContext; import io.seata.core.context.RootContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.HandlerInterceptor;
/** /**
* @author xiaojing * @author xiaojing
* *
* Seata HandlerInterceptor, Convert Seata information into * Seata HandlerInterceptor, Convert Seata information into
* @see io.seata.core.context.RootContext from http request's header in * @see RootContext from http request's header in
* {@link org.springframework.web.servlet.HandlerInterceptor#preHandle(HttpServletRequest , HttpServletResponse , Object )}, * {@link HandlerInterceptor#preHandle(HttpServletRequest, HttpServletResponse, Object )},
* And clean up Seata information after servlet method invocation in * And clean up Seata information after servlet method invocation in
* {@link org.springframework.web.servlet.HandlerInterceptor#afterCompletion(HttpServletRequest, HttpServletResponse, Object, Exception)} * {@link HandlerInterceptor#afterCompletion(HttpServletRequest, HttpServletResponse, Object, Exception)}
*/ */
public class SeataHandlerInterceptor implements HandlerInterceptor { public class SeataHandlerInterceptor implements HandlerInterceptor {
@ -42,7 +42,7 @@ public class SeataHandlerInterceptor implements HandlerInterceptor {
@Override @Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object handler) { Object handler) {
String xid = RootContext.getXID(); String xid = RootContext.getXID();
String rpcXid = request.getHeader(RootContext.KEY_XID); String rpcXid = request.getHeader(RootContext.KEY_XID);
@ -50,7 +50,7 @@ public class SeataHandlerInterceptor implements HandlerInterceptor {
log.debug("xid in RootContext {} xid in RpcContext {}", xid, rpcXid); log.debug("xid in RootContext {} xid in RpcContext {}", xid, rpcXid);
} }
if (xid == null && rpcXid != null) { if (StringUtils.isBlank(xid) && rpcXid != null) {
RootContext.bind(rpcXid); RootContext.bind(rpcXid);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("bind {} to RootContext", rpcXid); log.debug("bind {} to RootContext", rpcXid);
@ -61,23 +61,24 @@ public class SeataHandlerInterceptor implements HandlerInterceptor {
@Override @Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
Object handler, Exception e) { Object handler, Exception e) {
if (StringUtils.isNotBlank(RootContext.getXID())) {
String rpcXid = request.getHeader(RootContext.KEY_XID);
String rpcXid = request.getHeader(RootContext.KEY_XID); if (StringUtils.isEmpty(rpcXid)) {
return;
}
if (StringUtils.isEmpty(rpcXid)) { String unbindXid = RootContext.unbind();
return; if (log.isDebugEnabled()) {
} log.debug("unbind {} from RootContext", unbindXid);
}
String unbindXid = RootContext.unbind(); if (!rpcXid.equalsIgnoreCase(unbindXid)) {
if (log.isDebugEnabled()) { log.warn("xid in change during RPC from {} to {}", rpcXid, unbindXid);
log.debug("unbind {} from RootContext", unbindXid); if (unbindXid != null) {
} RootContext.bind(unbindXid);
if (!rpcXid.equalsIgnoreCase(unbindXid)) { log.warn("bind {} back to RootContext", unbindXid);
log.warn("xid in change during RPC from {} to {}", rpcXid, unbindXid); }
if (unbindXid != null) {
RootContext.bind(unbindXid);
log.warn("bind {} back to RootContext", unbindXid);
} }
} }
} }