tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alan Chaney <a...@compulsivecreative.com>
Subject Re: How can I refresh tomcat in the java code?
Date Thu, 03 Apr 2008 14:07:01 GMT
Chris

Very nicely put. The only thing that I'm not clear on is your comment 
about sending the data as a String. The OP is trying to return a pdf 
file, which is a byte stream. I'd worry about trying to wrap that in a 
String because of encoding issues.


You make a good point about two simultaneous requests breaking the app. 
The other issue is of course that Jasper isn't necessarily that quick at 
creating a report and the report generation is in line with the servlet 
request and response.

A more sophisticated solution would probably follow a pattern of:

1. Respond to request.
2. Schedule a process (thread) to create report.
3. Return from the request saying something like "Your report is being 
prepared..."
4. When the process in 2. is complete send an email saying "please go to 
... to pick up your report."

You can then make a design decision as to whether or not you want the 
report generating process to allow multiple instances to run or not 
(probably not in most cases).

Another tweak is to cache the generated reports if they are unlikely to 
change frequently etc etc...

I've written systems that work this way. It may be that the OP was 
trying to do something like this.



Alan

Christopher Schultz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Guilherme,
> 
> Guilherme Orioli wrote:
> | Didn't get it... it just doesn't work... what do I need to use instead of
> | the response.redirect ?
> 
> These good folks are telling you to do something differently than you
> are currently doing it.
> 
> Right now you are trying to:
> 
> 1. generate your content
> 2. write the content to a file on the disk
> 3. redirect the user to the newly-generated file on disk
> 
> Everyone is telling you to:
> 
> 1. generate your content
> 2. write the content out to the ServletOutputStream directly
> ~   (not to System.out, nor to a FileOutputStream)
> 
> No disk file; no redirect. Each request re-generates the content and
> sends it back to the client (browser) as the response to the original
> request.
> 
> Let me lay it out for you. You currently have this code:
> 
> | try{
> | ServletOutputStream sos = response.getOutputStream();
> | pdfStream.writeTo(sos);
> | System.out.println("pdsStream - "+pdfStream);
> | response.sendRedirect("myPDF.pdf");
> | sos.flush();
> | sos.close();
> | pdfStream.close();
> | pdfStream = null;
> | }catch(IOException e){
> | e.printStackTrace();
> | }
> | return "";
> 
> You should change it to:
> 
> try{
> ~    ServletOutputStream sos = response.getOutputStream();
> ~    pdfStream.writeTo(sos);
> ~    sos.flush();
> ~    sos.close();
> ~    pdfStream.close();
> } catch(IOException e) {
> ~    e.printStackTrace();
> 
> ~    response.sendError(HttpServletResponse.INTERNAL_SERVER_ERROR,
> ~                       e.getMessage());
> }
> return "";
> /// ^^^ What is this?
> 
> I'm not sure why your method returns a String. There's no reason for it
> to do so. Is this in a servlet? If it is, then you are going to run in
> to trouble with the "request" and "response" objects being members of
> the class. Two simultaneous requests will completely break your 
> application.
> 
> You can simplify the code somewhat, as well as reducing the amount of
> memory required to operate by eliminating your use of a
> ByteArrayOutputStream. The only downside is that your servlet will not
> be returning a Content-Length with the response (which isn't that big of
> a deal).
> 
> - -chris
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.8 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iEYEARECAAYFAkf030UACgkQ9CaO5/Lv0PAZUgCdFrgxEz2Ni1O7TTxcEWqvYyXN
> TzAAmwRB3Oau5Q4BMOr2/1YpamUXSyz+
> =bmNA
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 
> !DSPAM:47f4dff582799080218370!
> 

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message