|
@@ -3,12 +3,12 @@ package com.diagbot.filter;
|
|
|
import com.diagbot.client.DiagbotmanServiceClient;
|
|
|
import com.diagbot.client.UserServiceClient;
|
|
|
import com.diagbot.dto.RespDTO;
|
|
|
-import com.diagbot.entity.ServiceFilter;
|
|
|
import com.diagbot.entity.ServiceToken;
|
|
|
import com.diagbot.util.GsonUtil;
|
|
|
-import com.diagbot.util.ListUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
|
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
|
|
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
|
|
import org.springframework.cloud.gateway.support.ServerWebExchangeUtils;
|
|
@@ -25,7 +25,6 @@ import java.nio.charset.StandardCharsets;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.LinkedHashSet;
|
|
|
-import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -34,6 +33,7 @@ import java.util.Map;
|
|
|
* @time: 2018/9/7 13:55
|
|
|
*/
|
|
|
@Configuration
|
|
|
+@RefreshScope
|
|
|
@Slf4j
|
|
|
public class GlobalGatewayFilter implements GlobalFilter {
|
|
|
|
|
@@ -41,6 +41,9 @@ public class GlobalGatewayFilter implements GlobalFilter {
|
|
|
private static Boolean IS_GENERATE = false;
|
|
|
private static Map<String, Long> SERVICE_FILTER = new HashMap<>();
|
|
|
|
|
|
+ @Value("${lantone.product}")
|
|
|
+ private String lantonePrduct;
|
|
|
+
|
|
|
@Autowired
|
|
|
UserServiceClient userServiceClient;
|
|
|
@Autowired
|
|
@@ -67,19 +70,21 @@ public class GlobalGatewayFilter implements GlobalFilter {
|
|
|
log.info("APIURL:{}", requestUri);
|
|
|
log.info("SERVICENAME:{}", serviceName);
|
|
|
|
|
|
- if(!IS_GENERATE) {
|
|
|
- RespDTO<List<ServiceFilter>> filter = diagbotmanServiceClient.getAll();
|
|
|
- if (filter != null){
|
|
|
- List<ServiceFilter> list = filter.data;
|
|
|
- if (ListUtil.isNotEmpty(list)){
|
|
|
- for(ServiceFilter bean : list) {
|
|
|
- SERVICE_FILTER.put(bean.getName(), bean.getProductId());
|
|
|
- }
|
|
|
- IS_GENERATE = true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if(SERVICE_FILTER.get(serviceName) != null) {
|
|
|
+// if(!IS_GENERATE) {
|
|
|
+// RespDTO<List<ServiceFilter>> filter = diagbotmanServiceClient.getAll();
|
|
|
+// if (filter != null){
|
|
|
+// List<ServiceFilter> list = filter.data;
|
|
|
+// if (ListUtil.isNotEmpty(list)){
|
|
|
+// for(ServiceFilter bean : list) {
|
|
|
+// SERVICE_FILTER.put(bean.getName(), bean.getProductId());
|
|
|
+// }
|
|
|
+// IS_GENERATE = true;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ Map<String, Long> serviceFilters = this.dealServiceFilter();
|
|
|
+ if(serviceFilters.get(serviceName) != null) {
|
|
|
String appkey = request.getHeaders().getFirst("appkey");
|
|
|
String secret = request.getHeaders().getFirst("secret");
|
|
|
Long productId = SERVICE_FILTER.get(serviceName);
|
|
@@ -114,4 +119,18 @@ public class GlobalGatewayFilter implements GlobalFilter {
|
|
|
DataBuffer buffer = serverWebExchange.getResponse().bufferFactory().wrap(bytes);
|
|
|
return serverWebExchange.getResponse().writeWith(Flux.just(buffer));
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理需要过滤的列表
|
|
|
+ * @return 过滤的列表
|
|
|
+ */
|
|
|
+ private Map<String, Long> dealServiceFilter(){
|
|
|
+ Map<String, Long> serviceFilters = new HashMap<>();
|
|
|
+ String[] set = lantonePrduct.split(";");
|
|
|
+ for (String s: set){
|
|
|
+ String[] d = s.split(",");
|
|
|
+ serviceFilters.put(d[0],Long.valueOf(d[1]));
|
|
|
+ }
|
|
|
+ return serviceFilters;
|
|
|
+ }
|
|
|
}
|