Commit 9ee8fbf37391e64e90f4ff65e25d41a1fd826354

Authored by miaoguoxin
1 parent 8ef7b71d

代码格式化

Showing 24 changed files with 75 additions and 83 deletions
gateway-core/src/main/java/com/diligrp/xtrade/core/api/ApiManager.java
... ... @@ -3,11 +3,8 @@ package com.diligrp.xtrade.core.api;
3 3 import com.diligrp.xtrade.core.common.utils.PathUtils;
4 4 import com.diligrp.xtrade.core.config.property.AuthPathProperties;
5 5 import org.springframework.beans.factory.annotation.Autowired;
6   -import org.springframework.http.server.PathContainer;
7 6 import org.springframework.stereotype.Component;
8 7  
9   -import java.util.Optional;
10   -
11 8 /**
12 9 * @Auther: miaoguoxin
13 10 * @Date: 2019/3/26 0026 15:37
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/common/annotation/DispatchMapping.java
... ... @@ -16,11 +16,11 @@ import java.lang.annotation.Target;
16 16 @Documented
17 17 public @interface DispatchMapping {
18 18 /**
19   - * 映射路径
20   - * @param
21   - * @return
22   - * @author miaoguoxin
23   - * @date 2020/4/15
24   - */
  19 + * 映射路径
  20 + * @param
  21 + * @return
  22 + * @author miaoguoxin
  23 + * @date 2020/4/15
  24 + */
25 25 String value() default "";
26 26 }
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/common/constant/GatewayAttrType.java
... ... @@ -10,8 +10,8 @@ import java.util.Arrays;
10 10 * @Description: 网关属性类型(类型含义需参见spring cloud gateway官方文档)
11 11 */
12 12 public enum GatewayAttrType implements IEnumType {
13   - PREDICATE(1,"断言配置"),
14   - FILTER(2,"过滤器"),
  13 + PREDICATE(1, "断言配置"),
  14 + FILTER(2, "过滤器"),
15 15 ;
16 16 /**
17 17 * 编码
... ... @@ -23,7 +23,7 @@ public enum GatewayAttrType implements IEnumType {
23 23  
24 24 GatewayAttrType(int value, String desc) {
25 25 this.value = value;
26   - this.desc=desc;
  26 + this.desc = desc;
27 27 }
28 28  
29 29 public int getValue() {
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/common/utils/HttpUtils.java
... ... @@ -3,8 +3,6 @@ package com.diligrp.xtrade.core.common.utils;
3 3 import org.springframework.http.HttpHeaders;
4 4 import org.springframework.http.server.reactive.ServerHttpRequest;
5 5  
6   -import javax.servlet.http.HttpServletRequest;
7   -
8 6 /**
9 7 * @Auther: miaoguoxin
10 8 * @Date: 2020/4/24 10:23
... ... @@ -14,7 +12,7 @@ public class HttpUtils {
14 12 * @Description: 获取客户端IP地址
15 13 */
16 14 public static String getIpAddr(ServerHttpRequest request) {
17   - if (request==null){
  15 + if (request == null) {
18 16 return "127.0.0.1";
19 17 }
20 18 HttpHeaders headers = request.getHeaders();
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/common/utils/PathUtils.java
1 1 package com.diligrp.xtrade.core.common.utils;
2 2  
3 3 import org.springframework.http.server.PathContainer;
4   -import org.springframework.util.CollectionUtils;
5 4 import org.springframework.web.util.pattern.PathPattern;
6 5 import org.springframework.web.util.pattern.PathPatternParser;
7 6  
... ... @@ -14,15 +13,15 @@ import java.util.concurrent.CopyOnWriteArrayList;
14 13 * @Date: 2020/4/15 10:37
15 14 */
16 15 public class PathUtils {
17   - private static final PathPatternParser PATH_PATTERN_PARSER = new PathPatternParser();
  16 + private static final PathPatternParser PATH_PATTERN_PARSER = new PathPatternParser();
18 17  
19 18 /**
20   - * 多个路径拼接成一个标准uri,ex: /test + gateway = /test/gateway
21   - * @author miaoguoxin
22   - * @date 2020/4/15
23   - */
24   - public static String concatUri(String... paths){
25   - if (paths==null || paths.length ==0){
  19 + * 多个路径拼接成一个标准uri,ex: /test + gateway = /test/gateway
  20 + * @author miaoguoxin
  21 + * @date 2020/4/15
  22 + */
  23 + public static String concatUri(String... paths) {
  24 + if (paths == null || paths.length == 0) {
26 25 return "";
27 26 }
28 27 StringBuilder sb = new StringBuilder();
... ... @@ -30,17 +29,17 @@ public class PathUtils {
30 29 sb.append("/").append(path).append("/");
31 30 }
32 31 String s = removeExtraSlashOfUrl(sb.toString());
33   - if (s.endsWith("/")){
34   - s= s.substring(0,s.length()-1);
  32 + if (s.endsWith("/")) {
  33 + s = s.substring(0, s.length() - 1);
35 34 }
36 35 return s;
37 36 }
38 37  
39 38 /**
40   - * 去除多余的斜杠
41   - * @author miaoguoxin
42   - * @date 2020/4/15
43   - */
  39 + * 去除多余的斜杠
  40 + * @author miaoguoxin
  41 + * @date 2020/4/15
  42 + */
44 43 public static String removeExtraSlashOfUrl(String url) {
45 44 if (url == null || url.length() == 0) {
46 45 return url;
... ... @@ -49,11 +48,11 @@ public class PathUtils {
49 48 }
50 49  
51 50 /**
52   - * 判断uri是否匹配
53   - * @author miaoguoxin
54   - * @date 2020/4/15
55   - */
56   - public static boolean isUriMatch(String path, List<PathPattern> pathPatterns){
  51 + * 判断uri是否匹配
  52 + * @author miaoguoxin
  53 + * @date 2020/4/15
  54 + */
  55 + public static boolean isUriMatch(String path, List<PathPattern> pathPatterns) {
57 56 PathContainer pathContainer = PathContainer.parsePath(path);
58 57 return Optional.ofNullable(pathPatterns)
59 58 .map(patterns -> patterns
... ... @@ -80,15 +79,15 @@ public class PathUtils {
80 79 }
81 80  
82 81 /**
83   - * 转换路径格式
84   - * @author miaoguoxin
85   - * @date 2020/4/15
86   - */
87   - public static List<PathPattern> assemblePath(String[] paths,List<PathPattern> pathPatterns){
88   - if (paths == null || paths.length == 0){
  82 + * 转换路径格式
  83 + * @author miaoguoxin
  84 + * @date 2020/4/15
  85 + */
  86 + public static List<PathPattern> assemblePath(String[] paths, List<PathPattern> pathPatterns) {
  87 + if (paths == null || paths.length == 0) {
89 88 return null;
90 89 }
91   - if (pathPatterns == null){
  90 + if (pathPatterns == null) {
92 91 pathPatterns = new CopyOnWriteArrayList<>();
93 92 }
94 93 for (String path : paths) {
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/common/utils/ResponseUtils.java
... ... @@ -17,13 +17,13 @@ import java.nio.charset.StandardCharsets;
17 17 public class ResponseUtils {
18 18  
19 19  
20   - public static Mono<Void> writeForbidden(ServerHttpResponse response){
  20 + public static Mono<Void> writeForbidden(ServerHttpResponse response) {
21 21 Message<?> message = Message.failure(
22   - HttpStatus.FORBIDDEN.value(),HttpStatus.FORBIDDEN.toString());
23   - return writeResponse(response,message);
  22 + HttpStatus.FORBIDDEN.value(), HttpStatus.FORBIDDEN.toString());
  23 + return writeResponse(response, message);
24 24 }
25 25  
26   - public static Mono<Void> writeResponse(ServerHttpResponse response,Message<?> message){
  26 + public static Mono<Void> writeResponse(ServerHttpResponse response, Message<?> message) {
27 27 String respJson = JsonUtils.toJsonString(message);
28 28 response.getHeaders().setContentLength(
29 29 respJson.getBytes(StandardCharsets.UTF_8).length);
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/common/utils/ValidateUtils.java
... ... @@ -22,11 +22,11 @@ public class ValidateUtils {
22 22  
23 23  
24 24 @Autowired
25   - public void setValidator(Validator validator){
  25 + public void setValidator(Validator validator) {
26 26 ValidateUtils.validator = validator;
27 27 }
28 28  
29   - public static void validate(Object params){
  29 + public static void validate(Object params) {
30 30 validate(params, new Class[]{});
31 31 }
32 32  
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/config/GatewayResourceLoaderConfiguration.java
... ... @@ -26,7 +26,7 @@ import java.util.Properties;
26 26 public class GatewayResourceLoaderConfiguration {
27 27  
28 28 @Bean
29   - public ConfigService configService(Environment environment,NacosConfigProperties configProperties){
  29 + public ConfigService configService(Environment environment, NacosConfigProperties configProperties) {
30 30 String username = environment.getProperty("spring.cloud.nacos.config.username");
31 31 String password = environment.getProperty("spring.cloud.nacos.config.password");
32 32 Properties properties = new Properties();
... ... @@ -46,15 +46,15 @@ public class GatewayResourceLoaderConfiguration {
46 46 }
47 47  
48 48 @Bean(name = "cloudRouteResourceLoader")
49   - @ConditionalOnProperty(prefix = "xtrade",name = "gateway-loader",havingValue = "cloud",matchIfMissing = true)
50   - public DynamicRouteLoaderIntf cloudRouteResourceLoader(){
  49 + @ConditionalOnProperty(prefix = "xtrade", name = "gateway-loader", havingValue = "cloud", matchIfMissing = true)
  50 + public DynamicRouteLoaderIntf cloudRouteResourceLoader() {
51 51 return new CloudRouteResourceLoader();
52 52 }
53 53  
54 54  
55 55 @Bean(name = "mysqlRouteResourceLoader")
56   - @ConditionalOnProperty(prefix = "xtrade",name = "gateway-loader",havingValue = "mysql")
57   - public DynamicRouteLoaderIntf mysqlRouteResourceLoader(){
  56 + @ConditionalOnProperty(prefix = "xtrade", name = "gateway-loader", havingValue = "mysql")
  57 + public DynamicRouteLoaderIntf mysqlRouteResourceLoader() {
58 58 return new MysqlRouteResourceLoader();
59 59 }
60 60  
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/config/property/AuthPathProperties.java
... ... @@ -22,10 +22,10 @@ public class AuthPathProperties {
22 22  
23 23  
24 24 /**
25   - * 属性配置刷新的时候会从这里进入(不要直接注释掉属性配置,否则无法触发)
26   - * @author miaoguoxin
27   - * @date 2020/4/13
28   - */
  25 + * 属性配置刷新的时候会从这里进入(不要直接注释掉属性配置,否则无法触发)
  26 + * @author miaoguoxin
  27 + * @date 2020/4/13
  28 + */
29 29 public void setExcludePaths(String[] excludePaths) {
30 30 this.excludePaths = excludePaths;
31 31 if (!CollectionUtils.isEmpty(this.excludePathPatterns)) {
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/filters/global/CacheRequestBodyGlobalFilter.java
1 1 package com.diligrp.xtrade.core.filters.global;
2 2  
3 3 import com.diligrp.xtrade.core.common.constant.GatewayConst;
4   -import com.diligrp.xtrade.shared.util.JsonUtils;
5 4 import org.apache.commons.lang3.StringUtils;
6 5 import org.springframework.cloud.gateway.filter.GatewayFilterChain;
7 6 import org.springframework.cloud.gateway.filter.GlobalFilter;
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/filters/global/ResponseReadBodyGlobalFilter.java
... ... @@ -74,7 +74,7 @@ public class ResponseReadBodyGlobalFilter implements GlobalFilter, Ordered {
74 74 ClientResponse clientResponse = this.prepareClientResponse(exchange.getResponse().getStatusCode(), body, httpHeaders);
75 75 Mono<String> bodyMono = clientResponse.bodyToMono(String.class);
76 76 return bodyMono.flatMap(respBody -> {
77   - exchange.getAttributes().putIfAbsent(GatewayConst.CACHED_RESPONSE_BODY_STR_ATTR,respBody);
  77 + exchange.getAttributes().putIfAbsent(GatewayConst.CACHED_RESPONSE_BODY_STR_ATTR, respBody);
78 78 HttpHeaders headers = resp.getHeaders();
79 79 //特别声明:响应体改变必须设置contentLength,且长度要保持一致,(经过测试,如果过短则会截断,过长则会导致超时。)
80 80 headers.setContentLength(respBody.getBytes(StandardCharsets.UTF_8).length);
... ... @@ -127,7 +127,6 @@ public class ResponseReadBodyGlobalFilter implements GlobalFilter, Ordered {
127 127  
128 128 /**
129 129 * 默认body拦截处理器
130   - *
131 130 */
132 131 private BodyHandlerServerHttpResponseDecorator.BodyHandlerFunction initDefaultBodyHandler() {
133 132 return ReactiveHttpOutputMessage::writeWith;
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/filters/web/FacadeWebFilter.java
... ... @@ -79,7 +79,7 @@ public class FacadeWebFilter implements WebFilter {
79 79 } else if (ex instanceof GatewayParamNotValidException) {
80 80 return Message.failure(
81 81 ErrorCode.ILLEGAL_PARAMS.getCode(), ex.getMessage());
82   - } else if (ex instanceof TimeoutException){
  82 + } else if (ex instanceof TimeoutException) {
83 83 log.error("api处理超时:", ex);
84 84 return Message.failure(
85 85 ErrorCode.UNKNOWN_ERROR.getCode(), "请求超时");
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/predicates/ReadBodyRoutePredicateFactory.java
... ... @@ -19,7 +19,6 @@ import java.util.List;
19 19 import java.util.function.Predicate;
20 20  
21 21  
22   -
23 22 /**
24 23 * @Auther: miaoguoxin
25 24 * @Date: 2019/3/25 0025 10:47
... ... @@ -48,7 +47,7 @@ public class ReadBodyRoutePredicateFactory extends AbstractRoutePredicateFactory
48 47 return exchange -> {
49 48 ServerHttpRequest request = exchange.getRequest();
50 49 HttpHeaders headers = request.getHeaders();
51   - log.info("请求headers:{}",headers);
  50 + log.info("请求headers:{}", headers);
52 51 String rawPath = request.getURI().getRawPath();
53 52 //兼容没有content-type的情况
54 53 String contentTypeStr = headers.getFirst("Content-Type");
... ... @@ -60,7 +59,7 @@ public class ReadBodyRoutePredicateFactory extends AbstractRoutePredicateFactory
60 59 if (contentTypeStr.startsWith("multipart/form-data")) {
61 60 return Mono.just(Boolean.TRUE);
62 61 }
63   - // String cachedBody = exchange.getAttribute(CACHE_REQUEST_BODY_OBJECT_KEY);
  62 + // String cachedBody = exchange.getAttribute(CACHE_REQUEST_BODY_OBJECT_KEY);
64 63 // BodyInserter bodyInserter = BodyInserters.fromPublisher(modifiedBody, String.class);
65 64 // //因为请求体可能是null,这里自定义个缓存输出
66 65 // CustomCacheBodyOutputMessage outputMessage = new CustomCacheBodyOutputMessage(exchange, headers);
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/repository/GatewayRepository.java
... ... @@ -20,7 +20,6 @@ import org.springframework.cloud.gateway.route.RouteDefinition;
20 20 import org.springframework.stereotype.Repository;
21 21 import org.springframework.util.CollectionUtils;
22 22 import org.springframework.web.util.UriComponentsBuilder;
23   -import reactor.core.publisher.Mono;
24 23  
25 24 import java.lang.reflect.InvocationTargetException;
26 25 import java.net.URI;
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/repository/IGatewayRepository.java
... ... @@ -11,12 +11,12 @@ import java.util.List;
11 11 */
12 12 public interface IGatewayRepository {
13 13 /**
14   - * 获取所有路由资源配置
15   - * @param
16   - * @return
17   - * @author miaoguoxin
18   - * @date 2020/4/10
19   - */
  14 + * 获取所有路由资源配置
  15 + * @param
  16 + * @return
  17 + * @author miaoguoxin
  18 + * @date 2020/4/10
  19 + */
20 20 List<RouteDefinition> getAll();
21 21  
22 22 void addApiMetrics(List<ApiMetricsInfo> apiMetricsInfos);
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/repository/dao/ApiMetricsDao.java
1 1 package com.diligrp.xtrade.core.repository.dao;
2 2  
3 3 import com.diligrp.xtrade.core.repository.entity.ApiMetricsInfoEntity;
4   -import org.apache.ibatis.annotations.Param;
  4 +
5 5 import java.util.List;
6 6  
7 7 /**
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/repository/entity/GatewayAttrConfig.java
... ... @@ -8,7 +8,7 @@ import com.diligrp.xtrade.shared.domain.BaseDo;
8 8 * @Date: 2018/12/12 0012 17:43
9 9 * @Description: 网关断言和过滤器配置实体
10 10 */
11   -public class GatewayAttrConfig extends BaseDo{
  11 +public class GatewayAttrConfig extends BaseDo {
12 12 /**服务id名称*/
13 13 private String serviceId;
14 14 /**类型 {@link GatewayAttrType}*/
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/route/impl/CloudRouteResourceLoader.java
... ... @@ -107,7 +107,7 @@ public class CloudRouteResourceLoader implements DynamicRouteLoaderIntf {
107 107  
108 108  
109 109 private void notifyRefreshRoutes() {
110   - synchronized (CloudRouteResourceLoader.this){
  110 + synchronized (CloudRouteResourceLoader.this) {
111 111 if (gatewayPropertiesHash == gatewayProperties.getRoutes().hashCode()) {
112 112 return;
113 113 }
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/route/impl/MysqlRouteResourceLoader.java
... ... @@ -41,7 +41,7 @@ public class MysqlRouteResourceLoader implements DynamicRouteLoaderIntf {
41 41 }
42 42  
43 43 @Override
44   - public void refreshApis(){
  44 + public void refreshApis() {
45 45  
46 46 }
47 47  
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/support/ApiMetricsCollector.java
... ... @@ -2,7 +2,6 @@ package com.diligrp.xtrade.core.support;
2 2  
3 3 import com.diligrp.xtrade.core.config.property.ApiMetricsProperties;
4 4 import com.diligrp.xtrade.core.repository.IGatewayRepository;
5   -import com.diligrp.xtrade.shared.util.JsonUtils;
6 5 import com.google.common.collect.Queues;
7 6 import org.slf4j.Logger;
8 7 import org.slf4j.LoggerFactory;
... ... @@ -16,8 +15,6 @@ import java.util.Timer;
16 15 import java.util.TimerTask;
17 16 import java.util.concurrent.ArrayBlockingQueue;
18 17 import java.util.concurrent.BlockingQueue;
19   -import java.util.concurrent.Executors;
20   -import java.util.concurrent.TimeUnit;
21 18 import java.util.concurrent.atomic.AtomicBoolean;
22 19  
23 20 /**
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/support/context/ReactiveExchangeContextHolder.java
... ... @@ -11,15 +11,15 @@ public class ReactiveExchangeContextHolder {
11 11 /**让该变量可以在父子线程间传递*/
12 12 private static final ThreadLocal<ServerWebExchange> REQUEST_THREAD_LOCAL = new InheritableThreadLocal<>();
13 13  
14   - public static void put(ServerWebExchange exchange){
  14 + public static void put(ServerWebExchange exchange) {
15 15 REQUEST_THREAD_LOCAL.set(exchange);
16 16 }
17 17  
18   - public static ServerWebExchange get(){
  18 + public static ServerWebExchange get() {
19 19 return REQUEST_THREAD_LOCAL.get();
20 20 }
21 21  
22   - public static void remove(){
  22 + public static void remove() {
23 23 REQUEST_THREAD_LOCAL.remove();
24 24 }
25 25 }
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/support/context/ReactiveWebContextBeanProcessor.java
... ... @@ -19,8 +19,8 @@ public class ReactiveWebContextBeanProcessor implements BeanFactoryPostProcessor
19 19  
20 20 @Override
21 21 public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
22   - beanFactory.registerResolvableDependency(ServerHttpRequest.class,new ReactiveRequestObjectFactory());
23   - beanFactory.registerResolvableDependency(ServerHttpResponse.class,new ReactiveResponseObjectFactory());
  22 + beanFactory.registerResolvableDependency(ServerHttpRequest.class, new ReactiveRequestObjectFactory());
  23 + beanFactory.registerResolvableDependency(ServerHttpResponse.class, new ReactiveResponseObjectFactory());
24 24 }
25 25  
26 26 private static class ReactiveRequestObjectFactory implements ObjectFactory<ServerHttpRequest>, Serializable {
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/support/dispatch/MappingRegister.java
... ... @@ -17,7 +17,6 @@ import org.springframework.boot.SpringApplication;
17 17 import org.springframework.context.ApplicationContext;
18 18 import org.springframework.context.ApplicationListener;
19 19 import org.springframework.context.event.ContextRefreshedEvent;
20   -import org.springframework.lang.NonNullApi;
21 20 import org.springframework.stereotype.Component;
22 21 import org.springframework.validation.annotation.Validated;
23 22  
... ...
gateway-core/src/main/java/com/diligrp/xtrade/core/support/dispatch/package-info.java 0 → 100644
  1 +/**
  2 + * @Auther: miaoguoxin
  3 + * @Date: 2018/12/8 12:47
  4 + * @Description:类名一定要为filterName + GatewayFilterFactory,如定义为JwtCheckGatewayFilterFactory的话,它的filterName就是JwtCheck
  5 + */
  6 +package com.diligrp.xtrade.core.support.dispatch;
... ...