全局拦截器
This commit is contained in:
@ -0,0 +1,36 @@
|
|||||||
|
package com.bipt.intelligentapplicationorchestrationservice.filter;
|
||||||
|
|
||||||
|
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||||
|
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||||
|
import org.springframework.core.Ordered;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class ApiRequestGlobalFilter implements GlobalFilter, Ordered {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||||
|
ServerHttpRequest request = exchange.getRequest();
|
||||||
|
|
||||||
|
// 检查请求路径和方法
|
||||||
|
if (request.getURI().getPath().equals("/request") &&
|
||||||
|
request.getMethod() == HttpMethod.POST) {
|
||||||
|
|
||||||
|
// 在此处添加拦截逻辑
|
||||||
|
System.out.println("拦截到POST /request请求");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 继续处理请求
|
||||||
|
return chain.filter(exchange);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOrder() {
|
||||||
|
return 1; // 过滤器执行顺序,数值越小越先执行
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user