[2.2.2 Java] How to set HTTP status code asynchronously e.g. in Chunks class

24 views
Skip to first unread message

Donghwan Kim

unread,
Apr 23, 2014, 11:39:54 AM4/23/14
to play-fr...@googlegroups.com, Jeanfrancois Arcand
Hello,

How can I do that? Should I set that in return statement? Technically speaking, response headers including status code is able to be set before the first call `out.write`. For the purpose and longer context, see http://flowersinthesand.github.io/wes/

```java
@BodyParser.Of(BodyParser.TolerantText.class)
public static Result http() {
  final Request request = request();
  final Response response = response();
  // How can I defer this?
  return ok(new Chunks<String>(JavaResults.writeString(Codec.utf_8())) {
    @Override
    public void onReady(Chunks.Out<String> out) {
      // The user should be able to set response status code here. e.g. http.setStatus(HttpStatus.NOT_IMPLEMENTED);
      new PlayServerHttpExchange(request, response, out);
    }
  });
}
```

Thanks in advance,

-- Donghwan

Alberto Souza

unread,
Apr 24, 2014, 11:44:20 AM4/24/14
to play-fr...@googlegroups.com, Jeanfrancois Arcand
I don't know how to you :( but, just for curiosity, is this possible? I mean, you started to write the response already. Why don't you use some custom header to indicate a possible problem? Is it a possible solution?

Donghwan Kim

unread,
Apr 24, 2014, 11:51:37 PM4/24/14
to play-fr...@googlegroups.com
Once the response header is written, it's not possible but it can be deferred till the first chunk, out.write(chunk), and be flushed together. You can see more discussion at https://github.com/playframework/playframework/issues/2711

Because the purpose of this is to make an abstraction layer for I/O in Java frameworks that is explained in the wes site. Using custom header is not meaningful. I will check if Promise class can solve this problem. Thanks for your answer.

-- Donghwan


--
You received this message because you are subscribed to a topic in the Google Groups "play-framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/play-framework/F25E9DeaSJE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages