0

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>

1 Answers1

0

Chunking happens at data transfer level and is hidden to client. Multipart is managed at application level. A multi-part http message can be transferred using chunked encoding by the server if need by. See more details here

You can use ReceiveTimeout at CXF configuration level to set the length of time in milliseconds your service attempts to receive a request before the connection times out. Set 0 for no timeout

The configuration should looks like this

  <http-conf:destination name="{http://apache.org/hello_world_soap_http}SoapPort.http-destination">
       <http-conf:server ReceiveTimeout="0" />
  </http-conf:destination>

Take in account that connection timeout parameters also can be set in the application server, and could be limiting the connection.

Community
  • 1
  • 1
pedrofb
  • 37,271
  • 5
  • 94
  • 142