質問

myRequest:

WS.url(url)
.withHeaders("Accept-Encoding" -> "gzip")
.withQueryString("xxx","xxx")
.

ボディを解凍するためのコード

 def call[T](api: WeiboApi[T])(implicit mf: Manifest[T]) = {
    val param = parameters(api)
    (api match {
      case _: Get[T] => get(api.url, param)
      case _: Post[T] => post(api.url, param)
    }) map {
      resp =>
      try {
        val decompressedBody = decompressIfGzip(resp)
        api.parse(decompressedBody)
      } catch {
        case e: WeiboApiError => throw e
        case e: Exception =>
          throw new Exception("cannot parse body api " + api, e)
      }
    }
  }

private def decompressIfGzip(resp: Response) = {
    val ahcResp = resp.getAHCResponse
        ahcResp.getHeader("Content-Encoding") match {
          case "gzip" | "GZIP" =>
            val in = ahcResp.getResponseBodyAsStream
            val gzipStream = new GZIPInputStream(in)
            try {
              val source = scala.io.Source.fromInputStream(gzipStream)
              source.mkString
            } finally {
              in.close()
            }
          case _ =>
            ahcResp.getResponseBody
        }
}
.

それから私は同時に2つの要求を送ります。

時々それは問題ない

しかし時々それは再発

[error] Corrupt GZIP trailer
[error] sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
[error] sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
[error] sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
[error] lib.weibo.Weibo$.lib$weibo$Weibo$$decompressIfGzip(Weibo.scala:138)
[error] lib.weibo.Weibo$$anonfun$call$1.apply(Weibo.scala:47)
[error] lib.weibo.Weibo$$anonfun$call$1.apply(Weibo.scala:42)
[error] 
.

akka.dispatch.batchingexecutor $ Batch $$ anonfun $ run $ 1.ProcessBatch $ 1(BatchingExecutor.Scala:67) [エラー] akka.dispatch.batchingexecutor $ batch $$ anonfun $ run $ 1. $ mcv $ sp(batchingexecutor.scala:82) [エラー] akka.dispatch.batchingexecutor $ batch $$ anonfun $ run $ 1. apply(batchingexecutor.scala:59) [エラー] akka.dispatch.batchingexecutor $ batch $$ anonfun $ run $ 1. apply(batchingexecutor.scala:59) [エラー] akka.dispatch.batchingexecutor $ batch.run(batchingexecutor.scala:58) [エラー] akka.dispatch.taskInvocation.run(AbstractDispatcher.Scala:42) [エラー] akka.dispatch.forkjoinexecutorConfigurator $ akkaforkjontask.exec(AbstractDispatcher.Scala:386)

何が問題なのですか?

役に立ちましたか?

解決

応答データが破損していることがあります。

他のヒント

よくないが、InputStreamReaderでそのコードを包む必要があるかもしれません:

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top