Shwetanka
Shwetanka

Reputation: 5036

Lift InstantiationException

Here is my code -

def sendAcceptInvitationMail(invitation: Invitation) {
  val signupLink = Props.get("base.url").openOr("http://localhost:8080") + "/accounts/signup?code="+invitation.code.is
  S.eval(<lift:embed what="/templates-hidden/emails/accept_invitation">
            <lift:bind-at name="name">{invitation.name.is}</lift:bind-at>
            <lift:bind-at name="link"><a href={signupLink}>{signupLink}</a></lift:bind-at>
        </lift:embed>) match {
    case Full(msg) =>
      MailHelper.sendMail((invitation.email.is, invitation.name.is), S.?("subject.invitation.sent"), msg, MimeType.MIME_HTML)
      debug("Accept invitation mail sent for: "+invitation.email.is)

    case _ => warn("Invitation Accept Email not sent to: "+invitation.email.is+". Problem preparing message")
  }
}

I'm getting this exception.

Message: java.lang.InstantiationException: com.lgigs.admin.view.Admin
java.lang.Class.newInstance0(Class.java:357)
java.lang.Class.newInstance(Class.java:325)
net.liftweb.http.Templates$$anonfun$lookForClasses$1$$anonfun$apply$9.apply(Templates.scala:264)
net.liftweb.http.Templates$$anonfun$lookForClasses$1$$anonfun$apply$9.apply(Templates.scala:263)
net.liftweb.common.Full.flatMap(Box.scala:493)
net.liftweb.http.Templates$$anonfun$lookForClasses$1.apply(Templates.scala:262)
net.liftweb.http.Templates$$anonfun$lookForClasses$1.apply(Templates.scala:260)
scala.Function1$$anonfun$andThen$1.apply(Function1.scala:49)
scala.collection.immutable.Stream.flatMap(Stream.scala:217)
net.liftweb.util.ListHelpers$class.first(ListHelpers.scala:137)
net.liftweb.util.Helpers$.first(Helpers.scala:34)
net.liftweb.http.Templates$.lookForClasses(Templates.scala:259)
net.liftweb.http.Templates$.findRawTemplate(Templates.scala:245)
net.liftweb.http.Templates$.apply(Templates.scala:85)
net.liftweb.http.DefaultRoutines$.rawResBundle(DefaultRoutines.scala:43)
net.liftweb.http.DefaultRoutines$.net$liftweb$http$DefaultRoutines$$resBundleFor(DefaultRoutines.scala:59)
net.liftweb.http.DefaultRoutines$$anonfun$3.apply(DefaultRoutines.scala:104)
net.liftweb.http.DefaultRoutines$$anonfun$3.apply(DefaultRoutines.scala:101)
net.liftweb.common.Full.flatMap(Box.scala:493)
net.liftweb.http.DefaultRoutines$.resourceForCurrentReq(DefaultRoutines.scala:101)
net.liftweb.http.LiftRules$$anon$13$$anonfun$$init$$14$$anonfun$apply$14.apply(LiftRules.scala:785)
net.liftweb.http.LiftRules$$anon$13$$anonfun$$init$$14$$anonfun$apply$14.apply(LiftRules.scala:785)
net.liftweb.http.S$class.resourceBundles(S.scala:884)
net.liftweb.http.S$.resourceBundles(S.scala:48)
net.liftweb.http.S$class.resourceBundles(S.scala:878)
net.liftweb.http.S$.resourceBundles(S.scala:48)
net.liftweb.http.S$class.$qmark(S.scala:928)
net.liftweb.http.S$.$qmark(S.scala:48)
com.lgigs.admin.snippet.Admin.sendAcceptInvitationMail$1(Admin.scala:129)
com.lgigs.admin.snippet.Admin$$anonfun$save$1$2.apply(Admin.scala:148)
com.lgigs.admin.snippet.Admin$$anonfun$save$1$2.apply(Admin.scala:141)
scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.

I debugged and found out that while reading property from resource using S.?('subject.invitation.sent') throws this exception. But I'm using the same function call in many other snippets and not having any exceptions. Need help with this.

Upvotes: 0

Views: 137

Answers (1)

jcern
jcern

Reputation: 7848

Most of the items in the S package require that a valid session be available to it, and that normally requires that access happen in the same thread as the Http request. Is MailHelper something you wrote? I know that lift's Mailer.sendMail happens asynchronously through an actor, so that may have something to do with it.

One thing you might try, if you haven't already, is retrieving the translation earlier. Something like:

case Full(msg) =>
      val i18nConfirmation = S.?("subject.invitation.sent")
      MailHelper.sendMail((invitation.email.is, invitation.name.is), i18nConfirmation, msg, MimeType.MIME_HTML)
      debug("Accept invitation mail sent for: "+invitation.email.is)

Upvotes: 1

Related Questions