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

sync code

This commit is contained in:
flystar32
2019-06-03 14:45:31 +08:00
parent 2dc4061c58
commit 508f0f864e
26 changed files with 223 additions and 181 deletions

View File

@@ -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>

View File

@@ -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;

View File

@@ -27,7 +27,7 @@ public class SeataProperties {
// todo support config Fescar server information
/**
* Fescar tx service group.default is ${spring.application.name}-fescar-service-group.
* Seata tx service group.default is ${spring.application.name}-fescar-service-group.
*/
private String txServiceGroup;

View File

@@ -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());
}
}

View File

@@ -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);
}
}

View File

@@ -30,7 +30,7 @@ import com.netflix.hystrix.HystrixCommand;
public class SeataHystrixAutoConfiguration {
@Bean
SeataHystrixConcurrencyStrategy fescarHystrixConcurrencyStrategy() {
SeataHystrixConcurrencyStrategy seataHystrixConcurrencyStrategy() {
return new SeataHystrixConcurrencyStrategy();
}

View File

@@ -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();
}

View File

@@ -31,18 +31,17 @@
package org.springframework.cloud.alibaba.seata.rest;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.web.client.RestTemplate;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* @author xiaojing
*/
@@ -51,7 +50,7 @@ import org.springframework.web.client.RestTemplate;
public class SeataRestTemplateAutoConfiguration {
@Bean
public SeataRestTemplateInterceptor fescarRestTemplateInterceptor() {
public SeataRestTemplateInterceptor seataRestTemplateInterceptor() {
return new SeataRestTemplateInterceptor();
}

View File

@@ -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;

View File

@@ -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;
@@ -30,10 +30,10 @@ import org.springframework.web.servlet.ModelAndView;
/**
* @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 {