A CXF service has a POST method to upload and process some gzipped file with data. When the uploaded file is big it is processed by the service more then 10 minutes. The problem is that the client receives 504 (gateway time-out) response after 10 minutes.
As I understand, the key thing is that the data is uploaded fast but the processing time is large and the client fails to wait for the data being fully processed.
Is there a way to stream the multi-part so that the connection is not closed abruptly?
May be there is a way NOT to read a stream from attachment fully but read it chunk by cnunk?
Or there is a way to configure this timeout?
The service:
@POST
@Consumes("multipart/form-data")
@Produces("application/json")
@Path("/gzip")
UploadResult uploadGzip(
@Multipart("data") Attachment attachment,
@QueryParam("default-expiration-period") @Nullable String defaultExpirationPeriod
) throws NotAcceptableException, BadRequestException {
String filename = attachment.getContentDisposition().getParameter("filename"); //filename is important
InputStream inputStream = attachment.getDataHandler().getInputStream();
return readAndProcess(filename, inputStream);
}
And the html form to POST a file:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Dump factors</title>
</head>
<body>
<form method="POST" enctype="multipart/form-data"
action="https://myserver.com/api/data/gzip">
File to upload: <input type="file" name="data"><br/>
<br/>
<input type="submit" value="Press"> to upload the file!
</form>
</body>
</html>