Response throws "java.lang.IllegalStateException: Response has already been written"

712 views
Skip to first unread message

Alexander Dorfman

unread,
Jul 5, 2016, 12:53:05 PM7/5/16
to vert.x
When I try to reply to do .response(), Vert.x throws an error: java.lang.IllegalStateException: Response has already been written
Notice, reply takes place within the consumer handler, not right in the body of the route handler.
Thank you.

router.post("/rbuilder").handler(routingContext -> {

if (!routingContext.failed()) {
vertx.eventBus().<JsonObject>consumer("riot.HttpEndpoint", message -> {
// //success
if(message.body().getString("Success") == "True")
{
routingContext.response().setStatusCode(200).end(new JsonObject().put("Success","True").encode());
}
// failure
else
{
routingContext.response().setStatusCode(400).end(new JsonObject().put("Success", "False").encode());
}
});

Jez P

unread,
Jul 5, 2016, 12:59:21 PM7/5/16
to vert.x
What can write to that event bus address? Could more than one message hit it? If so, then the first will make it write the response, the second will cause your error.

Jez P

unread,
Jul 5, 2016, 12:59:44 PM7/5/16
to vert.x
Could you share a more extensive reproducer via github please?

Julien Viet

unread,
Jul 6, 2016, 2:34:48 AM7/6/16
to ve...@googlegroups.com
Hi Alexander,

it happens because you receive multiple messages from the event bus as this is a normal consumer.

can you explain what you are trying to achieve ?

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/083b2f01-c8fc-442e-8dfe-ce1de59ceecc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages