I'm creating service based on Tomcat Servlets and NIO. On input there is big XML request(~100 MB), send through HTML POST method. I want to stream only first 8 KiB, and after that immediately send response to client.
public class A extends HttpServlet {
@Override
protected void service(HttpServletRequest rq, HttpServletResponse rs) {
byte[] buffer = new byte[1024*8];
try {
rq.getInputStream().read(buffer);
rs.setContentType("text/plain");
rs.getOutputStream().write("Some Response".getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
}
There is no problem when I'm trying to send small request (few lines in content), socket works properly.
2016-02-01 10:44:52 Http11NioProtocol [DEBUG] Socket: [org.apache.tomcat.util.net.NioEndpoint$KeyAttachment@74f19fed:org.apache.tomcat.util.net.NioChannel@c478210:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8080 remote=/0:0:0:0:0:0:0:1:63943]], Status in: [OPEN_READ], State out: [OPEN]
But, if I try to send a bigger request (above 100 MB), there is no response on client side.
2016-02-01 10:48:42 Http11NioProtocol [DEBUG] Socket: [org.apache.tomcat.util.net.NioEndpoint$KeyAttachment@2b36c88f:org.apache.tomcat.util.net.NioChannel@25f12241:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8080 remote=/0:0:0:0:0:0:0:1:64079]], Status in: [OPEN_READ], State out: [CLOSED]
2016-02-01 10:48:42 LimitLatch [DEBUG] Counting down[http-nio-8080-exec-3] latch=1
Tomcat don't want to open socket (State out: CLOSED), before I read entire input stream request.
Is it possible to send response into client without reading entire request? According to specification, I'm able to find interesting me informations on very first 8 KiB of the request.