You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Hoying, Ken" <Ke...@PremierInc.com> on 2007/08/02 13:40:27 UTC

[S2] Design Advice Needed

I could use some advice from some folks with more experience and
knowledge of Struts2 than I to assist me in determining the correct way
(or lay out some viable options) to design a solution for the following
senario:

We need to generate a PDF report real time based on data in a database
that is available for download.  What we believe that we would like to
do is utilize FOP (http://xmlgraphics.apache.org/fop/) and use a JSP
page to actually generate the formatting objects and then run the
formatting objects through the FOP processor to generate and stream the
PDF back to the user.  

However, we are not real sure how to implement this in Struts2.  How do
we invoke the JSP page and then get access to the results?  Do we just
use the stream result type and then use a http call to the JSP as the
input source?  This would seem like it would not be optimal from a
performance standpoint, as we are making another http call to get the
formatting objects from the jsp.  It also adds the complexity of passing
security credentials in the call.  Or do we need to somehow create or
own result type and if so how do we get those JSP results?  I have not
really found any good documentation or example on writing your own
result types.

Thanks in advance!



-----------------------------------------
***Note:The information contained in this message may be privileged
and confidential and protected from disclosure. If the reader of
this message is not the intended recipient, or an employee or agent
responsible for delivering this message to the intended recipient,
you are hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited. If you have
received this communication in error, please notify the Sender
immediately by replying to the message and deleting it from your
computer. Thank you. Premier Inc.  

RE: [S2] Design Advice Needed

Posted by "Hoying, Ken" <Ke...@PremierInc.com>.
Thanks, Rene!

I actually just found that after sending my question.  Somehow I missed
it earlier.  We are definitely going to take a look at Jasper and the
plugin as it appears a lot of the heavy lifting may already be done for
us. 

Thank you!

-----Original Message-----
From: Rene Gielen [mailto:gielen@it-neering.net] 
Sent: Thursday, August 02, 2007 8:07 AM
To: Struts Users Mailing List
Subject: Re: [S2] Design Advice Needed

You should definitely have a look into the struts2-jasperreports-plugin
- both for checking out how to write own results and evaluating if you
might want to use jasper over FOP, since full s2 result support is
already available for jasper.

The plugin is part of the struts2 source distribution.

Regards,
Rene

Hoying, Ken schrieb:
> I could use some advice from some folks with more experience and 
> knowledge of Struts2 than I to assist me in determining the correct 
> way (or lay out some viable options) to design a solution for the 
> following
> senario:
> 
> We need to generate a PDF report real time based on data in a database

> that is available for download.  What we believe that we would like to

> do is utilize FOP (http://xmlgraphics.apache.org/fop/) and use a JSP 
> page to actually generate the formatting objects and then run the 
> formatting objects through the FOP processor to generate and stream 
> the PDF back to the user.
> 
> However, we are not real sure how to implement this in Struts2.  How 
> do we invoke the JSP page and then get access to the results?  Do we 
> just use the stream result type and then use a http call to the JSP as

> the input source?  This would seem like it would not be optimal from a

> performance standpoint, as we are making another http call to get the 
> formatting objects from the jsp.  It also adds the complexity of 
> passing security credentials in the call.  Or do we need to somehow 
> create or own result type and if so how do we get those JSP results?  
> I have not really found any good documentation or example on writing 
> your own result types.
> 
> Thanks in advance!
> 
> 
> 
> -----------------------------------------
> ***Note:The information contained in this message may be privileged 
> and confidential and protected from disclosure. If the reader of this 
> message is not the intended recipient, or an employee or agent 
> responsible for delivering this message to the intended recipient, you

> are hereby notified that any dissemination, distribution or copying of

> this communication is strictly prohibited. If you have received this 
> communication in error, please notify the Sender immediately by 
> replying to the message and deleting it from your computer. Thank you.

> Premier Inc.

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


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


Re: [S2] Design Advice Needed

Posted by Rene Gielen <gi...@it-neering.net>.
You should definitely have a look into the struts2-jasperreports-plugin
- both for checking out how to write own results and evaluating if you
might want to use jasper over FOP, since full s2 result support is
already available for jasper.

The plugin is part of the struts2 source distribution.

Regards,
Rene

Hoying, Ken schrieb:
> I could use some advice from some folks with more experience and
> knowledge of Struts2 than I to assist me in determining the correct way
> (or lay out some viable options) to design a solution for the following
> senario:
> 
> We need to generate a PDF report real time based on data in a database
> that is available for download.  What we believe that we would like to
> do is utilize FOP (http://xmlgraphics.apache.org/fop/) and use a JSP
> page to actually generate the formatting objects and then run the
> formatting objects through the FOP processor to generate and stream the
> PDF back to the user.  
> 
> However, we are not real sure how to implement this in Struts2.  How do
> we invoke the JSP page and then get access to the results?  Do we just
> use the stream result type and then use a http call to the JSP as the
> input source?  This would seem like it would not be optimal from a
> performance standpoint, as we are making another http call to get the
> formatting objects from the jsp.  It also adds the complexity of passing
> security credentials in the call.  Or do we need to somehow create or
> own result type and if so how do we get those JSP results?  I have not
> really found any good documentation or example on writing your own
> result types.
> 
> Thanks in advance!
> 
> 
> 
> -----------------------------------------
> ***Note:The information contained in this message may be privileged
> and confidential and protected from disclosure. If the reader of
> this message is not the intended recipient, or an employee or agent
> responsible for delivering this message to the intended recipient,
> you are hereby notified that any dissemination, distribution or
> copying of this communication is strictly prohibited. If you have
> received this communication in error, please notify the Sender
> immediately by replying to the message and deleting it from your
> computer. Thank you. Premier Inc.  

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


Re: [S2] Design Advice Needed

Posted by Mike Baroukh <mb...@cardiweb.com>.
I suppose there is a lot of other way to generate pdf with struts2. 
Certainly a plugin. But I don't know how it works.

However, to invoke a jsp and get the result in your action, you can use 
a requestDispatcher to obtain the resut of a jsp execution.

Here is something I already done with struts1. I have problems now with 
struts2's request dispatcher. So I don't know if it still work ...


request.setAttribute("param1", valuepram1);
...
Eventally, had a path to an embeded image :
request.setAttribute("logo", 
MyActionClass.class.getClassLoader().getResource("/path/to/th/logo.gif").getFile());

ResponseWrapper responseWrapper = new ResponseWrapper(response);


getServlet().getServletContext().getRequestDispatcher("path/to/the/fop-jsp.jsp").include(request, 
responseWrapper).include(request, responseWrapper);

you can use now
byte[] bytes = responseWrapper.getBytes();
to get the file generated by the jsp.


responseWrapper is a simple class like :


public static class ResponseWrapper extends HttpServletResponseWrapper {

         private ByteArrayOutputStream baos = new ByteArrayOutputStream();
         private ServletOutputStream sos = new ServletOutputStream() {
                         public void write(int b) throws IOException {
                                 baos.write(b);
                         }
         };
         private PrintWriter osw = new PrintWriter(new 
OutputStreamWriter(baos));
                 public ResponseWrapper(HttpServletResponse response) {
                         super(response);
                 }

                 public ServletOutputStream getOutputStream() throws 
IOException {
                         return sos;
                 }

                 public PrintWriter getWriter() throws IOException {
                         return osw;
                 }

                 public byte[] getBytes() {
                         osw.flush();
                         return baos.toByteArray();
                 }

     }

Hoying, Ken a écrit :
> I could use some advice from some folks with more experience and
> knowledge of Struts2 than I to assist me in determining the correct way
> (or lay out some viable options) to design a solution for the following
> senario:
> 
> We need to generate a PDF report real time based on data in a database
> that is available for download.  What we believe that we would like to
> do is utilize FOP (http://xmlgraphics.apache.org/fop/) and use a JSP
> page to actually generate the formatting objects and then run the
> formatting objects through the FOP processor to generate and stream the
> PDF back to the user.  
> 
> However, we are not real sure how to implement this in Struts2.  How do
> we invoke the JSP page and then get access to the results?  Do we just
> use the stream result type and then use a http call to the JSP as the
> input source?  This would seem like it would not be optimal from a
> performance standpoint, as we are making another http call to get the
> formatting objects from the jsp.  It also adds the complexity of passing
> security credentials in the call.  Or do we need to somehow create or
> own result type and if so how do we get those JSP results?  I have not
> really found any good documentation or example on writing your own
> result types.
> 
> Thanks in advance!
> 
> 
> 
> -----------------------------------------
> ***Note:The information contained in this message may be privileged
> and confidential and protected from disclosure. If the reader of
> this message is not the intended recipient, or an employee or agent
> responsible for delivering this message to the intended recipient,
> you are hereby notified that any dissemination, distribution or
> copying of this communication is strictly prohibited. If you have
> received this communication in error, please notify the Sender
> immediately by replying to the message and deleting it from your
> computer. Thank you. Premier Inc.  

-- 

Mike Baroukh

---
Cardiweb  - 31 Rue de Mogador Paris IXeme
06 63 57 27 22 - 01 53 21 82 63 - Jabber: mbaroukh@jabber.org
http://www.cardiweb.com
---


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