Thursday 15 September 2011

Action(parser.json) vs Action.async Error, and using concurrent.Execution.Implicits made could not initialize class controllers in Play Scala -



Action(parser.json) vs Action.async Error, and using concurrent.Execution.Implicits made could not initialize class controllers in Play Scala -

i'm trying create post request insert info mongoddb using : 1. sbt 0.13.6 2. play 2.10 3. scala 2.11.2 4. play2-reactivamongo 0.10.2 5. mongodb 2.6.4

data post json, , create case class model, , using jspath convert json entity class.

this sample code :

def insertransaction = action(parser.json) { implicit request => val json = request.body val info = json.as[transaction] logger.info(data.tostring) val future = collection.insert(data.copy(id = option[bsonobjectid](bsonobjectid.generate))) var result = "" future.oncomplete { case failure(t) => result = "an error has occured: " + t.getmessage case success(post) => result = "success" } ok(result) }

i've seen sample code used action.sync handling asynchronous in controllers, when seek utilize action.sync, intellij ide observe error "cannot resolve action.sync signature", i've tried alter result of function this

future.oncomplete { case failure(t) => ok("an error has occured: " + t.getmessage) case success(post) => ok("success") }

so decided utilize action(parser.json) , issue came activator play tell me should utilize "import play.api.libs.concurrent.execution.implicits._" in code. when import libraries, came new error :

! internal server error, (post) [/insertdata] -> java.lang.exceptionininitializererror: null .... caused by: play.api.playexception: reactivemongoplugin error[the reactivemongoplugin has not been initialized! please edit conf/play.plugins file , add together next line....

when tried reload request, showed error :

! internal server error, (post) [/api/insertdata] -> java.lang.noclassdeffounderror: not initialize class controllers.transactioncontroller$ [error] application - error while rendering default error page scala.matcherror: java.lang.noclassdeffounderror: not initialize class controllers.transactioncontroller$ (of class java.lang.noclassdeffounderror)

anyone have solution problem?

this question might help: are there benefits in using non-async actions in play framework 2.2?

action vs action.async

if think of actions @ high level take , input , produce output these 2 same thing different. both of these take in request , output results. action.async allows action code deal futures. skipping on details hope helps.

can paste plugins file?

json scala asynchronous playframework play-reactivemongo

No comments:

Post a Comment