Merge remote-tracking branch 'origin/leng_dev' into leng_dev

This commit is contained in:
冷冷 committed 2019-01-31 14:11:57 +08:00
commit db0a3e0de6
7 files changed
+16 -16

No files matched your search

@@ -42,7 +42,7 @@ import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResour
*/
@Configuration
@ConditionalOnClass(Feign.class)
public class PigxFeginConfiguration {
public class PigxFeignConfiguration {
@Bean
@ConditionalOnProperty("security.oauth2.client.client-id")
@@ -61,7 +61,7 @@ public class PigxFeginConfiguration {
public Feign.Builder feignHystrixBuilder(FeignContext feignContext) {
return PigxHystrixFeign.builder(feignContext)
.decode404()
.errorDecoder(new PigxFeginErrorDecoder());
.errorDecoder(new PigxFeignErrorDecoder());
}
}
@@ -48,30 +48,30 @@ import static java.util.concurrent.TimeUnit.SECONDS;
*
* @author L.cm
*/
public class PigxFeginErrorDecoder extends ErrorDecoder.Default {
public class PigxFeignErrorDecoder extends ErrorDecoder.Default {
private final RetryAfterDecoder retryAfterDecoder = new RetryAfterDecoder();
private static final String REGEX = "^[0-9]+$";
@Override
public Exception decode(String methodKey, Response response) {
PigxFeginException exception = errorStatus(methodKey, response);
PigxFeignException exception = errorStatus(methodKey, response);
Date retryAfter = retryAfterDecoder.apply(firstOrNull(response.headers()));
return new RetryableException(exception.getMessage(), response.request().httpMethod(), exception, retryAfter);
}
private static PigxFeginException errorStatus(String methodKey, Response response) {
private static PigxFeignException errorStatus(String methodKey, Response response) {
try {
if (response.body() != null) {
Reader reader = response.body().asReader();
return new PigxFeginException(R.builder()
return new PigxFeignException(R.builder()
.msg(IoUtil.read(reader))
.code(CommonConstants.FAIL).build());
}
} catch (IOException ignored) { // NOPMD
}
String message = format("status %s reading %s", response.status(), methodKey);
return new PigxFeginException(message);
return new PigxFeignException(message);
}
@Nullable
@@ -29,16 +29,16 @@ import lombok.Getter;
*
* @author L.cm
*/
public class PigxFeginException extends RuntimeException {
public class PigxFeignException extends RuntimeException {
@Getter
private final R result;
public PigxFeginException(R result) {
public PigxFeignException(R result) {
super(result.getMsg());
this.result = result;
}
public PigxFeginException(String message) {
public PigxFeignException(String message) {
super(message);
this.result = R.builder()
.code(CommonConstants.FAIL)
@@ -36,8 +36,8 @@ import java.util.concurrent.ConcurrentMap;
*/
@Slf4j
@NoArgsConstructor
public final class PigxFeginFallbackFactory<T> implements FallbackFactory<T> {
public static final PigxFeginFallbackFactory INSTANCE = new PigxFeginFallbackFactory();
public final class PigxFeignFallbackFactory<T> implements FallbackFactory<T> {
public static final PigxFeignFallbackFactory INSTANCE = new PigxFeignFallbackFactory();
private static final ConcurrentMap<Class<?>, Object> FALLBACK_MAP = new ConcurrentHashMap<>();
@SuppressWarnings("unchecked")
@@ -27,8 +27,8 @@ public class PigxFeignFallbackMethod implements MethodInterceptor {
type.getName(), method.getName(), cause.getMessage());
if (R.class == method.getReturnType()) {
final R result = cause instanceof PigxFeginException ?
((PigxFeginException) cause).getResult() : R.builder()
final R result = cause instanceof PigxFeignException ?
((PigxFeignException) cause).getResult() : R.builder()
.code(CommonConstants.FAIL)
.msg(cause.getMessage()).build();
return result;
@@ -137,7 +137,7 @@ public final class PigxHystrixInvocationHandler implements InvocationHandler {
Object fallback;
try {
if (fallbackFactory == null) {
fallback = PigxFeginFallbackFactory.INSTANCE.create(target.type(), getExecutionException());
fallback = PigxFeignFallbackFactory.INSTANCE.create(target.type(), getExecutionException());
} else {
fallback = fallbackFactory.create(getExecutionException());
}
@@ -1,3 +1,3 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.pig4cloud.pigx.common.security.feign.PigxFeginConfiguration,\
com.pig4cloud.pigx.common.security.feign.PigxFeignConfiguration,\
com.pig4cloud.pigx.common.security.service.PigxUserDetailsServiceImpl