如何在请求完全流式传输到带有Jersey的服务器之前,如何开始向客户端返回响应? 我想避免在服务器中缓冲任何内容。
我尝试过这样的事情:
@POST
@Path("/post")
public StreamingOutput post(InputStream inputstream) {
MyCustomIterator<MyObject> it = new MyCustomIterator<>(inputsream);
return output -> {
while (it.hasNext()) {
MyObject obj = it.next(); // this read the object from the inputstream
output.write(someConversion(obj));
}
output.flush;
}
}
但是当InputStream很大时它会超时:
ERROR o.g.j.s.ServerRuntime$Responder - An I/O error has occurred while writing a response message entity chunk to the container output stream.
java.io.IOException: java.util.concurrent.TimeoutException: Idle timeout expired: 30003/30000 ms
at org.eclipse.jetty.util.SharedBlockingCallback$Blocker.block(SharedBlockingCallback.java:234)
at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:141)
at org.eclipse.jetty.server.HttpOutput.flush(HttpOutput.java:242)
编辑:我尝试用Jersey Async ChunkedOutput替换StreamingOutput,但我得到了相同的超时错误。