1

I have a Scalatra API with a POST method, which is invoked by an external API that sends gzip encoded messages. But I am unable to read the body of the post request, and when I try to read the body of POST or try to decompress it, I get the exception:

MalformedInputException: Input length = 1.

If I route the incoming POST request to fiddler, the fiddler handles the message correctly and states that the message is encoded, and after decoding, I can see the correct message in the body of the request

here are the things I have tried:

val body = new GZIPInputStream(new ByteArrayInputStream(request.body.getBytes))

Same exception is thrown by:

logger.info(s"Response body..." + request.body ) 

I also tried reading the body as json, but it returns JNothing:

logger.info(s"Response body...\n${parsedBody}" ) 

here are the POST headers:

(Expect,100-continue)
(Connection,keep-alive)
(Content-Encoding,gzip)
(Content-Type,application/json)
(Content-Length,3500)

here is part of the stack tract:

    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]

1 Answer 1

0

Solution can be found here on the scalatra user group:

https://groups.google.com/forum/#!topic/scalatra-user/2vBBA2-CzDM

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.