1 Reply Latest reply on Dec 21, 2007 1:02 PM by Pete Muir

    Rendering email from a servlet

    Tim Timson Newbie

      I am trying to send html email from a servlet and could use some help.

      I have added the following to my components.xml file as described in chapter 21 of the reference manual (Section 21.1.2.5. Context management for custom servlets):

      <web:context-filter url-pattern="/servlet/*" />


      With the above in place, my servlet can retrieve a non-null Renderer (org.jboss.seam.core.Renderer) using the following:
      Renderer renderer = (Renderer) Component.getInstance("org.jboss.seam.core.renderer");


      I then try to use the renderer:
      renderer.render("/WEB-INF/email/test-email.xhtml");

      but this throws an exception as shown in the stacktrace below. Do I need to somehow provide more context for the renderer? Note that for this test the xhtml file has no dynamic content, although I am hoping to make it dynamic at some point. Any suggestions would be appreciated.

      The following is the stack trace that results from the call to the renderer:
      java.lang.NullPointerException
      at com.sun.faces.application.ApplicationAssociate.(ApplicationAssociate.java:143)
      at com.sun.faces.application.ApplicationImpl.(ApplicationImpl.java:156)
      at com.sun.faces.application.ApplicationFactoryImpl.getApplication(ApplicationFactoryImpl.java:97)
      at org.jboss.seam.mock.MockFacesContext.(MockFacesContext.java:62)
      at org.jboss.seam.ui.facelet.FaceletsRenderer$Context.wrap(FaceletsRenderer.java:59)
      at org.jboss.seam.ui.facelet.FaceletsRenderer.render(FaceletsRenderer.java:110)
      at com.el.util.mail.EmailServlet.processRequest(EmailServlet.java:54)
      at com.el.util.mail.EmailServlet.doGet(EmailServlet.java:82)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:718)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
      at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:317)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
      at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:63)
      at org.jboss.seam.web.ContextFilter.doFilter(ContextFilter.java:56)
      at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
      at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:57)
      at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
      at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:60)
      at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
      at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
      at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
      at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:79)
      at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
      at org.jboss.seam.web.SeamFilter.doFilter(SeamFilter.java:84)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
      at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:288)
      at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
      at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
      at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
      at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
      at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
      at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
      at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
      at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
      at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:270)
      at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
      at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
      at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
      at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:339)
      at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:261)
      at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:212)
      at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:361)
      at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
      at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)

        • 1. Re: Rendering email from a servlet
          Pete Muir Master

          I've not tested this, and see several ways in which it might fail (you don't have a full faces environment available, and as I haven't coded for it some of the needed mocks may not be available).

          File a JIRA issue and I can try to take a look, but I'm not going to get around to it soon.