Commit 6c85ec69 authored by 周健威's avatar 周健威

屏蔽代码

parent c5618a58
...@@ -99,7 +99,7 @@ public class AccessGatewayFilter implements GlobalFilter { ...@@ -99,7 +99,7 @@ public class AccessGatewayFilter implements GlobalFilter {
log.info("check token and user permission...."); log.info("check token and user permission....");
LinkedHashSet requiredAttribute = serverWebExchange.getRequiredAttribute(ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR); LinkedHashSet requiredAttribute = serverWebExchange.getRequiredAttribute(ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR);
ServerHttpRequest request = serverWebExchange.getRequest(); ServerHttpRequest request = serverWebExchange.getRequest();
setLogService(serverWebExchange, gatewayFilterChain); // setLogService(serverWebExchange, gatewayFilterChain);
String requestUri = request.getPath().pathWithinApplication().value(); String requestUri = request.getPath().pathWithinApplication().value();
if (requiredAttribute != null) { if (requiredAttribute != null) {
Iterator<URI> iterator = requiredAttribute.iterator(); Iterator<URI> iterator = requiredAttribute.iterator();
...@@ -287,105 +287,105 @@ public class AccessGatewayFilter implements GlobalFilter { ...@@ -287,105 +287,105 @@ public class AccessGatewayFilter implements GlobalFilter {
} }
public void setLogService(ServerWebExchange exchange, GatewayFilterChain chain) { // public void setLogService(ServerWebExchange exchange, GatewayFilterChain chain) {
MediaType mediaType = exchange.getRequest().getHeaders().getContentType(); // MediaType mediaType = exchange.getRequest().getHeaders().getContentType();
ServerRequest serverRequest = new DefaultServerRequest(exchange); // ServerRequest serverRequest = new DefaultServerRequest(exchange);
//
// 如果是json格式,将body内容转化为object or map 都可 // // 如果是json格式,将body内容转化为object or map 都可
if (MediaType.APPLICATION_JSON.isCompatibleWith(mediaType)) { // if (MediaType.APPLICATION_JSON.isCompatibleWith(mediaType)) {
Mono<Object> modifiedBody = serverRequest.bodyToMono(Object.class) // Mono<Object> modifiedBody = serverRequest.bodyToMono(Object.class)
.flatMap(body -> { // .flatMap(body -> {
recordLog(exchange.getRequest(), body); // recordLog(exchange.getRequest(), body);
return Mono.just(body); // return Mono.just(body);
}); // });
//
} // }
// 如果是表单请求 // // 如果是表单请求
else if (MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(mediaType)) { // else if (MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(mediaType)) {
Mono<String> modifiedBody = serverRequest.bodyToMono(String.class) // Mono<String> modifiedBody = serverRequest.bodyToMono(String.class)
// .log("modify_request_mono", Level.INFO) // // .log("modify_request_mono", Level.INFO)
.flatMap(body -> { // .flatMap(body -> {
recordLog(exchange.getRequest(), body); // recordLog(exchange.getRequest(), body);
//
return Mono.just(body); // return Mono.just(body);
}); // });
//
} // }
// TODO 这里未来还可以限制一些格式 // // TODO 这里未来还可以限制一些格式
//
// 无法兼容的请求,则不读取body,像Get请求这种 // // 无法兼容的请求,则不读取body,像Get请求这种
recordLog(exchange.getRequest(), ""); // recordLog(exchange.getRequest(), "");
} // }
//
private void recordLog(ServerHttpRequest request, Object body) { // private void recordLog(ServerHttpRequest request, Object body) {
// 记录要访问的url // // 记录要访问的url
if (!getNotLogUri().contains(request.getURI().getRawPath())) { // if (!getNotLogUri().contains(request.getURI().getRawPath())) {
//
//
StringBuilder builder = new StringBuilder(); // StringBuilder builder = new StringBuilder();
log.info("=================请求uri:" + request.getURI().getRawPath()); // log.info("=================请求uri:" + request.getURI().getRawPath());
// 记录访问的方法 // // 记录访问的方法
HttpMethod method = request.getMethod(); // HttpMethod method = request.getMethod();
if (null != method) { // if (null != method) {
log.info("=================请求方法:" + method.name()); // log.info("=================请求方法:" + method.name());
} // }
request.getHeaders().add("uuid", UUID.randomUUID().toString()); // request.getHeaders().add("uuid", UUID.randomUUID().toString());
// 记录头部信息 // // 记录头部信息
builder.append(", header { "); // builder.append(", header { ");
for (Map.Entry<String, List<String>> entry : request.getHeaders().entrySet()) { // for (Map.Entry<String, List<String>> entry : request.getHeaders().entrySet()) {
builder.append(entry.getKey()).append(":").append(StringUtils.join(entry.getValue(), ",")).append(","); // builder.append(entry.getKey()).append(":").append(StringUtils.join(entry.getValue(), ",")).append(",");
if("uuid".equals(entry.getKey())) { // if("uuid".equals(entry.getKey())) {
if(entry.getValue() != null && entry.getValue().size() > 0) { // if(entry.getValue() != null && entry.getValue().size() > 0) {
log.info("=================请求方法uuid:" + entry.getValue().get(0)); // log.info("=================请求方法uuid:" + entry.getValue().get(0));
} // }
} // }
if("Authorization".equals(entry.getKey())) { // if("Authorization".equals(entry.getKey())) {
if(entry.getValue() != null && entry.getValue().size() > 0) { // if(entry.getValue() != null && entry.getValue().size() > 0) {
getAdminUserInfo(entry.getValue().get(0)); // getAdminUserInfo(entry.getValue().get(0));
} // }
//
} // }
} // }
log.info("=================请求头header:" + builder.toString()); // log.info("=================请求头header:" + builder.toString());
// 记录参数 // // 记录参数
builder = new StringBuilder(); // builder = new StringBuilder();
// 处理get的请求 // // 处理get的请求
if (null != method && HttpMethod.GET.matches(method.name())) { // if (null != method && HttpMethod.GET.matches(method.name())) {
// 记录请求的参数信息 针对GET 请求 // // 记录请求的参数信息 针对GET 请求
MultiValueMap<String, String> queryParams = request.getQueryParams(); // MultiValueMap<String, String> queryParams = request.getQueryParams();
for (Map.Entry<String, List<String>> entry : queryParams.entrySet()) { // for (Map.Entry<String, List<String>> entry : queryParams.entrySet()) {
builder.append(entry.getKey()).append("=").append(StringUtils.join(entry.getValue(), ",")).append(","); // builder.append(entry.getKey()).append("=").append(StringUtils.join(entry.getValue(), ",")).append(",");
} // }
} else { // } else {
// 从body中读取参数 // // 从body中读取参数
builder.append(body); // builder.append(body);
} // }
log.info("=================请求参数:" + builder.toString()); // log.info("=================请求参数:" + builder.toString());
} // }
} // }
//
private void getAdminUserInfo(String token) { // private void getAdminUserInfo(String token) {
if(token !=null) { // if(token !=null) {
UserDTO userDTO = userFeign.userinfoByToken(token).getData(); // UserDTO userDTO = userFeign.userinfoByToken(token).getData();
if(userDTO != null) { // if(userDTO != null) {
log.info("=================后台用户名:username = {}", userDTO.getUsername()); // log.info("=================后台用户名:username = {}", userDTO.getUsername());
log.info("=================后台姓名: name = {}", userDTO.getName()); // log.info("=================后台姓名: name = {}", userDTO.getName());
} else { // } else {
AppUserDTO appUserDTO = userFeign.userDetailByToken(token).getData(); // AppUserDTO appUserDTO = userFeign.userDetailByToken(token).getData();
if(appUserDTO != null) { // if(appUserDTO != null) {
log.info("=================APP用户名:userId = {}", appUserDTO.getUserid()); // log.info("=================APP用户名:userId = {}", appUserDTO.getUserid());
log.info("=================APP姓名: name = {}", appUserDTO.getRealname()); // log.info("=================APP姓名: name = {}", appUserDTO.getRealname());
log.info("=================APP手机号: phone = {}", appUserDTO.getUsername()); // log.info("=================APP手机号: phone = {}", appUserDTO.getUsername());
} // }
} // }
} // }
} // }
//
@Value("${logback.ignore-log-path}") // @Value("${logback.ignore-log-path}")
String[] path; // String[] path;
public List<String> getNotLogUri() { // public List<String> getNotLogUri() {
return Arrays.asList(path); // return Arrays.asList(path);
} // }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment