Hi,
I'm starting a PoC with Play 2.2.0 and having some pain points with the way sync/async Results are returned in Java.
Consider the following:
public static F.Promise<Result> myAction(/* some input */) {
// Request validation
if (StringUtils.isEmpty(content.title)) {
return badRequest("Title field cannot be empty");
}
if (StringUtils.isEmpty(content.content)) {
return badRequest("Content field cannot be empty");
}
F.Promise<MyObject> rsp = F.Promise.promise(
new F.Function0<MyObject>() {
public MyObject apply() {
return myMagicHappensHere(content, new MyStrategy());
}
}
);
return rsp.map(
new F.Function<MyObject,Result>() {
public Result apply(MyObject pr) {
return ok(index.render(pr));
}
}
);
}
This won't compile, because badRequest() is a Result, and I need to return a Promise<Result>
Another issue is with the verbosity of the response building, just because I wanted to use the async capabilities. Since most controllers are going to be using this (or should), surely there's a better way to do that?
Is it possible perhaps to have the framework expect a return type which is an interface, having both F.Promise<Result> and Result implementing it, and then some helper functions to return every Result as a Promise?
Just throwing ideas in the air. Having looked at several other web-frameworks, I'll be happy to participate in any in-depth discussion on the matter.
Thanks
Itamar.