【问题标题】:spring webflux (netty) handler can't parse ServerRequest containing json larger than 750 bytesspring webflux(netty)处理程序无法解析包含大于 750 字节的 json 的 ServerRequest
【发布时间】:2018-07-29 18:57:06
【问题描述】:

我们最近开始尝试使用 Spring Boot 2.0。 具有以下处理程序代码:

@Component
public class DataStreamHandler {

    public Mono<ServerResponse> pipeEvent(ServerRequest request) {
        Mono<String> reqBody = request.bodyToMono(String.class);
        String body = reqBody.block();
        System.out.println(body);
        return ServerResponse.ok().body(fromObject("OK"));
    }
}

@Configuration
public class RouterConfig {

    @Bean
    public RouterFunction<ServerResponse> monoRouterFunction(DataStreamHandler dataStreamHandler) {
        return route(POST("/pipeEvent"), dataStreamHandler::pipeEvent);
    }
}

处理程序似乎无法解析包含大于 750 字节的 json 的请求。 当我搜索如何配置 max-http-post-size 时,我发现仅适用于 tomcat、jetty 和 undertow 的解决方案。

如何为底层网络配置它?

【问题讨论】:

  • 你能分享一个示例 curl 命令吗?发生此错误时会发生什么(HTTP 响应是什么?您在日志中看到了什么吗?)
  • 很愿意,但是当它发生时,我没有看到任何错误,并且客户端(邮递员)没有得到任何响应。如果我使用较小的 json,那么我会得到 200 ok,并且 json 会打印到日志中

标签: spring-boot netty spring-webflux


【解决方案1】:

这是 Reactor Betty 中的一个已知问题 - look at this issue comment 了解更多信息。

您不应该在 Handler 中执行阻塞操作。

你应该把你的代码改成这样:

@Component
public class DataStreamHandler {

    public Mono<ServerResponse> pipeEvent(ServerRequest request) {
        return request.bodyToMono(String.class)
                .doOnNext(System.out::println)
                .then(ServerResponse.ok().body(fromObject("OK")));
    }
}

【讨论】:

  • block操作只是简单的例子,反正block不是问题,没有任何影响。
  • 我无法用我提供的代码 sn-p 重现该问题 - 是什么让您认为块运算符不是问题?
  • 我已经更新了我的答案,提供了一个已知问题的链接。一开始我可能无法重现这个,因为我没有使用 curl。
猜你喜欢
  • 2023-03-10
  • 2019-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多