Commit f966b5553cf300b944848cd5d8b929a713333d24
1 parent
e46dab0f
一些错误修改
Showing
10 changed files
with
17 additions
and
31 deletions
gateway-business/src/main/java/com/diligrp/xtrade/business/XtradeGatewayApplication.java
1 | package com.diligrp.xtrade.business; | 1 | package com.diligrp.xtrade.business; |
2 | 2 | ||
3 | -import io.netty.util.ResourceLeakDetector; | ||
4 | import org.mybatis.spring.annotation.MapperScan; | 3 | import org.mybatis.spring.annotation.MapperScan; |
5 | import org.springframework.boot.SpringApplication; | 4 | import org.springframework.boot.SpringApplication; |
6 | import org.springframework.boot.autoconfigure.SpringBootApplication; | 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
gateway-core/src/main/java/com/diligrp/xtrade/core/common/utils/ResponseUtils.java
@@ -18,7 +18,7 @@ public class ResponseUtils { | @@ -18,7 +18,7 @@ public class ResponseUtils { | ||
18 | 18 | ||
19 | 19 | ||
20 | public static Mono<Void> writeForbidden(ServerHttpResponse response){ | 20 | public static Mono<Void> writeForbidden(ServerHttpResponse response){ |
21 | - Message<Object> message = Message.builder().failure( | 21 | + Message message = Message.failure( |
22 | HttpStatus.FORBIDDEN.value(),HttpStatus.FORBIDDEN.toString()); | 22 | HttpStatus.FORBIDDEN.value(),HttpStatus.FORBIDDEN.toString()); |
23 | return writeResponse(response,message); | 23 | return writeResponse(response,message); |
24 | } | 24 | } |
gateway-core/src/main/java/com/diligrp/xtrade/core/filters/global/AuthGlobalFilter.java
@@ -36,22 +36,20 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered { | @@ -36,22 +36,20 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered { | ||
36 | //排除在外的Uri跳过权限 | 36 | //排除在外的Uri跳过权限 |
37 | if (apiManager.isExcludePathMatch(originalUri)) { | 37 | if (apiManager.isExcludePathMatch(originalUri)) { |
38 | return chain.filter(exchange); | 38 | return chain.filter(exchange); |
39 | - // throw new RuntimeException("异常测试"); | ||
40 | } | 39 | } |
41 | exchange.getAttributes().put(ServerWebExchangeUtils.ORIGINAL_RESPONSE_CONTENT_TYPE_ATTR, MediaType.APPLICATION_JSON_VALUE); | 40 | exchange.getAttributes().put(ServerWebExchangeUtils.ORIGINAL_RESPONSE_CONTENT_TYPE_ATTR, MediaType.APPLICATION_JSON_VALUE); |
42 | return ResponseUtils.writeForbidden(response); | 41 | return ResponseUtils.writeForbidden(response); |
43 | } | 42 | } |
44 | 43 | ||
44 | + @Override | ||
45 | + public int getOrder() { | ||
46 | + return GatewayConst.AUTH_FILTER_ORDER; | ||
47 | + } | ||
48 | + | ||
45 | private static String getOriginalUri(ServerWebExchange exchange) { | 49 | private static String getOriginalUri(ServerWebExchange exchange) { |
46 | LinkedHashSet<URI> uris = exchange.getAttribute(ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR); | 50 | LinkedHashSet<URI> uris = exchange.getAttribute(ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR); |
47 | return Optional.ofNullable(uris) | 51 | return Optional.ofNullable(uris) |
48 | .flatMap(us -> us.stream().findFirst().map(URI::getRawPath)) | 52 | .flatMap(us -> us.stream().findFirst().map(URI::getRawPath)) |
49 | .orElse(exchange.getRequest().getURI().getRawPath()); | 53 | .orElse(exchange.getRequest().getURI().getRawPath()); |
50 | } | 54 | } |
51 | - | ||
52 | - @Override | ||
53 | - public int getOrder() { | ||
54 | - return GatewayConst.AUTH_FILTER_ORDER; | ||
55 | - } | ||
56 | - | ||
57 | } | 55 | } |
gateway-core/src/main/java/com/diligrp/xtrade/core/filters/global/CacheRequestBodyGlobalFilter.java
1 | package com.diligrp.xtrade.core.filters.global; | 1 | package com.diligrp.xtrade.core.filters.global; |
2 | 2 | ||
3 | import com.diligrp.xtrade.core.common.constant.GatewayConst; | 3 | import com.diligrp.xtrade.core.common.constant.GatewayConst; |
4 | +import com.diligrp.xtrade.shared.util.JsonUtils; | ||
4 | import org.apache.commons.lang3.StringUtils; | 5 | import org.apache.commons.lang3.StringUtils; |
5 | import org.springframework.cloud.gateway.filter.GatewayFilterChain; | 6 | import org.springframework.cloud.gateway.filter.GatewayFilterChain; |
6 | import org.springframework.cloud.gateway.filter.GlobalFilter; | 7 | import org.springframework.cloud.gateway.filter.GlobalFilter; |
@@ -40,7 +41,7 @@ public class CacheRequestBodyGlobalFilter implements GlobalFilter, Ordered { | @@ -40,7 +41,7 @@ public class CacheRequestBodyGlobalFilter implements GlobalFilter, Ordered { | ||
40 | @Override | 41 | @Override |
41 | public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { | 42 | public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { |
42 | String contentType = exchange.getRequest().getHeaders().getFirst(HttpHeaders.CONTENT_TYPE); | 43 | String contentType = exchange.getRequest().getHeaders().getFirst(HttpHeaders.CONTENT_TYPE); |
43 | - if (StringUtils.isNotBlank(contentType) && contentType.startsWith("multipart")) { | 44 | + if (StringUtils.isNotBlank(contentType) && contentType.contains("multipart")) { |
44 | return chain.filter(exchange); | 45 | return chain.filter(exchange); |
45 | } | 46 | } |
46 | ServerRequest serverRequest = ServerRequest.create(exchange, | 47 | ServerRequest serverRequest = ServerRequest.create(exchange, |
gateway-core/src/main/java/com/diligrp/xtrade/core/filters/web/FacadeWebFilter.java
@@ -63,29 +63,29 @@ public class FacadeWebFilter implements WebFilter { | @@ -63,29 +63,29 @@ public class FacadeWebFilter implements WebFilter { | ||
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | - private static Message<Object> handleException(Throwable ex) { | 66 | + private static Message handleException(Throwable ex) { |
67 | if (ex instanceof GatewayDispatchException) { | 67 | if (ex instanceof GatewayDispatchException) { |
68 | GatewayDispatchException dispatchEx = (GatewayDispatchException) ex; | 68 | GatewayDispatchException dispatchEx = (GatewayDispatchException) ex; |
69 | if (dispatchEx.getCause() != null) { | 69 | if (dispatchEx.getCause() != null) { |
70 | return handleException(dispatchEx.getCause()); | 70 | return handleException(dispatchEx.getCause()); |
71 | } else { | 71 | } else { |
72 | - return Message.builder().failure( | 72 | + return Message.failure( |
73 | ErrorCode.UNKNOWN_ERROR.getCode(), ErrorCode.UNKNOWN_ERROR.getName()); | 73 | ErrorCode.UNKNOWN_ERROR.getCode(), ErrorCode.UNKNOWN_ERROR.getName()); |
74 | } | 74 | } |
75 | } else if (ex instanceof ResponseStatusException) { | 75 | } else if (ex instanceof ResponseStatusException) { |
76 | ResponseStatusException statusException = (ResponseStatusException) ex; | 76 | ResponseStatusException statusException = (ResponseStatusException) ex; |
77 | log.warn("response status error:{}", statusException.getMessage()); | 77 | log.warn("response status error:{}", statusException.getMessage()); |
78 | - return Message.builder().failure(statusException.getStatus().value(), ex.getMessage()); | 78 | + return Message.failure(statusException.getStatus().value(), ex.getMessage()); |
79 | } else if (ex instanceof GatewayParamNotValidException) { | 79 | } else if (ex instanceof GatewayParamNotValidException) { |
80 | - return Message.builder().failure( | 80 | + return Message.failure( |
81 | ErrorCode.ILLEGAL_PARAMS.getCode(), ex.getMessage()); | 81 | ErrorCode.ILLEGAL_PARAMS.getCode(), ex.getMessage()); |
82 | } else if (ex instanceof TimeoutException){ | 82 | } else if (ex instanceof TimeoutException){ |
83 | log.error("api处理超时:", ex); | 83 | log.error("api处理超时:", ex); |
84 | - return Message.builder().failure( | 84 | + return Message.failure( |
85 | ErrorCode.UNKNOWN_ERROR.getCode(), "请求超时"); | 85 | ErrorCode.UNKNOWN_ERROR.getCode(), "请求超时"); |
86 | } else { | 86 | } else { |
87 | log.error("unknown error:", ex); | 87 | log.error("unknown error:", ex); |
88 | - return Message.builder().failure( | 88 | + return Message.failure( |
89 | ErrorCode.UNKNOWN_ERROR.getCode(), ErrorCode.UNKNOWN_ERROR.getName()); | 89 | ErrorCode.UNKNOWN_ERROR.getCode(), ErrorCode.UNKNOWN_ERROR.getName()); |
90 | } | 90 | } |
91 | } | 91 | } |
gateway-core/src/main/java/com/diligrp/xtrade/core/repository/entity/GatewayConfig.java
@@ -37,16 +37,6 @@ public class GatewayConfig extends BaseDo { | @@ -37,16 +37,6 @@ public class GatewayConfig extends BaseDo { | ||
37 | this.url = url; | 37 | this.url = url; |
38 | } | 38 | } |
39 | 39 | ||
40 | - @Override | ||
41 | - public Integer getIsDel() { | ||
42 | - return isDel; | ||
43 | - } | ||
44 | - | ||
45 | - @Override | ||
46 | - public void setIsDel(Integer isDel) { | ||
47 | - this.isDel = isDel; | ||
48 | - } | ||
49 | - | ||
50 | public String getDescription() { | 40 | public String getDescription() { |
51 | return description; | 41 | return description; |
52 | } | 42 | } |
gateway-core/src/main/java/com/diligrp/xtrade/core/support/dispatch/MappingRegister.java
@@ -50,7 +50,6 @@ public class MappingRegister implements ApplicationListener<ContextRefreshedEven | @@ -50,7 +50,6 @@ public class MappingRegister implements ApplicationListener<ContextRefreshedEven | ||
50 | .addScanners(new MethodAnnotationsScanner()) | 50 | .addScanners(new MethodAnnotationsScanner()) |
51 | .addScanners(new FieldAnnotationsScanner())); | 51 | .addScanners(new FieldAnnotationsScanner())); |
52 | try { | 52 | try { |
53 | - | ||
54 | Set<Method> methodMappings = reflections.getMethodsAnnotatedWith(DispatchMapping.class); | 53 | Set<Method> methodMappings = reflections.getMethodsAnnotatedWith(DispatchMapping.class); |
55 | for (Method method : methodMappings) { | 54 | for (Method method : methodMappings) { |
56 | //只扫描参数为DispatchContext的方法 | 55 | //只扫描参数为DispatchContext的方法 |
gateway-core/src/main/java/com/diligrp/xtrade/core/support/dispatch/RequestDispatcher.java
@@ -68,7 +68,7 @@ public class RequestDispatcher { | @@ -68,7 +68,7 @@ public class RequestDispatcher { | ||
68 | } | 68 | } |
69 | //分发逻辑 | 69 | //分发逻辑 |
70 | Object resultData = this.beginDispatch(matchUri, paramsJson, exchange); | 70 | Object resultData = this.beginDispatch(matchUri, paramsJson, exchange); |
71 | - return Message.builder().success(resultData); | 71 | + return Message.success(resultData); |
72 | } catch (Throwable e) { | 72 | } catch (Throwable e) { |
73 | throw new GatewayDispatchException("dispatch method error", e); | 73 | throw new GatewayDispatchException("dispatch method error", e); |
74 | } | 74 | } |
gateway-core/src/main/resources/mapper/AttrConfigDao.xml
1 | <?xml version="1.0" encoding="UTF-8" ?> | 1 | <?xml version="1.0" encoding="UTF-8" ?> |
2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > | 2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
3 | -<mapper namespace="com.diligrp.xtrade.gateway.repository.dao.AttrConfigDao"> | 3 | +<mapper namespace="com.diligrp.xtrade.core.repository.dao.AttrConfigDao"> |
4 | <resultMap id="Base_Result_Map" type="com.diligrp.xtrade.core.repository.entity.GatewayAttrConfig"> | 4 | <resultMap id="Base_Result_Map" type="com.diligrp.xtrade.core.repository.entity.GatewayAttrConfig"> |
5 | <id property="id" column="id"/> | 5 | <id property="id" column="id"/> |
6 | <result property="serviceId" column="service_id"/> | 6 | <result property="serviceId" column="service_id"/> |
@@ -9,7 +9,6 @@ | @@ -9,7 +9,6 @@ | ||
9 | <result property="attrArgs" column="attr_args"/> | 9 | <result property="attrArgs" column="attr_args"/> |
10 | <result property="description" column="description"/> | 10 | <result property="description" column="description"/> |
11 | <result property="sortOrder" column="sort_order"/> | 11 | <result property="sortOrder" column="sort_order"/> |
12 | - <result property="isDel" column="is_del"/> | ||
13 | <result property="modifiedTime" column="modified_time"/> | 12 | <result property="modifiedTime" column="modified_time"/> |
14 | <result property="createdTime" column="created_time"/> | 13 | <result property="createdTime" column="created_time"/> |
15 | </resultMap> | 14 | </resultMap> |
gateway-core/src/main/resources/mapper/RouteDao.xml
1 | <?xml version="1.0" encoding="UTF-8" ?> | 1 | <?xml version="1.0" encoding="UTF-8" ?> |
2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > | 2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
3 | -<mapper namespace="com.diligrp.xtrade.gateway.repository.dao.RouteDao"> | 3 | +<mapper namespace="com.diligrp.xtrade.core.repository.dao.RouteDao"> |
4 | <resultMap id="Base_Result_Map" type="com.diligrp.xtrade.core.repository.entity.GatewayConfig"> | 4 | <resultMap id="Base_Result_Map" type="com.diligrp.xtrade.core.repository.entity.GatewayConfig"> |
5 | <id property="id" column="id"/> | 5 | <id property="id" column="id"/> |
6 | <result property="url" column="url"/> | 6 | <result property="url" column="url"/> |