java.net.URI中的Grails NPE $ Parser.parse()在Quartz中发送邮件时

时间:2016-03-09 07:33:29

标签: java grails nullpointerexception uri javamail

我们有预定的发票服务,我们会将发票发送给客户的电子邮件。

asynchronousMailService.sendMail {
            multipart true
            to emailTo.split("[,;]")
            bcc bccString
            from fromString
            subject subjectString
            html view:'/email/invoiceEmailTemplate',
                    model: [companyName: companyName, customerFirstName:  order.customer.firstName,
                            xeroInvoiceId: invoice.invoiceNumber, invoiceTotal: order.totalAmount,
                            invoiceUrl: invoiceUrl,
                            currencyCode: invoice.currencyCode, dueDate: invoice.dueDate]
            attachBytes invoice.invoiceNumber+".pdf" , 'application/pdf', invoiceBytes
        }

导致此错误:

2016-03-09 18:22:23,073 [quartzScheduler_Worker-10] ERROR listeners.ExceptionPrinterJobListener  - Exception occurred in job: Grails Job
        org.quartz.JobExecutionException: java.lang.NullPointerException [See nested exception: java.lang.NullPointerException]
                at grails.plugins.quartz.GrailsJobFactory$GrailsJob.execute(GrailsJobFactory.java:111)
                at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
                at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
        Caused by: java.lang.NullPointerException
                at java.net.URI$Parser.parse(URI.java:3023)
                at java.net.URI.<init>(URI.java:595)
                at grails.plugin.mail.MailMessageContentRenderer$PageRenderRequestCreator.createInstance(MailMessageContentRenderer.groovy:198)
                at grails.plugin.mail.MailMessageContentRenderer$RenderEnvironment.init(MailMessageContentRenderer.groovy:147)
                at grails.plugin.mail.MailMessageContentRenderer$RenderEnvironment.with(MailMessageContentRenderer.groovy:178)
                at grails.plugin.mail.MailMessageContentRenderer.render(MailMessageContentRenderer.groovy:63)
                at grails.plugin.asyncmail.AsynchronousMailMessageBuilder.doRender(AsynchronousMailMessageBuilder.groovy:281)
                at grails.plugin.asyncmail.AsynchronousMailMessageBuilder.html(AsynchronousMailMessageBuilder.groovy:267)
                at com.mycompany.thirdparty.InvoiceService$_emailInvoiceToCustomer_closure5.doCall(InvoiceService.groovy:118)
                at grails.plugin.asyncmail.AsynchronousMailService.sendAsynchronousMail(AsynchronousMailService.groovy:21)
                at AsynchronousMailGrailsPlugin$_configureSendMail_closure9.doCall(AsynchronousMailGrailsPlugin.groovy:132)
                at com.mycompany.thirdparty.InvoiceService.emailInvoiceToCustomer(InvoiceService.groovy:112)
                at com.mycompany.thirdparty.InvoiceService$_createInvoice_closure2.doCall(InvoiceService.groovy:47)
                at grails.plugin.multitenant.core.MultiTenantService$_doWithTenantId_closure1_closure2.doCall(MultiTenantService.groovy:32)
                at grails.plugin.hibernatehijacker.template.HibernateTemplates$_withTransaction_closure1.doCall(HibernateTemplates.groovy:39)
                at grails.plugin.hibernatehijacker.template.HibernateTemplates.withTransaction(HibernateTemplates.groovy:37)
                at grails.plugin.multitenant.core.MultiTenantService$_doWithTenantId_closure1.doCall(MultiTenantService.groovy:31)
                at grails.plugin.hibernatehijacker.template.HibernateTemplates$_withNewSession_closure2.doCall(HibernateTemplates.groovy:65)
                at grails.plugin.hibernatehijacker.template.HibernateTemplates.withNewSession(HibernateTemplates.groovy:57)
                at grails.plugin.multitenant.core.MultiTenantService.doWithTenantId(MultiTenantService.groovy:30)
                at grails.plugin.multitenant.singledb.MtSingleDbPluginSupport$_createWithTenantIdMethod_closure2.doCall(MtSingleDbPluginSupport.groovy:141)
                at com.mycompany.thirdparty.InvoiceService.createInvoice(InvoiceService.groovy:38)
                at com.mycompany.thirdparty.InvoiceJob.execute(InvoiceJob.groovy:13)
                at grails.plugins.quartz.GrailsJobFactory$GrailsJob.execute(GrailsJobFactory.java:102)

上述错误日志只发生在生产服务器上,我在本地计算机和开发服务器上复制没有成功。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

我在这里回答了一个问题:Grails Mail service not working with guartz scheduler in war mode

AsyncMail无法获取服务器的URL。最简单的方法是通过grails.serverURL config属性配置它。