Composing Action(BodyParser) with ActionFilter in play framework scala
Asked Answered
R

0

6

I've got a play framework application and a problematic action. I'm trying to parse a request body using parse.form and then have an ActionFilter run against that parsed body.

So far I've got something like this

object ModelValidationAction extends ActionFilter[Request[MyModel]]{
  def filter[A <: MyModel](request: Request[A]) = ???
}

def routePointsHere = (Action(parse.form(myModelForm)) andThen ModelValidationAction) { (request: Request[MyModel]) => ??? }

however IDEA gives me the error hint

expected Action[MyModel] => NotInferredA, actual ModelValidationAction.type

and the compiler tells me

... missing argument list for method apply in trait ActionBuilder
[error] Unapplied methods are only converted to functions when a function type is expected. [error] You can make this conversion explicit by writing apply _ or apply(_)(_) instead of apply.

So I can gather that the issue is the method apply[A](bodyParser: BodyParser[A])(block: R[A] => Result): Action[A] around the fact that that second parameter list is not getting filled, but I don't know exactly how the language behaves here.

My (completely baseless) assumption is that Action(parse.form(myModelForm)) would become Request[MyModel] => Result and that invoking andThen would return the same.

Any pointers as to what I'm missing? Thanks!

Roaster answered 9/5, 2017 at 2:19 Comment(2)
Did you ever get to the bottom of this?Hopple
I had a very similar issue, except I wanted to do async. For that the solution is something like: Action.andThen(ModelValidationAction).async(parse.json) { ??? }. I expect it'd be very similar here too, but I'm not sure exactly how it'd map.Hopple

© 2022 - 2024 — McMap. All rights reserved.