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

running Rapidoid from JUnit - exception when handling async response

mzheravin opened this issue · comments

Hi!

When running rapidoid from JUnit (4 or 5) I'm getting following error for async requests. Sync handling works fine. Exception happens when calling done() method:

2019-08-13/21:07:49.230/EEST [Thread-9] ERROR o.r.h.impl.lowlevel.LowLevelHttpIO - Error occurred when handling request! | error = java.lang.IllegalArgumentException: The customization request (POST /syncAdminApi/v1/users) doesn't match the context request (null)!
java.lang.IllegalArgumentException: The customization request (POST /syncAdminApi/v1/users) doesn't match the context request (null)!
    at org.rapidoid.u.U.illegal(U.java:443)
    at org.rapidoid.u.U.must(U.java:476)
    at org.rapidoid.http.customize.Customization.inValidContext(Customization.java:130)
    at org.rapidoid.http.customize.Customization.of(Customization.java:121)
    at org.rapidoid.http.impl.BodyRenderer.mediaResponseRenderer(BodyRenderer.java:91)
    at org.rapidoid.http.impl.BodyRenderer.resultToRespBody(BodyRenderer.java:85)
    at org.rapidoid.http.impl.BodyRenderer.createRespBodyFromResult(BodyRenderer.java:75)
    at org.rapidoid.http.impl.BodyRenderer.toRespBody(BodyRenderer.java:41)
    at org.rapidoid.http.impl.ReqImpl.renderResponse(ReqImpl.java:569)
    at org.rapidoid.http.impl.ReqImpl.renderResponseOrError(ReqImpl.java:549)
    at org.rapidoid.http.impl.ReqImpl.onDone(ReqImpl.java:524)
    at org.rapidoid.http.impl.ReqImpl.done(ReqImpl.java:510)
    at org.rapidoid.http.impl.RespImpl.done(RespImpl.java:294)
    ...

How I do async processing in the code:

in rapidoid handler thread:

  1. Resp resp = req.async()
  2. ... publish resp to processing pipeline...
  3. return resp

later from another thread:

  1. resp.code(..)
  2. resp.json(..)
  3. resp.done()

When running as standalone application, above approach works fine.

I have noticed that startup log is different when starting rapidoid from the junit, for some reason main=null:

INFO  org.rapidoid.setup.App - Inferred application root | main = null | package = com.package.my

Many thanks!