1

I am trying to use grails mail plugin in service. It works fine in grails environment (using "grails run-app") but when I deploy war in standalone tomcat, I get NPE.

my config file:

plugins {
   // plugins for the build system only
    build ":tomcat:7.0.54"
// plugins for the compile step
compile ":scaffolding:2.1.2"
compile ':cache:1.1.7'
compile ":asset-pipeline:1.8.11"
compile ":mail:1.0.7"
compile ":quartz:1.0.2"
compile ":quartz-monitor:1.0"
compile ":eclipse-scripts:1.0.7"
//runtime ":cors:1.1.6"

//runtime 'org.springframework.security:spring-security-ldap:3.2.4.RELEASE'
// plugins needed at runtime but not for compilation
runtime ":hibernate4:4.3.5.4" // or ":hibernate:3.6.10.15"
runtime ":database-migration:1.4.0"
runtime ":jquery:1.11.1"
//runtime ':db-reverse-engineer:0.5'
compile ":jms:1.3"

runtime ":resources:1.2.8"
runtime ":cached-resources:1.0"
runtime ":zipped-resources:1.0"
runtime ":yui-minify-resources:0.1.5"
compile ":cache-headers:1.1.7"
compile ":marshallers:0.6"

}

mailsend in service file:

log.info "using view.."
sendMail {
        to "${userDetails.email}"
        subject "Your request was successfully processed."
        html view:'/SuccessMailView',model: [title:"${req.title}",DESC:"${req.description}"]
    }

Error: I double checked that "SuccessMailView.gsp" is present under "views" folder and it sends mail in grails environment just fine. To generate war, I used "grails dev war" and then copied the file to tomcat webapps dir. Tomcat is on same host as my grails but running on different port. I also tried

body( view:'/SuccessMailView',model: [title:"${req.title}",DESC:"${req.description}"])

but same error.

java.lang.NullPointerException
        at java.net.URI$Parser.parse(URI.java:3023)
        at java.net.URI.<init>(URI.java:595)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
        at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190)
        at grails.plugin.mail.MailMessageContentRenderer$PageRenderRequestCreator.createInstance(MailMessageContentRenderer.groovy:198)
        at grails.plugin.mail.MailMessageContentRenderer$PageRenderRequestCreator$createInstance.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
        at grails.plugin.mail.MailMessageContentRenderer$RenderEnvironment.init(MailMessageContentRenderer.groovy:147)
        at grails.plugin.mail.MailMessageContentRenderer$RenderEnvironment.this$2$init(MailMessageContentRenderer.groovy)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:207)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:68)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
        at grails.plugin.mail.MailMessageContentRenderer$RenderEnvironment.with(MailMessageContentRenderer.groovy:178)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
        at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:148)
        at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:88)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
        at grails.plugin.mail.MailMessageContentRenderer.render(MailMessageContentRenderer.groovy:63)
        at grails.plugin.mail.MailMessageContentRenderer$render.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
        at grails.plugin.mail.MailMessageBuilder.doRender(MailMessageBuilder.groovy:277)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:207)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:56)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
        at grails.plugin.mail.MailMessageBuilder.html(MailMessageBuilder.groovy:295)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1085)
        at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:997)
        at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
        at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
user3741611
  • 327
  • 2
  • 16
  • Just a hunch gsps usually start lowercase - can you try to rename it to _successMailView.gsp and call view:'/successMailView', Also ... According to http://grails.org/plugin/mail If your HTML is contained within a GSP template html g.render(template:"myMailTemplate"). My suggestion would be to start simple without templates if it works then its your templates.. https://github.com/gpc/grails-mail/blob/master/src/groovy/grails/plugin/mail/MailMessageContentRenderer.groovy#L147 this is where your first error points to – V H Mar 20 '15 at 13:56
  • I tried with lowercase but no difference, I got same error. This is not a temple but just to try it out I have also added another file under /views folder with '_successMailView.gsp'...no luck. – user3741611 Mar 20 '15 at 15:16
  • I can't use g.render as 'g.' won't work in services. Yes, I looked at the source file but could not figure out why it is throwing error there. Since the error is "NPE at java.net.URI$Parser.parse", If I remove leading '/' in view path just to see if the view i.e just give 'view:'successMailView', I see error: 'IllegalArgumentException: Mail views cannot be loaded from relative view paths where there is no current HTTP request'.... so view parameter is being passed and not NULL. – user3741611 Mar 20 '15 at 15:24
  • try def g = new org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib() def gotourl= g.createLink(controller: 'something', action: 'showall', params: params, absolute: 'true') -thats an exampleI have in a service – V H Mar 20 '15 at 16:05

1 Answers1

2

finally this worked for me (from another post)

   // inject the service
   def groovyPageRenderer

   def content = groovyPageRenderer.render(view: 'SuccessMailView', model: [title:"${req.title}",DESC:"${req.description}"])

        mailService.sendMail {
            to user.email
            from "email@test.com"
            subject "MySubject"
            html(content)
        }
Community
  • 1
  • 1
user3741611
  • 327
  • 2
  • 16