我想要过滤器的顺序来做这个
我的自定义筛选器向我的 base
url参数
返回响应后,转至 uri
以及 SetPath
这是我的申请表
- id: sanity
uri: http://localhost:8080
predicates:
- Path=/sanity/**
filters:
- SetPath=/checkIfWorks
- name: Test
args:
prox: true
post: true
base: http://localhost:8080/test
这是我的自定义过滤器
@Component
class TestGatewayFilterFactory: AbstractGatewayFilterFactory<ProxyGatewayFilterFactory.Params>(Params::class.java) {
val logger: Logger = LoggerFactory.getLogger(" ")
override fun apply(params: Params): GatewayFilter {
return OrderedGatewayFilter(
GatewayFilter { exchange, chain ->
exchange.request.mutate().header("active", "false").build()
if (params.prox) {
if (params.post) {
WebClient.create().post()
.uri(params.base)
.body(BodyInserters.fromDataBuffers(exchange.request.body))
.headers { it.addAll(exchange.request.headers) }
.exchange()
.flatMap {
it.bodyToMono(JsonNode::class.java)
}
.map {
val om = ObjectMapper()
val bytes = om.writer().writeValueAsBytes(it)
val buffer = exchange.response.bufferFactory().wrap(bytes)
exchange.response.writeWith(Flux.just(buffer))
}.flatMap {
it
}.map{
exchange
}
.flatMap(chain::filter)
在命中自定义过滤器之后,它不会在setpath过滤器上执行,直接从
flatMap.(chain::filter) localhost:8080/test
有人打电话来,但在这之后, localhost:8080/checkIfWorks
从来没有得到平
暂无答案!
目前还没有任何答案,快来回答吧!