Reputation: 696
Hey I'm struggling with that problem. The server gets the request but not the json that i transmit. I have searched in the threads, but found nothing that works for me.
My Coffescript request:
d = { 'filter': "John Portella" };
$.ajax(
type: "POST",
dataType: "text/json",
data : JSON.stringify(d),
url: "/restricted/actionOnMultipleDatasets",
success: (data) ->
...
The related route:
POST /restricted/actionOnMultipleDatasets controllers.ajax.AjaxDatasetOperations.actionOnMultipleDatasets()
and the Controller action
@SecuredAction(authorization = WithProvider.class, params = { "userpassword" })
public static Result actionOnMultipleDatasets() {
UserInfo userInfo = (UserInfo) ctx().args.get(SecureSocial.USER_KEY);
JsonNode json=request().body().asJson();
if(json==null){
return badRequest(Json.toJson("Data is not Json!"));
}
And every time I request that action the json is null. Does anyone figure out why this happens? As additional information I use securesocial.
I have tried to clean up the project. Nothing happened.
The related stack trace:
java.lang.NullPointerException
at controllers.ajax.AjaxDatasetOperations.actionOnMultipleDatasets(AjaxDatasetOperations.java:588)
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$36$$anonfun$apply$36.apply(routes_routing.scala:497)
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$36$$anonfun$apply$36.apply(routes_routing.scala:497)
at play.core.Router$HandlerInvoker$$anon$7$$anon$2.invocation(Router.scala:183)
at play.core.Router$Routes$$anon$1.invocation(Router.scala:377)
at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:56)
at play.GlobalSettings$1.call(GlobalSettings.java:64)
at play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:91)
at play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:90)
at play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82)
at play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82)
at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:278)
at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:274)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:29)
at play.core.j.HttpExecutionContext$$anon$2.run(HttpExecutionContext.scala:37)
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:42)
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Upvotes: 0
Views: 374
Reputation: 965
When posting with jquery, try adding the following lines as parameters:
contentType: "application/json; charset=utf-8",
dataType: "json",
Upvotes: 2