0
我有一個使用POST方法的Scalatra API,該方法由發送gzip編碼消息的外部API調用。但我無法讀取POST請求的身體,當我嘗試讀取POST的身體或試圖解壓,我得到異常:Scalatra,使用Gzip編碼處理POST請求
MalformedInputException: Input length = 1.
如果我的路線傳入POST請求提琴手,小提琴手正確處理該消息並指出,該消息被編碼,解碼後,我可以在請求的主體看到正確的消息
這裏是我已經試過的東西:
val body = new GZIPInputStream(new ByteArrayInputStream(request.body.getBytes))
同樣的例外情況如下:
logger.info(s"Response body..." + request.body)
我也試着讀身體JSON,但它返回JNothing:
logger.info(s"Response body...\n${parsedBody}")
這裏是POST頭:
(Expect,100-continue)
(Connection,keep-alive)
(Content-Encoding,gzip)
(Content-Type,application/json)
(Content-Length,3500)
這裏是堆棧道的一部分:
Parsing the request body failed, because:
java.nio.charset.MalformedInputException: Input length = 1
at java.nio.charset.CoderResult.throwException(Unknown Source) ~[na:1.8.0_45]
at sun.nio.cs.StreamDecoder.implRead(Unknown Source) ~[na:1.8.0_45]
at sun.nio.cs.StreamDecoder.read(Unknown Source) ~[na:1.8.0_45]
at java.io.InputStreamReader.read(Unknown Source) ~[na:1.8.0_45]
at java.io.BufferedReader.read1(Unknown Source) ~[na:1.8.0_45]
at java.io.BufferedReader.read(Unknown Source) ~[na:1.8.0_45]
at java.io.Reader.read(Unknown Source) ~[na:1.8.0_45]
at scala.io.BufferedSource.mkString(BufferedSource.scala:96) ~[scala-library-2.11.6.jar:na]
at org.scalatra.servlet.RichRequest$$anonfun$body$1.apply(RichRequest.scala:181) ~[scalatra_2.11-2.3.0.jar:2.3.0]
at org.scalatra.servlet.RichRequest$$anonfun$body$1.apply(RichRequest.scala:176) ~[scalatra_2.11-2.3.0.jar:2.3.0]
at scala.Option.getOrElse(Option.scala:121) [scala-library-2.11.6.jar:na]
at org.scalatra.servlet.RichRequest.body(RichRequest.scala:176) ~[scalatra_2.11-2.3.0.jar:2.3.0]
at org.scalatra.json.JsonSupport$class.parseRequestBody(JsonSupport.scala:29) [scalatra-json_2.11-2.3.0.jar:2.3.0]
at impala.api.GreetingController.parseRequestBody(GreetingController.scala:13) [classes/:na]