rapidoid / rapidoid

Rapidoid - Extremely Fast, Simple and Powerful Java Web Framework and HTTP Server!

Home Page:http://www.rapidoid.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to return Protobuff binary from server ?

vsaji opened this issue · comments

commented

We are evaluating rapidoid for one of our projects. While trying with Protobuff stream, we were able to send the stream to server, however, we have no clue how to return a binary data to the client.

We could read the data via Req.body().
We have tried with Req and ReqResHandler, but they both return object but we don't know what to return.

We tried returning instance of Resp (req.response() from Req or Resp from ReqResHandler) after setting the outputstrem (Resp.out). But it threw the following exception. Kindly help.

ERROR | 26/Oct/2018 12:36:39:319 | executor1 | org.rapidoid.net.impl.RapidoidConnection | Tried to resume a job that already has finished! | handle = 1 | currentHandle = 1 | job = org.rapidoid.http.impl.RespImpl$1@50e2dba6
ERROR | 26/Oct/2018 12:36:39:320 | executor1 | org.rapidoid.http.impl.lowlevel.LowLevelHttpIO | Error occurred when handling request! | error = java.lang.RuntimeException: Tried to resume a job that already has finished!
java.lang.RuntimeException: Tried to resume a job that already has finished!
       at org.rapidoid.u.U.rte(U.java:423)
       at org.rapidoid.net.impl.RapidoidConnection.resume(RapidoidConnection.java:372)
       at org.rapidoid.http.impl.RespImpl.resume(RespImpl.java:422)
       at org.rapidoid.http.impl.RespImpl.chunk(RespImpl.java:531)
       at org.rapidoid.http.impl.ChunkedResponse.flush(ChunkedResponse.java:70)
       at org.rapidoid.http.impl.ChunkedResponse.close(ChunkedResponse.java:77)
       at org.rapidoid.io.IO.close(IO.java:291)
       at org.rapidoid.http.impl.RespImpl.finish(RespImpl.java:561)
       at org.rapidoid.http.impl.ReqImpl.onDone(ReqImpl.java:534)
       at org.rapidoid.http.impl.ReqImpl.done(ReqImpl.java:510)
       at org.rapidoid.http.handler.HttpManagedHandlerDecorator.processNormalResult(HttpManagedHandlerDecorator.java:232)
       at org.rapidoid.http.handler.HttpManagedHandlerDecorator.complete(HttpManagedHandlerDecorator.java:223)
       at org.rapidoid.http.handler.HttpManagedHandlerDecorator.handleWithWrappers(HttpManagedHandlerDecorator.java:109)
       at org.rapidoid.http.handler.HttpManagedHandlerDecorator.access$200(HttpManagedHandlerDecorator.java:39)
       at org.rapidoid.http.handler.HttpManagedHandlerDecorator$2.run(HttpManagedHandlerDecorator.java:83)
       at org.rapidoid.job.PredefinedContextJobWrapper.run(PredefinedContextJobWrapper.java:56)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
       at java.lang.Thread.run(Thread.java:745)

It appears that one needs to return the response object, as documented here: https://www.rapidoid.org/docs.html#_sending_chunked_http_response

Doing so solved it for me.