我有一个Undertow服务器,我正在运行默认值.我试图发送一个分块请求,当服务器接收块时,输入流服务器端永远不会达到-1状态并挂起.
我已经使用了Undertow服务器的默认值(我曾尝试增加线程数但仍然没有运气).
Undertow server = Undertow.builder()
.addHttpListener(8080, "localhost")
.setHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
exchange.getResponseSender().send("Hello World");
}
})
.setHandler(Handlers.routing().post("/xml", blockingHandler))
.build();
server.start();
Run Code Online (Sandbox Code Playgroud)
起初我试图使用普通的httpHandler,但是却引发了错误.
java.lang.IllegalStateException: UT000035: Cannot get stream as startBlocking has not been invoked
Run Code Online (Sandbox Code Playgroud)
经过一些研究后,我使用了Blockoverflow上的建议,然后使用了BlockingHandler.我不再收到上面的错误,但现在处理程序挂起.
这是处理程序的代码(为了清楚起见,我删除了异常处理):
HttpHandler httpHandler = new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
StringBuilder builder = new StringBuilder( );
try(InputStream inputStream = exchange.getInputStream()){
int line;
while( ( line = inputStream.read() ) != -1 ) { …Run Code Online (Sandbox Code Playgroud)