原因似乎是WebFluxInboundEndpoint在没有正文的情况下停止处理POST请求
doHandle()
,该行
.map(body -> new HttpEntity<>(...))
如果没有请求正文内容,则从不执行:
private Mono<Void> doHandle(ServerWebExchange exchange) {
return extractRequestBody(exchange)
.doOnSubscribe(s -> this.activeCount.incrementAndGet())
.map(body -> new HttpEntity<>(body, exchange.getRequest().getHeaders()))
.map(entity -> buildMessage(entity, exchange))
.flatMap(requestMessage -> {
if (this.expectReply) {
return sendAndReceiveMessageReactive(requestMessage)
.flatMap(replyMessage -> populateResponse(exchange, replyMessage));
}
else {
send(requestMessage);
return setStatusCode(exchange);
}
})
.doOnTerminate(this.activeCount::decrementAndGet);
}
解决方法:调用者必须发送任何非空的请求正文才能使其工作,例如,使用-d传递一个报价就足够了:
curl -d ' http://localhost:8080/message/4
有了这样一个请求,我的日志将按预期包含传入的GenericMessage,/events资源开始生成SSE。
2018-05-05 17:25:24.777 TRACE 40436 --- [ctor-http-nio-8] o.s.w.r.r.method.InvocableHandlerMethod : Method [org.springframework.integration.webflux.inbound.WebFluxInboundEndpoint.handle] returned [MonoDefer]
2018-05-05 17:25:24.777 DEBUG 40436 --- [ctor-http-nio-8] o.s.w.r.r.method.InvocableHandlerMethod : Response fully handled in controller method
2018-05-05 17:25:24.778 INFO 40436 --- [ctor-http-nio-8] o.s.integration.handler.LoggingHandler : GenericMessage [payload=4, headers={http_requestMethod=POST, Accept=*/*, User-Agent=curl/7.49.1, http_requestUrl=http://localhost:8080/message/4, Host=localhost:8080, id=9a09294d-280a-af3b-0894-23597cf1cb5f, Content-Length=1, contentType=application/x-www-form-urlencoded, timestamp=1525533924778}]