【问题标题】:Multipart Form Errors with LagomLagom 的多部分表单错误
【发布时间】:2017-10-18 00:36:04
【问题描述】:

我们的大多数 Lagom 入口点不使用多部分表单请求,但有一个使用。由于 Lagom 目前不支持原生多部分请求,因此我看到的一般建议是使用 PlayServiceCall 机制调用底层 Play API。

我们已经做到了,而且大部分时间都有效。但是我们会遇到间歇性错误,尤其是在提交大文件时。这些总是java.util.zip.ZipException(各种)的情况,看起来好像没有收到整个文件进行处理。

下面是入口点在代码中的样子;特别是 Play 包装机制:

def upload = PlayServiceCall[NotUsed, UUID] {
  wrapCall => Action.async(multipartFormData) {
    request => wrapCall(ServiceCall { _ =>
      val upload = request.body.file("upload")
      val input = new FileInputStream(upload.get.ref.file)
      val filename = upload.get.filename
      // ...
      // other code to actually process the file
      // ...
    })(request).run
  }
}

这里只是我们看到的两个异常示例:

Caused by: java.util.zip.ZipException: invalid code lengths set
  at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
  at java.util.zip.ZipInputStream.read(ZipInputStream.java:194)
  at org.apache.poi.openxml4j.util.ZipSecureFile$ThresholdInputStream.read(ZipSecureFile.java:214)
  at java.io.FilterInputStream.read(FilterInputStream.java:107)
  etc.

Caused by: java.util.zip.ZipException: invalid distance too far back
  at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
  at java.util.zip.ZipInputStream.read(ZipInputStream.java:194)
  at org.apache.poi.openxml4j.util.ZipSecureFile$ThresholdInputStream.read(ZipSecureFile.java:214)
  at java.io.FilterInputStream.read(FilterInputStream.java:107)
  etc.

我们在 Scala 中使用 Lagom 1.3.8。有什么建议吗?

【问题讨论】:

    标签: scala playframework multipartform-data lagom


    【解决方案1】:

    尝试使用基于 Akka HTTP 的新服务网关。

    您可以通过将以下内容添加到您的build.sbt 来启用此功能:

    lagomServiceGatewayImpl in ThisBuild := "akka-http"
    

    新服务网关在 Lagom 1.3.8 中仍默认禁用,但遇到此问题的 Lagom 用户报告已通过启用akka-http 网关解决。这将成为 Lagom 1.4.0 中的默认实现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 2017-08-14
      • 1970-01-01
      • 2016-02-19
      • 2020-01-18
      • 2017-10-20
      相关资源
      最近更新 更多