scalatra / scalatra

Tiny Scala high-performance, async web framework, inspired by Sinatra
http://scalatra.org
Other
2.65k stars 336 forks source link

scalatra-atmosphere and RichRequest conflicts getReader/getInputStream and RichRequest.cachedBody problem #722

Open kounoike opened 6 years ago

kounoike commented 6 years ago

I'm trying implement gitbucket-chat-plugin with scalatra-atmosphere. I made simple websocket-based chat. It works fine with sbt jetty:start, embedded Jetty. But it fails on Tomcat.

first problem

I got exception it says "already used getInputStream" when calling getReader method.

second problem

I fix readBody with getInputStream, but it returns body as empty string always on Tomcat. On Jetty, it works fine.

third problem

I tried to find method which read body with getInputStream. I found it is RichRequest. So, I changed readBody to RichRequest(request).body. Then it works fine on Tomcat. But it doesn't works on Jetty, it repeats first message's body eternally. It seems as cachedBody doesn't clear when handled message.

workaround

I have a workaround. But I don't have any confidence.

version

I'm using scalatra-2.6.0-SNAPSHOT because 2.5.x uses too old version of atmosphere library.

takezoe commented 6 years ago

@kounoike Is your application communicating via WebSocket? I think this workaround looks to work for only when communication is fallbacked to Ajax polling.