mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
upgrade Seata version to 0.5.0
Signed-off-by: jimin.jm <jimin.jm@alibaba-inc.com>
This commit is contained in:
@@ -16,8 +16,8 @@
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fescar</groupId>
|
||||
<artifactId>fescar-spring</artifactId>
|
||||
<groupId>io.seata</groupId>
|
||||
<artifactId>seata-spring</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.alibaba.seata;
|
||||
|
||||
import com.alibaba.fescar.spring.annotation.GlobalTransactionScanner;
|
||||
import io.seata.spring.annotation.GlobalTransactionScanner;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
@@ -23,13 +23,11 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.fescar.core.context.RootContext;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
|
||||
import feign.Client;
|
||||
import feign.Request;
|
||||
import feign.Response;
|
||||
import io.seata.core.context.RootContext;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -37,49 +35,49 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class SeataFeignClient implements Client {
|
||||
|
||||
private final Client delegate;
|
||||
private final BeanFactory beanFactory;
|
||||
private final Client delegate;
|
||||
private final BeanFactory beanFactory;
|
||||
private static final int MAP_SIZE = 16;
|
||||
|
||||
SeataFeignClient(BeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
this.delegate = new Client.Default(null, null);
|
||||
}
|
||||
SeataFeignClient(BeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
this.delegate = new Client.Default(null, null);
|
||||
}
|
||||
|
||||
SeataFeignClient(BeanFactory beanFactory, Client delegate) {
|
||||
this.delegate = delegate;
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
SeataFeignClient(BeanFactory beanFactory, Client delegate) {
|
||||
this.delegate = delegate;
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response execute(Request request, Request.Options options) throws IOException {
|
||||
@Override
|
||||
public Response execute(Request request, Request.Options options) throws IOException {
|
||||
|
||||
Request modifiedRequest = getModifyRequest(request);
|
||||
Request modifiedRequest = getModifyRequest(request);
|
||||
|
||||
try {
|
||||
return this.delegate.execute(modifiedRequest, options);
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
return this.delegate.execute(modifiedRequest, options);
|
||||
} finally {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Request getModifyRequest(Request request) {
|
||||
private Request getModifyRequest(Request request) {
|
||||
|
||||
String xid = RootContext.getXID();
|
||||
String xid = RootContext.getXID();
|
||||
|
||||
if (StringUtils.isEmpty(xid)) {
|
||||
return request;
|
||||
}
|
||||
if (StringUtils.isEmpty(xid)) {
|
||||
return request;
|
||||
}
|
||||
|
||||
Map<String, Collection<String>> headers = new HashMap<>();
|
||||
headers.putAll(request.headers());
|
||||
Map<String, Collection<String>> headers = new HashMap<>(MAP_SIZE);
|
||||
headers.putAll(request.headers());
|
||||
|
||||
List<String> fescarXid = new ArrayList<>();
|
||||
fescarXid.add(xid);
|
||||
headers.put(RootContext.KEY_XID, fescarXid);
|
||||
List<String> fescarXid = new ArrayList<>();
|
||||
fescarXid.add(xid);
|
||||
headers.put(RootContext.KEY_XID, fescarXid);
|
||||
|
||||
return Request.create(request.method(), request.url(), headers, request.body(),
|
||||
request.charset());
|
||||
}
|
||||
return Request.create(request.method(), request.url(), headers, request.body(),
|
||||
request.charset());
|
||||
}
|
||||
|
||||
}
|
@@ -65,19 +65,19 @@ public class SeataFeignClientAutoConfiguration {
|
||||
protected static class FeignBeanPostProcessorConfiguration {
|
||||
|
||||
@Bean
|
||||
SeataBeanPostProcessor fescarBeanPostProcessor(
|
||||
SeataBeanPostProcessor seataBeanPostProcessor(
|
||||
SeataFeignObjectWrapper seataFeignObjectWrapper) {
|
||||
return new SeataBeanPostProcessor(seataFeignObjectWrapper);
|
||||
}
|
||||
|
||||
@Bean
|
||||
SeataContextBeanPostProcessor fescarContextBeanPostProcessor(
|
||||
SeataContextBeanPostProcessor seataContextBeanPostProcessor(
|
||||
BeanFactory beanFactory) {
|
||||
return new SeataContextBeanPostProcessor(beanFactory);
|
||||
}
|
||||
|
||||
@Bean
|
||||
SeataFeignObjectWrapper fescarFeignObjectWrapper(BeanFactory beanFactory) {
|
||||
SeataFeignObjectWrapper seataFeignObjectWrapper(BeanFactory beanFactory) {
|
||||
return new SeataFeignObjectWrapper(beanFactory);
|
||||
}
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ import com.netflix.hystrix.HystrixCommand;
|
||||
public class SeataHystrixAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
SeataHystrixConcurrencyStrategy fescarHystrixConcurrencyStrategy() {
|
||||
SeataHystrixConcurrencyStrategy seataHystrixConcurrencyStrategy() {
|
||||
return new SeataHystrixConcurrencyStrategy();
|
||||
}
|
||||
|
||||
|
@@ -17,7 +17,7 @@ package org.springframework.cloud.alibaba.seata.feign.hystrix;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import com.alibaba.fescar.core.context.RootContext;
|
||||
import io.seata.core.context.RootContext;
|
||||
|
||||
import com.netflix.hystrix.strategy.HystrixPlugins;
|
||||
import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy;
|
||||
@@ -37,7 +37,7 @@ public class SeataHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy
|
||||
|
||||
@Override
|
||||
public <K> Callable<K> wrapCallable(Callable<K> c) {
|
||||
if (c instanceof FescarContextCallable) {
|
||||
if (c instanceof SeataContextCallable) {
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -48,19 +48,19 @@ public class SeataHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy
|
||||
else {
|
||||
wrappedCallable = c;
|
||||
}
|
||||
if (wrappedCallable instanceof FescarContextCallable) {
|
||||
if (wrappedCallable instanceof SeataContextCallable) {
|
||||
return wrappedCallable;
|
||||
}
|
||||
|
||||
return new FescarContextCallable<>(wrappedCallable);
|
||||
return new SeataContextCallable<>(wrappedCallable);
|
||||
}
|
||||
|
||||
private static class FescarContextCallable<K> implements Callable<K> {
|
||||
private static class SeataContextCallable<K> implements Callable<K> {
|
||||
|
||||
private final Callable<K> actual;
|
||||
private final String xid;
|
||||
|
||||
FescarContextCallable(Callable<K> actual) {
|
||||
SeataContextCallable(Callable<K> actual) {
|
||||
this.actual = actual;
|
||||
this.xid = RootContext.getXID();
|
||||
}
|
||||
|
@@ -50,7 +50,7 @@ import java.util.List;
|
||||
public class SeataRestTemplateAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public SeataRestTemplateInterceptor fescarRestTemplateInterceptor() {
|
||||
public SeataRestTemplateInterceptor seataRestTemplateInterceptor() {
|
||||
return new SeataRestTemplateInterceptor();
|
||||
}
|
||||
|
||||
|
@@ -18,7 +18,7 @@ package org.springframework.cloud.alibaba.seata.rest;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.alibaba.fescar.core.context.RootContext;
|
||||
import io.seata.core.context.RootContext;
|
||||
|
||||
import org.springframework.http.HttpRequest;
|
||||
import org.springframework.http.client.ClientHttpRequestExecution;
|
||||
|
@@ -19,7 +19,7 @@ package org.springframework.cloud.alibaba.seata.web;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.alibaba.fescar.core.context.RootContext;
|
||||
import io.seata.core.context.RootContext;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -29,10 +29,10 @@ import org.springframework.web.servlet.HandlerInterceptor;
|
||||
/**
|
||||
* @author xiaojing
|
||||
*
|
||||
* Fescar HandlerInterceptor, Convert Fescar information into
|
||||
* @see com.alibaba.fescar.core.context.RootContext from http request's header in
|
||||
* Seata HandlerInterceptor, Convert Seata information into
|
||||
* @see io.seata.core.context.RootContext from http request's header in
|
||||
* {@link org.springframework.web.servlet.HandlerInterceptor#preHandle(HttpServletRequest , HttpServletResponse , Object )},
|
||||
* And clean up Fescar 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)}
|
||||
*/
|
||||
public class SeataHandlerInterceptor implements HandlerInterceptor {
|
||||
@@ -42,7 +42,7 @@ public class SeataHandlerInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler) throws Exception {
|
||||
Object handler) {
|
||||
|
||||
String xid = RootContext.getXID();
|
||||
String rpcXid = request.getHeader(RootContext.KEY_XID);
|
||||
@@ -61,7 +61,7 @@ public class SeataHandlerInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler, Exception e) throws Exception {
|
||||
Object handler, Exception e) {
|
||||
|
||||
String rpcXid = request.getHeader(RootContext.KEY_XID);
|
||||
|
||||
|
Reference in New Issue
Block a user