gpt4 book ai didi

spring-webflow - 支持通过 Spring Cloud Gateway 代理 SOAP/XML 端点

转载 作者:行者123 更新时间:2023-12-05 07:25:28 43 4
gpt4 key购买 nike

尝试在使用 Spring 云网关代理 soap 服务时记录请求和响应。下面是代码片段...抛出 IllegalStateException。

java.lang.IllegalStateException: Only one connection receive subscriber allowed. at reactor.netty.channel.FluxReceive.startReceiver(FluxReceive.java:271) [reactor-netty-0.8.4.RELEASE.jar:0.8.4.RELEASE] at reactor.netty.channel.FluxReceive.subscribe(FluxReceive.java:121) [reactor-netty-0.8.4.RELEASE.jar:0.8.4.RELEASE]

--- Spring Versions ---

SpringBoot : 2.1.2.RELEASE
spring-cloud-gateway : 2.1.1.BUILD-SNAPSHOT
spring-boot-starter-webflux : 2.1.2.RELEASE
reactor-core : 3.2.5.RELEASE

网关示例应用程序

public class  GatewaySampleApplication {
@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
return builder.routes()
.route(
r ->
r.path("/security/getToken")
.filters( f -> f.preserveHostHeader()
.filter(new PolicyHandlerReactive()))
.uri("http://targetendpoint.xyz.com")
)
.build();
}
}

PolicyHandlerReactive :

PolicyHandlerReactive implements GatewayFilter  {

@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain)
{
ServerHttpRequest request = (ServerHttpRequest) exchange.getRequest();
Flux<DataBuffer> xmlReqFlux = request.getBody();
Mono<List<DataBuffer>> monoDataList = xmlReqFlux.collectList();
monoDataList.map(dataA -> logRequest2(dataA)).subscribe();
return chain.filter(exchange);
}
}
private List<DataBuffer> logRequest(List<DataBuffer> dataA) {           

ListIterator<DataBuffer> dataAList = dataA.listIterator();

while(dataAList.hasNext() ) {
DataBuffer dataBuffer = dataAList.next();
InputStream is = dataBuffer.asInputStream();
System.out.println(convertStreamToString(is));
}
return dataA;
}

最佳答案

能够使用 .modifyRequestBody 而不是过滤器来解决这个问题......更新了下面的 java DSL...

    .route(
r ->
r.path("external/v2/security/")
.filters( f -> f
.preserveHostHeader()
.modifyRequestBody(String.class, String.class,
(exchange, s) -> {
Mono<String> dataA = Mono.just(s);
dataA.subscribe(System.out::print);
return dataA;
})
)
.uri("http://targetendpoint.xyz.com")
)

关于spring-webflow - 支持通过 Spring Cloud Gateway 代理 SOAP/XML 端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54786497/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com