【问题标题】:Long processing of multi-part attachment in CXF causes 504 (time-out)CXF中多部分附件的长时间处理导致504(超时)
【发布时间】:2017-04-23 14:57:37
【问题描述】:

CXF 服务有一个 POST 方法来上传和处理一些带有数据的 gzip 文件。当上传的文件很大时,服务会处理超过 10 分钟。问题是客户端在 10 分钟后收到 504(网关超时)响应。
据我了解,关键是数据上传速度快,但处理时间长,客户端无法等待数据完全处理完毕。
有没有办法流式传输多部分,以便连接不会突然关闭?
可能有一种方法不完全从附件中读取流,而是通过 cnunk 读取它?
或者有办法配置这个超时?

服务:

@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);
}

以及 POST 文件的 html 表单:

<!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>

【问题讨论】:

    标签: java web-services http cxf


    【解决方案1】:

    分块发生在数据传输级别,对客户端隐藏。 Multipart 在应用程序级别进行管理。如果需要,服务器可以使用分块编码传输多部分 http 消息。查看更多详情here

    您可以使用ReceiveTimeout CXF configuration level 来设置连接超时之前服务尝试接收请求的时间长度(以毫秒为单位)。设置 0 表示不超时

    配置应该是这样的

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

    考虑到连接超时参数也可以在应用服务器中设置,可能会限制连接。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-18
      • 1970-01-01
      • 2014-10-14
      • 1970-01-01
      • 2011-07-29
      • 2018-10-23
      • 1970-01-01
      相关资源
      最近更新 更多