Reading POST body: java.lang.IllegalStateException: 只允许一个连接接收订阅者
Reading POST body: java.lang.IllegalStateException: Only one connection receive subscriber allowed
在 Spring Webflux 中,当我阅读 POST body 并尝试使用它时,它总是导致标题中的 IllegalStateException。
这里是代码:
@Bean
public RouterFunction<ServerResponse> selectByPost(SasoSecurityFacade solrHandler) {
return RouterFunctions.route(RequestPredicates.POST("/v1/{collection}/select")
.and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), request -> request.bodyToMono(String.class)
.flatMap(s -> {
System.out.println(s);
return ServerResponse.ok()
.syncBody(s);
}));
}
同样重要的(事实证明),对服务器的请求:
curl 'https://<myserver>:9443/v1/banana-int/select' -H 'Pragma: no-cache' -H 'Origin: https://<myserver>:9443' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7' -H 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36' -H 'Content-type: application/x-www-form-urlencoded' -H 'Accept: application/json, text/plain, */*' -H 'Cache-Control: no-cache' -H 'Referer: https://<myserver>:9443/banana/src/index.html' -H 'Connection: keep-alive' -H 'DNT: 1' --data 'q=*:*&rows=20&wt=json' --compressed
我做错了什么?我该如何调试呢?还有谁在阅读我的 post body,以至于我收到此错误消息?
您发送的请求是 POST 表单请求,HiddenHttpMethodFilter
会自动读取该请求。此过滤器使用表单数据来改变 HTTP 方法,以防通过 "_method"
参数指定替代方法。
在这种情况下,在 WebFlux annotation/functional 中使用专用的 request.formData()
API 来消费表单数据是最好的选择,它被缓存以备将来使用并且不会触发新订阅。
如果您希望完全禁用此行为,you'll be able to set a property in Spring Boot 2.1。
在 Spring Webflux 中,当我阅读 POST body 并尝试使用它时,它总是导致标题中的 IllegalStateException。
这里是代码:
@Bean
public RouterFunction<ServerResponse> selectByPost(SasoSecurityFacade solrHandler) {
return RouterFunctions.route(RequestPredicates.POST("/v1/{collection}/select")
.and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), request -> request.bodyToMono(String.class)
.flatMap(s -> {
System.out.println(s);
return ServerResponse.ok()
.syncBody(s);
}));
}
同样重要的(事实证明),对服务器的请求:
curl 'https://<myserver>:9443/v1/banana-int/select' -H 'Pragma: no-cache' -H 'Origin: https://<myserver>:9443' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7' -H 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36' -H 'Content-type: application/x-www-form-urlencoded' -H 'Accept: application/json, text/plain, */*' -H 'Cache-Control: no-cache' -H 'Referer: https://<myserver>:9443/banana/src/index.html' -H 'Connection: keep-alive' -H 'DNT: 1' --data 'q=*:*&rows=20&wt=json' --compressed
我做错了什么?我该如何调试呢?还有谁在阅读我的 post body,以至于我收到此错误消息?
您发送的请求是 POST 表单请求,HiddenHttpMethodFilter
会自动读取该请求。此过滤器使用表单数据来改变 HTTP 方法,以防通过 "_method"
参数指定替代方法。
在这种情况下,在 WebFlux annotation/functional 中使用专用的 request.formData()
API 来消费表单数据是最好的选择,它被缓存以备将来使用并且不会触发新订阅。
如果您希望完全禁用此行为,you'll be able to set a property in Spring Boot 2.1。