I am trying the below code with vertx 3.9.10 and it does not seem to write to the zipfile however the file gets created correctly. The pipeTo eventHandler is never called and i keep getting 202 in the client instead of 200.
@Override
public Handler<RoutingContext> createHandler() {
return rtx -> {
HttpServerRequest req = rtx.request();
HttpServerResponse res = rtx.response();
FileSystem fs = vertx.fileSystem();
log.info("-- Starting file upload -- ");
String filename = "file" + System.currentTimeMillis() + ".zip";
req.pause();
fs.open(filename
, new OpenOptions()
, ares -> {
AsyncFile afile = ares.result();
log.info("File Created:" + filename);
req.pipeTo(afile,event -> {
afile.close(event1 -> {
log.info("I am in ...." +req.isEnded());
req.response().end();
});
});
req.response().setStatusCode(202).end();
});
};
}
As soon as i try to attach a handler to the request below i keep after the pipeTo i get a java.lang.IllegalStateException: Request has already been read
req.endHandler(v1 -> afile.close(v2 -> {
log.info("Uploaded Finished!! ");
req.response().end();
}));
What is being done incorrectly here?? How can this be corrected ??