playframework 2.0 - Play 2.4 java.lang.RuntimeException: There is no HTTP Context available from here -
i have application. on application start wake akka actor every 24 second. actor iterates through entities within jpa.withtransaction, job , sends email users.
the problem within jpa.withtransaction method when calling render method (using render scala template) runtime exception thrown: there no htto context available here
[error] - akka.actor.oneforonestrategy - jpa transaction failed 11:50:42 worker.1 | java.lang.runtimeexception: jpa transaction failed 11:50:42 worker.1 | @ play.db.jpa.defaultjpaapi.withtransaction(defaultjpaapi.java:107) ~[play-java-jpa_2.11-2.4.6.jar:2.4.6] 11:50:42 worker.1 | @ play.db.jpa.jpa.withtransaction(jpa.java:148) ~[play-java-jpa_2.11-2.4.6.jar:2.4.6] 11:50:42 worker.1 | @ utils.medicalvalidityactor.onreceive(medicalvalidityactor.java:35) ~[classes/:na] 11:50:42 worker.1 | @ akka.actor.untypedactor$$anonfun$receive$1.applyorelse(untypedactor.scala:167) ~[akka-actor_2.11-2.3.13.jar:na] 11:50:42 worker.1 | @ akka.actor.actor$class.aroundreceive(actor.scala:467) ~[akka-actor_2.11-2.3.13.jar:na] 11:50:42 worker.1 | @ akka.actor.untypedactor.aroundreceive(untypedactor.scala:97) ~[akka-actor_2.11-2.3.13.jar:na] 11:50:42 worker.1 | @ akka.actor.actorcell.receivemessage(actorcell.scala:516) [akka-actor_2.11-2.3.13.jar:na] 11:50:42 worker.1 | @ akka.actor.actorcell.invoke(actorcell.scala:487) [akka-actor_2.11-2.3.13.jar:na] 11:50:42 worker.1 | @ akka.dispatch.mailbox.processmailbox(mailbox.scala:238) [akka-actor_2.11-2.3.13.jar:na] 11:50:42 worker.1 | @ akka.dispatch.mailbox.run(mailbox.scala:220) [akka-actor_2.11-2.3.13.jar:na] 11:50:42 worker.1 | @ akka.dispatch.forkjoinexecutorconfigurator$akkaforkjointask.exec(abstractdispatcher.scala:397) [akka-actor_2.11-2.3.13.jar:na] 11:50:42 worker.1 | @ scala.concurrent.forkjoin.forkjointask.doexec(forkjointask.java:260) [scala-library-2.11.6.jar:na] 11:50:42 worker.1 | @ scala.concurrent.forkjoin.forkjoinpool$workqueue.runtask(forkjoinpool.java:1339) [scala-library-2.11.6.jar:na] 11:50:42 worker.1 | @ scala.concurrent.forkjoin.forkjoinpool.runworker(forkjoinpool.java:1979) [scala-library-2.11.6.jar:na] 11:50:42 worker.1 | @ scala.concurrent.forkjoin.forkjoinworkerthread.run(forkjoinworkerthread.java:107) [scala-library-2.11.6.jar:na] 11:50:42 worker.1 | caused by: java.lang.runtimeexception: there no http context available here. 11:50:42 worker.1 | @ play.mvc.http$context.current(http.java:57) ~[play_2.11-2.4.6.jar:2.4.6] 11:50:42 worker.1 | @ play.mvc.http$context$implicit.ctx(http.java:308) ~[play_2.11-2.4.6.jar:2.4.6] 11:50:42 worker.1 | @ play.core.j.playmagicforjava$.requestheader(templatemagicforjava.scala:58) ~[play-java_2.11-2.4.6.jar:2.4.6] 11:50:42 worker.1 | @ views.html.emailtemplatemedicalvalidity_scope0$emailtemplatemedicalvalidity.apply(emailtemplatemedicalvalidity.template.scala:77) ~[classes/:na] 11:50:42 worker.1 | @ views.html.emailtemplatemedicalvalidity_scope0$emailtemplatemedicalvalidity.render(emailtemplatemedicalvalidity.template.scala:113) ~[classes/:na] 11:50:42 worker.1 | @ views.html.emailtemplatemedicalvalidity.render(emailtemplatemedicalvalidity.template.scala) ~[classes/:na] 11:50:42 worker.1 | @ utils.medicalvalidityactor$1.invoke(medicalvalidityactor.java:97) ~[classes/:na] 11:50:42 worker.1 | @ play.db.jpa.defaultjpaapi.lambda$withtransaction$1(defaultjpaapi.java:103) ~[play-java-jpa_2.11-2.4.6.jar:2.4.6] 11:50:42 worker.1 | @ play.db.jpa.defaultjpaapi.withtransaction(defaultjpaapi.java:136) ~[play-java-jpa_2.11-2.4.6.jar:2.4.6] 11:50:42 worker.1 | @ play.db.jpa.defaultjpaapi.withtransaction(defaultjpaapi.java:102) ~[play-java-jpa_2.11-2.4.6.jar:2.4.6] 11:50:42 worker.1 | ... 14 common frames omitted
this code:
public class medicalvalidityactor extends untypedactor { @inject httpexecutioncontext ec; @transactional public void onreceive(object message) { if (message instanceof checkmedicalvalidity) { // start jpa.withtransaction(new play.libs.f.callback0() { @override public void invoke() throws throwable { //get today , add 1 month date todayplusmonth = new date(); todayplusmonth = dateutils.addmonths(todayplusmonth, 1); list<organization> organizationlist = organization.findall(); for(organization organization : organizationlist){ list<player> playerlist = playermanager.findallactivedomesticplayersbyorganization(organization); // list containing players specific organization have invalid medical arraylist<player> playersinvalidmedical = new arraylist<>(); for(player player : playerlist){ system.out.println(organization.getname() + " " + player.getfirstname() + " " + player.getlastname() + " " + player.getmedicalvalidityformatted()); if(player.getmedicalvalidity() != null && !player.ismedicalvalid()) { // medical not valid anymore playersinvalidmedical.add(player); } else if(player.getmedicalvalidity() != null && todayplusmonth.after(player.getmedicalvalidity())) { // medical not valid anymore playersinvalidmedical.add(player); player.setmedicalvalid(false); } } // send notification users medical validity if(!playersinvalidmedical.isempty()) { system.out.println("potekli: " + playersinvalidmedical.size()); // recipients organization list<enduser> endusers = endusermanager.findbyorganization(organization); arraylist<string> recipients = new arraylist<>(); for(enduser enduser : endusers){ if(enduser.getroles().get(0).getname().equals(securityrole.administrator) || enduser.getroles().get(0).getname().equals(securityrole.secretary) || enduser.getroles().get(0).getname().equals(securityrole.coach) || enduser.getroles().get(0).getname().equals(securityrole.head)) { // add recipients recipients.add(enduser.getemail()); } } system.out.println("1"); // initialize not initialized every iteration emailutilsmailgun mailgunutils = new emailutilsmailgun(); system.out.println("2"); string emailtemplate = emailtemplatemedicalvalidity.render(organization, playersinvalidmedical).tostring(); system.out.println("3"); mailgunutils.sendemailtowithoutattachmenet(emailtemplate, organization.getname(), organization.getemail(), "potekli zdravniški pregledi", recipients); system.out.println("4"); } } } }); } } }
Comments
Post a Comment