[2.2.2] [Java] Action Composition

188 views
Skip to first unread message

Kevin Sheppard

unread,
Dec 16, 2013, 1:26:10 PM12/16/13
to play-fr...@googlegroups.com
I'm using Play 2.2.1(Java) and I'd like to know how to compose an action that will allow a forbidden() or badRequest() response once a certain condition was not met.

Example action:

public class Secured extends Action.Simple {
   
public F.Promise<SimpleResult> call(Http.Context ctx) throws Throwable {
       
if(ctx.request().cookie("username") == null) return F.Promise.pure(badRequest("You need to log in."));
       
return delegate.call(ctx);
   
}


My problem is that the badRequest() method is a Results.Status and that doesn't agree with the method signature. How can I fix this?
Message has been deleted

Ólafur Gauti Guðmundsson

unread,
Dec 16, 2013, 3:49:39 PM12/16/13
to play-fr...@googlegroups.com
Hi Kevin,
This works for me:

return Promise.<SimpleResult>pure(badRequest("Something bad happened"));

Best regards,
OGG

Kevin Sheppard

unread,
Dec 16, 2013, 5:42:10 PM12/16/13
to play-fr...@googlegroups.com
Seemed to do the trick now though it didn't work earlier (saw it on a previous thread). Why is this not in the documentation btw?


--
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/8xdABaEwryE/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/groups/opt_out.



--
Kevin Sheppard

Kevin Sheppard

unread,
Dec 16, 2013, 5:42:30 PM12/16/13
to play-fr...@googlegroups.com
Oh and thank you for your assistance.
Reply all
Reply to author
Forward
0 new messages