我正在尝试将发送通知电子邮件与导致它们的事件分开。到目前为止,我将一个邮件对象(DocumentIssuedMail
)从控制器传递给Akka actor(EmailDispatcher
),然后通过Play邮件插件的play-easymail包装器发送邮件。邮件正文在传递给actor后由邮件对象生成,HTML是从Scala模板生成的。
此模板包含通过调用
获得的绝对URL链接@routes.SomeController.someAction().absoluteURL()
但是,我在尝试渲染模板时遇到了RuntimeException。
堆栈跟踪如下:
java.lang.RuntimeException: There is no HTTP Context available from here.
at play.mvc.Http$Context.current(Http.java:30)
at play.mvc.Http$Context$Implicit.ctx(Http.java:196)
at play.core.j.PlayMagicForJava$.requestHeader(TemplateMagicForJava.scala:56)
at views.html.email._learner_main$.apply(_learner_main.template.scala:41)
at views.html.documents.email.new_doc_unregistered$.apply(new_doc_unregistered.template.scala:47)
at views.html.documents.email.new_doc_unregistered$.render(new_doc_unregistered.template.scala:67)
at views.html.documents.email.new_doc_unregistered.render(new_doc_unregistered.template.scala)
at email.DocumentIssuedMail.getUnregisteredMail(DocumentIssuedMail.java:71)
at email.DocumentIssuedMail.getMail(DocumentIssuedMail.java:67)
at actors.email.EmailDispatcher.onReceive(EmailDispatcher.java:32)
at akka.actor.UntypedActor$$anonfun$receive$1.applyOrElse(UntypedActor.scala:167)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:498)
at akka.actor.ActorCell.invoke(ActorCell.scala:456)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:237)
at akka.dispatch.Mailbox.run(Mailbox.scala:219)
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)
是否可以在该位置呈现模板,或者我是否需要在原始线程上执行该模板?