Hi there,
I had a working solution that was fine for struts1 and doesn't work with
struts2.
The scenario is evey time the application needs to send a mail from an
action (for example, when a user signs up, the system sends him a welcome
mail)

My solution got the JSP the following way:

        public String getResourceAsString(String path) throws ServletException,
IOException
        {
                HttpServletRequest request =
org.apache.struts2.ServletActionContext.getRequest();
                HttpServletResponse response = 
ServletActionContext.getResponse();
                try
                {
                        ByteArrayOutputStream out = new ByteArrayOutputStream();
                        RequestDispatcher dispatcher = 
request.getRequestDispatcher(path);
                        RedirectingServletResponse dummyResponse = new
RedirectingServletResponse(response, out);
                        dispatcher.include(request, dummyResponse);
                        return out.toString();
                } catch (NullPointerException e)
                {
                        return "<p>No such template: " + path + "</p>";
                }
        }
 
(RedirectingServletResponse class just extends HttpServletResponseWrapper
and captures output to a ByteArrayOutputStream)


The JSP needs a small scriptlet at its end:
<% out.flush(); %>

Without it, the mail is sent blank as the JSP is not rendered to HTML/text
as the request has not ended (I use the current thread request because: 1) I
don't know how to create a brand new request/response 2) This way I can use
all request parameters, attributes... in the mail sent and so not use just
plain HTML but real JSP.

The problem now is that struts2 shows the following exception:

java.io.IOException: Stream closed

   
org.apache.jasper.runtime.JspWriterImpl.ensureOpen(JspWriterImpl.java:204)
   
org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:115)
    org.apache.jasper.runtime.JspWriterImpl.flush(JspWriterImpl.java:173)
   
org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:956)
   
org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:609)
   
org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:123)
   
org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
   
com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:361)
   
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:265)
   
com.servengine.struts2.InjectEJBInterceptor.intercept(InjectEJBInterceptor.java:89)
   
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
   
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
   
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:468)
   
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
   
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206

Any ideas on this... or better... any directions on how can I instanciate a
"fake" response not based on current struts2 Action ServletResponse object
(and so flush() or close() will not affect it).

Thanks,
Ignacio
-- 
View this message in context: 
http://www.nabble.com/How-to-render-a-JSP-Struts2-action-to-send-it-%28mail%2C-...%29-tp21982445p21982445.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to