新增请求头,请求参数配置
This commit is contained in:
parent
25d7d1668b
commit
00046d5bc9
@ -0,0 +1,22 @@
|
|||||||
|
package ink.wgink.gateway.dao.route.request;
|
||||||
|
|
||||||
|
import ink.wgink.gateway.pojo.route.request.RequestHeader;
|
||||||
|
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When you feel like quitting. Think about why you started
|
||||||
|
* 当你想要放弃的时候,想想当初你为何开始
|
||||||
|
*
|
||||||
|
* @ClassName: IRequestHeaderDao
|
||||||
|
* @Description: 请求头
|
||||||
|
* @Author: WangGeng
|
||||||
|
* @Date: 2021/5/29 22:21
|
||||||
|
* @Version: 1.0
|
||||||
|
**/
|
||||||
|
@Repository
|
||||||
|
public interface IRequestHeaderDao extends ReactiveMongoRepository<RequestHeader, String> {
|
||||||
|
|
||||||
|
String COLLECTION_NAME = "sys_request_header";
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package ink.wgink.gateway.dao.route.request;
|
||||||
|
|
||||||
|
import ink.wgink.gateway.pojo.route.request.RequestHeader;
|
||||||
|
import ink.wgink.gateway.pojo.route.request.RequestParameter;
|
||||||
|
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When you feel like quitting. Think about why you started
|
||||||
|
* 当你想要放弃的时候,想想当初你为何开始
|
||||||
|
*
|
||||||
|
* @ClassName: IRequestParameterDao
|
||||||
|
* @Description: 请求参数
|
||||||
|
* @Author: WangGeng
|
||||||
|
* @Date: 2021/5/29 22:33
|
||||||
|
* @Version: 1.0
|
||||||
|
**/
|
||||||
|
@Repository
|
||||||
|
public interface IRequestParameterDao extends ReactiveMongoRepository<RequestParameter, String> {
|
||||||
|
|
||||||
|
String COLLECTION_NAME = "sys_request_parameter";
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package ink.wgink.gateway.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When you feel like quitting. Think about why you started
|
||||||
|
* 当你想要放弃的时候,想想当初你为何开始
|
||||||
|
*
|
||||||
|
* @ClassName: FilterRequestTypeEnum
|
||||||
|
* @Description: 请求过滤器类型
|
||||||
|
* @Author: WangGeng
|
||||||
|
* @Date: 2021/5/30 16:54
|
||||||
|
* @Version: 1.0
|
||||||
|
**/
|
||||||
|
public enum FilterRequestTypeEnum {
|
||||||
|
ADD("add", "添加"),
|
||||||
|
SET("set", "设置");
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
private String summary;
|
||||||
|
|
||||||
|
FilterRequestTypeEnum(String value, String summary) {
|
||||||
|
this.value = value;
|
||||||
|
this.summary = summary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSummary() {
|
||||||
|
return summary;
|
||||||
|
}
|
||||||
|
}
|
@ -2,13 +2,15 @@ package ink.wgink.gateway.filter.local;
|
|||||||
|
|
||||||
import ink.wgink.gateway.consts.ISystemConst;
|
import ink.wgink.gateway.consts.ISystemConst;
|
||||||
import ink.wgink.gateway.pojo.route.Route;
|
import ink.wgink.gateway.pojo.route.Route;
|
||||||
|
import ink.wgink.gateway.pojo.route.request.RequestHeader;
|
||||||
|
import ink.wgink.gateway.pojo.route.request.RequestParameter;
|
||||||
import org.springframework.cloud.gateway.filter.FilterDefinition;
|
import org.springframework.cloud.gateway.filter.FilterDefinition;
|
||||||
import org.springframework.cloud.gateway.filter.factory.RewriteLocationResponseHeaderGatewayFilterFactory;
|
import org.springframework.cloud.gateway.filter.factory.RewriteLocationResponseHeaderGatewayFilterFactory;
|
||||||
import org.springframework.cloud.gateway.filter.factory.RewritePathGatewayFilterFactory;
|
import org.springframework.cloud.gateway.filter.factory.RewritePathGatewayFilterFactory;
|
||||||
import org.springframework.cloud.gateway.filter.factory.RewriteResponseHeaderGatewayFilterFactory;
|
|
||||||
import org.springframework.cloud.gateway.filter.factory.SetPathGatewayFilterFactory;
|
import org.springframework.cloud.gateway.filter.factory.SetPathGatewayFilterFactory;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,6 +25,43 @@ import java.util.Map;
|
|||||||
**/
|
**/
|
||||||
public class CommonFiltersDefinition {
|
public class CommonFiltersDefinition {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求头参数过滤器
|
||||||
|
*
|
||||||
|
* @param route
|
||||||
|
* @param requestHeaders
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public FilterDefinition addRequestHeader(List<RequestHeader> requestHeaders) {
|
||||||
|
FilterDefinition addRequestHeader = new FilterDefinition();
|
||||||
|
Map<String, String> addRequestHeaderMap = new HashMap<>(requestHeaders.size() * 2);
|
||||||
|
for (RequestHeader requestHeader : requestHeaders) {
|
||||||
|
addRequestHeaderMap.put("name", requestHeader.getName());
|
||||||
|
addRequestHeaderMap.put("value", requestHeader.getValue());
|
||||||
|
}
|
||||||
|
addRequestHeader.setArgs(addRequestHeaderMap);
|
||||||
|
addRequestHeader.setName("AddRequestHeader");
|
||||||
|
return addRequestHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求参数过滤器
|
||||||
|
*
|
||||||
|
* @param requestParameters
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public FilterDefinition addRequestParameter(List<RequestParameter> requestParameters) {
|
||||||
|
FilterDefinition addRequestParameter = new FilterDefinition();
|
||||||
|
Map<String, String> addRequestParameterMap = new HashMap<>(requestParameters.size() * 2);
|
||||||
|
for (RequestParameter requestParameter : requestParameters) {
|
||||||
|
addRequestParameterMap.put("name", requestParameter.getName());
|
||||||
|
addRequestParameterMap.put("value", requestParameter.getValue());
|
||||||
|
}
|
||||||
|
addRequestParameter.setArgs(addRequestParameterMap);
|
||||||
|
addRequestParameter.setName("AddRequestParameter");
|
||||||
|
return addRequestParameter;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重写过滤器,将路径中的gw删除,暂时无用
|
* 重写过滤器,将路径中的gw删除,暂时无用
|
||||||
*
|
*
|
||||||
@ -69,4 +108,5 @@ public class CommonFiltersDefinition {
|
|||||||
return rewriteLocationResponse;
|
return rewriteLocationResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,137 @@
|
|||||||
|
package ink.wgink.gateway.handler.route.request;
|
||||||
|
|
||||||
|
import ink.wgink.gateway.dao.route.request.IRequestHeaderDao;
|
||||||
|
import ink.wgink.gateway.exception.SearchException;
|
||||||
|
import ink.wgink.gateway.handler.BaseHandler;
|
||||||
|
import ink.wgink.gateway.pojo.result.SuccessResult;
|
||||||
|
import ink.wgink.gateway.pojo.route.request.RequestHeader;
|
||||||
|
import ink.wgink.gateway.pojo.route.request.RequestParameter;
|
||||||
|
import ink.wgink.gateway.pojo.routetype.RouteType;
|
||||||
|
import ink.wgink.gateway.util.RequestFieldCheckUtil;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.data.domain.Example;
|
||||||
|
import org.springframework.data.domain.ExampleMatcher;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||||
|
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||||
|
import reactor.core.publisher.Flux;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When you feel like quitting. Think about why you started
|
||||||
|
* 当你想要放弃的时候,想想当初你为何开始
|
||||||
|
*
|
||||||
|
* @ClassName: RequestHeaderHandler
|
||||||
|
* @Description: 请求头处理
|
||||||
|
* @Author: WangGeng
|
||||||
|
* @Date: 2021/5/30 17:00
|
||||||
|
* @Version: 1.0
|
||||||
|
**/
|
||||||
|
@Service
|
||||||
|
public class RequestHeaderHandler extends BaseHandler {
|
||||||
|
|
||||||
|
private IRequestHeaderDao requestHeaderDao;
|
||||||
|
|
||||||
|
public RequestHeaderHandler(IRequestHeaderDao requestHeaderDao) {
|
||||||
|
this.requestHeaderDao = requestHeaderDao;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mono<ServerResponse> save(ServerRequest serverRequest) {
|
||||||
|
Mono<RequestHeader> requestHeaderMono = serverRequest.bodyToMono(RequestHeader.class);
|
||||||
|
return requestHeaderMono.flatMap(requestHeader -> {
|
||||||
|
RequestFieldCheckUtil.check(requestHeader);
|
||||||
|
setSave(requestHeader);
|
||||||
|
|
||||||
|
RouteType routeTypeExample = new RouteType();
|
||||||
|
routeTypeExample.setTitle(requestHeader.getName().trim());
|
||||||
|
ExampleMatcher exampleMatcher = ExampleMatcher.matching().withMatcher("name", ExampleMatcher.GenericPropertyMatcher::exact).withIgnoreCase("id");
|
||||||
|
Example example = Example.of(routeTypeExample, exampleMatcher);
|
||||||
|
return requestHeaderDao.findOne(example).flatMap(
|
||||||
|
r -> Mono.error(new SearchException("Header已经存在"))
|
||||||
|
).switchIfEmpty(requestHeaderDao.save(requestHeader));
|
||||||
|
}).then(ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8).body(Flux.just(new SuccessResult()), SuccessResult.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mono<ServerResponse> delete(ServerRequest serverRequest) {
|
||||||
|
String ids = serverRequest.pathVariable("ids");
|
||||||
|
List<String> idList = Arrays.asList(ids.split(","));
|
||||||
|
return requestHeaderDao.findAllById(idList).flatMap(requestHeader -> requestHeaderDao.delete(requestHeader)).then(ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8).body(Mono.just(new SuccessResult()), SuccessResult.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mono<ServerResponse> update(ServerRequest serverRequest) {
|
||||||
|
String id = serverRequest.pathVariable("id");
|
||||||
|
Mono<RequestHeader> requestHeaderMono = serverRequest.bodyToMono(RequestHeader.class);
|
||||||
|
|
||||||
|
// 查询ID是否存在
|
||||||
|
return requestHeaderDao.findById(id).flatMap(requestHeader -> {
|
||||||
|
setUpdate(requestHeader);
|
||||||
|
return requestHeaderMono.flatMap(rh -> {
|
||||||
|
RequestFieldCheckUtil.check(rh);
|
||||||
|
requestHeader.setRouteId(rh.getRouteId());
|
||||||
|
requestHeader.setType(rh.getType());
|
||||||
|
requestHeader.setName(rh.getName());
|
||||||
|
requestHeader.setValue(rh.getValue());
|
||||||
|
|
||||||
|
RequestHeader requestHeaderExample = new RequestHeader();
|
||||||
|
requestHeaderExample.setRouteId(rh.getRouteId());
|
||||||
|
requestHeaderExample.setName(rh.getName());
|
||||||
|
ExampleMatcher exampleMatcher = ExampleMatcher.matching()
|
||||||
|
.withMatcher("routeId", ExampleMatcher.GenericPropertyMatcher::exact)
|
||||||
|
.withMatcher("name", ExampleMatcher.GenericPropertyMatcher::exact)
|
||||||
|
.withIgnoreCase("id");
|
||||||
|
Example example = Example.of(requestHeaderExample, exampleMatcher);
|
||||||
|
// 查询Name是否存在
|
||||||
|
return requestHeaderDao.findOne(example).flatMap(erh -> {
|
||||||
|
RequestHeader existRouteHeader = (RequestHeader) erh;
|
||||||
|
// 如果已经存在
|
||||||
|
if (!StringUtils.equals(existRouteHeader.getUuid(), id)) {
|
||||||
|
return Mono.error(new SearchException("参数已经存在"));
|
||||||
|
}
|
||||||
|
return requestHeaderDao.save(requestHeader);
|
||||||
|
}).switchIfEmpty(requestHeaderDao.save(requestHeader));
|
||||||
|
});
|
||||||
|
}).switchIfEmpty(ServerResponse.notFound().build()).then(ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8).body(Mono.just(new SuccessResult()), SuccessResult.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mono<ServerResponse> list(ServerRequest serverRequest) {
|
||||||
|
String routeId = serverRequest.pathVariable("routeId");
|
||||||
|
Optional<String> keywords = serverRequest.queryParam("keywords");
|
||||||
|
Optional<String> type = serverRequest.queryParam("type");
|
||||||
|
|
||||||
|
RequestParameter requestParameter = new RequestParameter();
|
||||||
|
requestParameter.setRouteId(routeId);
|
||||||
|
|
||||||
|
ExampleMatcher exampleMatcher = ExampleMatcher.matching()
|
||||||
|
.withMatcher("routeId", ExampleMatcher.GenericPropertyMatcher::exact)
|
||||||
|
.withIgnoreCase("id");
|
||||||
|
if (keywords.isPresent() || type.isPresent()) {
|
||||||
|
String keywordTrim = keywords.get().trim();
|
||||||
|
String typeTrim = type.get().trim();
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(keywordTrim)) {
|
||||||
|
requestParameter.setName(keywordTrim);
|
||||||
|
exampleMatcher.withMatcher("name", ExampleMatcher.GenericPropertyMatcher::contains);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(typeTrim)) {
|
||||||
|
requestParameter.setType(typeTrim);
|
||||||
|
exampleMatcher.withMatcher("type", ExampleMatcher.GenericPropertyMatcher::exact);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Example example = Example.of(requestParameter, exampleMatcher);
|
||||||
|
return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8).body(requestHeaderDao.findAll(example), RequestHeader.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mono<ServerResponse> get(ServerRequest serverRequest) {
|
||||||
|
String id = serverRequest.pathVariable("id");
|
||||||
|
return requestHeaderDao.findById(id).flatMap(
|
||||||
|
requestHeader -> ServerResponse.ok().body(Mono.just(requestHeader), RequestHeader.class)
|
||||||
|
).switchIfEmpty(ServerResponse.notFound().build());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,136 @@
|
|||||||
|
package ink.wgink.gateway.handler.route.request;
|
||||||
|
|
||||||
|
import ink.wgink.gateway.dao.route.request.IRequestParameterDao;
|
||||||
|
import ink.wgink.gateway.exception.SearchException;
|
||||||
|
import ink.wgink.gateway.handler.BaseHandler;
|
||||||
|
import ink.wgink.gateway.pojo.result.SuccessResult;
|
||||||
|
import ink.wgink.gateway.pojo.route.request.RequestHeader;
|
||||||
|
import ink.wgink.gateway.pojo.route.request.RequestParameter;
|
||||||
|
import ink.wgink.gateway.pojo.routetype.RouteType;
|
||||||
|
import ink.wgink.gateway.util.RequestFieldCheckUtil;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.data.domain.Example;
|
||||||
|
import org.springframework.data.domain.ExampleMatcher;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||||
|
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||||
|
import reactor.core.publisher.Flux;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When you feel like quitting. Think about why you started
|
||||||
|
* 当你想要放弃的时候,想想当初你为何开始
|
||||||
|
*
|
||||||
|
* @ClassName: RequestParameterHeader
|
||||||
|
* @Description: 请求参数
|
||||||
|
* @Author: WangGeng
|
||||||
|
* @Date: 2021/5/30 17:00
|
||||||
|
* @Version: 1.0
|
||||||
|
**/
|
||||||
|
@Service
|
||||||
|
public class RequestParameterHandler extends BaseHandler {
|
||||||
|
|
||||||
|
private IRequestParameterDao requestParameterDao;
|
||||||
|
|
||||||
|
public RequestParameterHandler(IRequestParameterDao requestParameterDao) {
|
||||||
|
this.requestParameterDao = requestParameterDao;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mono<ServerResponse> save(ServerRequest serverRequest) {
|
||||||
|
Mono<RequestParameter> requestParameterMono = serverRequest.bodyToMono(RequestParameter.class);
|
||||||
|
return requestParameterMono.flatMap(requestParameter -> {
|
||||||
|
RequestFieldCheckUtil.check(requestParameter);
|
||||||
|
setSave(requestParameter);
|
||||||
|
|
||||||
|
RouteType routeTypeExample = new RouteType();
|
||||||
|
routeTypeExample.setTitle(requestParameter.getName().trim());
|
||||||
|
ExampleMatcher exampleMatcher = ExampleMatcher.matching().withMatcher("name", ExampleMatcher.GenericPropertyMatcher::exact).withIgnoreCase("id");
|
||||||
|
Example example = Example.of(routeTypeExample, exampleMatcher);
|
||||||
|
return requestParameterDao.findOne(example).flatMap(
|
||||||
|
r -> Mono.error(new SearchException("Parameter已经存在"))
|
||||||
|
).switchIfEmpty(requestParameterDao.save(requestParameter));
|
||||||
|
}).then(ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8).body(Flux.just(new SuccessResult()), SuccessResult.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mono<ServerResponse> delete(ServerRequest serverRequest) {
|
||||||
|
String ids = serverRequest.pathVariable("ids");
|
||||||
|
List<String> idList = Arrays.asList(ids.split(","));
|
||||||
|
return requestParameterDao.findAllById(idList).flatMap(requestParameter -> requestParameterDao.delete(requestParameter)).then(ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8).body(Mono.just(new SuccessResult()), SuccessResult.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mono<ServerResponse> update(ServerRequest serverRequest) {
|
||||||
|
String id = serverRequest.pathVariable("id");
|
||||||
|
Mono<RequestParameter> requestParameterMono = serverRequest.bodyToMono(RequestParameter.class);
|
||||||
|
|
||||||
|
// 查询ID是否存在
|
||||||
|
return requestParameterDao.findById(id).flatMap(requestParameter -> {
|
||||||
|
setUpdate(requestParameter);
|
||||||
|
return requestParameterMono.flatMap(rp -> {
|
||||||
|
RequestFieldCheckUtil.check(rp);
|
||||||
|
requestParameter.setRouteId(rp.getRouteId());
|
||||||
|
requestParameter.setType(rp.getType());
|
||||||
|
requestParameter.setName(rp.getName());
|
||||||
|
requestParameter.setValue(rp.getValue());
|
||||||
|
|
||||||
|
RequestHeader requestHeaderExample = new RequestHeader();
|
||||||
|
requestHeaderExample.setRouteId(rp.getRouteId());
|
||||||
|
requestHeaderExample.setName(rp.getName());
|
||||||
|
ExampleMatcher exampleMatcher = ExampleMatcher.matching()
|
||||||
|
.withMatcher("routeId", ExampleMatcher.GenericPropertyMatcher::exact)
|
||||||
|
.withMatcher("name", ExampleMatcher.GenericPropertyMatcher::exact)
|
||||||
|
.withIgnoreCase("id");
|
||||||
|
Example example = Example.of(requestHeaderExample, exampleMatcher);
|
||||||
|
// 查询Name是否存在
|
||||||
|
return requestParameterDao.findOne(example).flatMap(erp -> {
|
||||||
|
RequestParameter existRouteParameter = (RequestParameter) erp;
|
||||||
|
// 如果已经存在
|
||||||
|
if (!StringUtils.equals(existRouteParameter.getUuid(), id)) {
|
||||||
|
return Mono.error(new SearchException("参数已经存在"));
|
||||||
|
}
|
||||||
|
return requestParameterDao.save(requestParameter);
|
||||||
|
}).switchIfEmpty(requestParameterDao.save(requestParameter));
|
||||||
|
});
|
||||||
|
}).switchIfEmpty(ServerResponse.notFound().build()).then(ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8).body(Mono.just(new SuccessResult()), SuccessResult.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mono<ServerResponse> list(ServerRequest serverRequest) {
|
||||||
|
String routeId = serverRequest.pathVariable("routeId");
|
||||||
|
Optional<String> keywords = serverRequest.queryParam("keywords");
|
||||||
|
Optional<String> type = serverRequest.queryParam("type");
|
||||||
|
|
||||||
|
RequestParameter requestParameter = new RequestParameter();
|
||||||
|
requestParameter.setRouteId(routeId);
|
||||||
|
ExampleMatcher exampleMatcher = ExampleMatcher.matching()
|
||||||
|
.withMatcher("routeId", ExampleMatcher.GenericPropertyMatcher::exact)
|
||||||
|
.withIgnoreCase("id");
|
||||||
|
if (keywords.isPresent() || type.isPresent()) {
|
||||||
|
String keywordTrim = keywords.get().trim();
|
||||||
|
String typeTrim = type.get().trim();
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(keywordTrim)) {
|
||||||
|
requestParameter.setName(keywordTrim);
|
||||||
|
exampleMatcher.withMatcher("name", ExampleMatcher.GenericPropertyMatcher::contains);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(typeTrim)) {
|
||||||
|
requestParameter.setType(typeTrim);
|
||||||
|
exampleMatcher.withMatcher("type", ExampleMatcher.GenericPropertyMatcher::exact);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Example example = Example.of(requestParameter, exampleMatcher);
|
||||||
|
return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8).body(requestParameterDao.findAll(example), RequestParameter.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mono<ServerResponse> get(ServerRequest serverRequest) {
|
||||||
|
String id = serverRequest.pathVariable("id");
|
||||||
|
return requestParameterDao.findById(id).flatMap(
|
||||||
|
requestParameter -> ServerResponse.ok().body(Mono.just(requestParameter), RequestParameter.class)
|
||||||
|
).switchIfEmpty(ServerResponse.notFound().build());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
package ink.wgink.gateway.pojo.route.request;
|
||||||
|
|
||||||
|
import ink.wgink.gateway.annoation.CheckEmptyAnnotation;
|
||||||
|
import ink.wgink.gateway.annoation.CheckNumberAnnotation;
|
||||||
|
import ink.wgink.gateway.dao.route.request.IRequestHeaderDao;
|
||||||
|
import ink.wgink.gateway.pojo.BasePOJO;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When you feel like quitting. Think about why you started
|
||||||
|
* 当你想要放弃的时候,想想当初你为何开始
|
||||||
|
*
|
||||||
|
* @ClassName: RequestHeader
|
||||||
|
* @Description: 请求头
|
||||||
|
* @Author: WangGeng
|
||||||
|
* @Date: 2021/5/29 22:20
|
||||||
|
* @Version: 1.0
|
||||||
|
**/
|
||||||
|
@Document(collection = IRequestHeaderDao.COLLECTION_NAME)
|
||||||
|
public class RequestHeader extends BasePOJO {
|
||||||
|
|
||||||
|
@CheckEmptyAnnotation(name = "路由ID")
|
||||||
|
private String routeId;
|
||||||
|
@CheckNumberAnnotation(name = "类型")
|
||||||
|
private String type;
|
||||||
|
@CheckEmptyAnnotation(name = "名称")
|
||||||
|
private String name;
|
||||||
|
@CheckEmptyAnnotation(name = "值")
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
public String getRouteId() {
|
||||||
|
return routeId == null ? "" : routeId.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRouteId(String routeId) {
|
||||||
|
this.routeId = routeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name == null ? "" : name.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type == null ? "" : type.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value == null ? "" : value.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
package ink.wgink.gateway.pojo.route.request;
|
||||||
|
|
||||||
|
import ink.wgink.gateway.annoation.CheckEmptyAnnotation;
|
||||||
|
import ink.wgink.gateway.dao.route.request.IRequestParameterDao;
|
||||||
|
import ink.wgink.gateway.pojo.BasePOJO;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When you feel like quitting. Think about why you started
|
||||||
|
* 当你想要放弃的时候,想想当初你为何开始
|
||||||
|
*
|
||||||
|
* @ClassName: RequestParameter
|
||||||
|
* @Description: 请求参数
|
||||||
|
* @Author: WangGeng
|
||||||
|
* @Date: 2021/5/29 22:32
|
||||||
|
* @Version: 1.0
|
||||||
|
**/
|
||||||
|
@Document(collection = IRequestParameterDao.COLLECTION_NAME)
|
||||||
|
public class RequestParameter extends BasePOJO {
|
||||||
|
|
||||||
|
@CheckEmptyAnnotation(name = "路由ID")
|
||||||
|
private String routeId;
|
||||||
|
@CheckEmptyAnnotation(name = "类型")
|
||||||
|
private String type;
|
||||||
|
@CheckEmptyAnnotation(name = "名称")
|
||||||
|
private String name;
|
||||||
|
@CheckEmptyAnnotation(name = "值")
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
public String getRouteId() {
|
||||||
|
return routeId == null ? "" : routeId.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type == null ? "" : type.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRouteId(String routeId) {
|
||||||
|
this.routeId = routeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name == null ? "" : name.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value == null ? "" : value.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package ink.wgink.gateway.router.route.request;
|
||||||
|
|
||||||
|
import ink.wgink.gateway.router.BaseRouter;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When you feel like quitting. Think about why you started
|
||||||
|
* 当你想要放弃的时候,想想当初你为何开始
|
||||||
|
*
|
||||||
|
* @ClassName: RequestHeaderRouter
|
||||||
|
* @Description: 请求头路由
|
||||||
|
* @Author: WangGeng
|
||||||
|
* @Date: 2021/5/30 17:07
|
||||||
|
* @Version: 1.0
|
||||||
|
**/
|
||||||
|
@Component
|
||||||
|
public class RequestHeaderRouter extends BaseRouter {
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package ink.wgink.gateway.router.route.request;
|
||||||
|
|
||||||
|
import ink.wgink.gateway.router.BaseRouter;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When you feel like quitting. Think about why you started
|
||||||
|
* 当你想要放弃的时候,想想当初你为何开始
|
||||||
|
*
|
||||||
|
* @ClassName: RequestParameterRouter
|
||||||
|
* @Description: 请求参数路由
|
||||||
|
* @Author: WangGeng
|
||||||
|
* @Date: 2021/5/30 17:08
|
||||||
|
* @Version: 1.0
|
||||||
|
**/
|
||||||
|
@Component
|
||||||
|
public class RequestParameterRouter extends BaseRouter {
|
||||||
|
}
|
@ -10,9 +10,9 @@ spring:
|
|||||||
use-insecure-trust-manager: true
|
use-insecure-trust-manager: true
|
||||||
data:
|
data:
|
||||||
mongodb:
|
mongodb:
|
||||||
uri: mongodb://127.0.0.1:27017/gateway
|
uri: mongodb://192.168.0.151:27017/gateway
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
org.springframework: debug
|
org.springframework: error
|
||||||
ink.wgink: debug
|
ink.wgink: debug
|
Loading…
Reference in New Issue
Block a user