Re: How can I refresh tomcat in the java code?

2008-04-04 Thread Christopher Schultz

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Guilherme,

Guilherme Orioli wrote:
| Yes, it's an EJB managed by the JSF config faces-config.xml . Should I
use a
| different servlet to get the result wanted?

The problem is that you are using an EJB to manipulate the HTTP request
and response. You shouldn't do that. Fill the EJB with whatever data you
need from the request, tell it to generate the PDF, and then ask it
where the new PDF was written on the disk (or, you could even ask for an
InputStream to it, if you want to hide the location from the servlet).

The servlet should do all the work with the request and response. Get
that stuff out of your EJB. It'll be a lot easier to test that way.

| Is this code right, i mean, should it show the download dialog (or
even  the
| PDF screen).

If you always want to show a download dialog, you'll need to set a few
new headers. Search the web for Content-Disposition and attachment.
You'll find stuff like this:
http://classicasp.aspfaq.com/general/how-do-i-prompt-a-save-as-dialog-for-an-accepted-mime-type.html

Otherwise, the PDF will be displayed in the browser's content ares
instead of being downloaded (unless the user chooses Save Page As...
from the file menu, of course).

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkf2LdoACgkQ9CaO5/Lv0PDwpwCgtVaGmKReiCAC1yoxMa370z9A
FeEAn2L1k13zu5XAHZo2cCMMP7Qx6O4L
=8EPy
-END PGP SIGNATURE-

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



Re: How can I refresh tomcat in the java code?

2008-04-03 Thread Guilherme Orioli
Didn't get it... it just doesn't work... what do I need to use instead of
the response.redirect ?

2008/4/2, Alan Chaney [EMAIL PROTECTED]:

 You don't need the redirect. The response to the request IS the pdf file.

 HTH


 Guilherme Orioli wrote:

  It just doesn't show the Download dialog on the screen when i click the
  button...
 
  2008/4/2, Guilherme Orioli [EMAIL PROTECTED]:
 
   ok... here's what i'm doing... in system out, something like a pdf
   file is
   printed... itś probably there... just don't know how to show it from
   the
   button i'm clicking on:
  
   public String geraReportBois(){
   try{
  
   //Generating the report
   String caminho_arquivo = new File().getAbsolutePath() +
   /workspace/safeTrace/WebContent/reports/cliente/frigorifico/;
   String nome_arquivo = reportBois.jasper;
   JasperReport jasperReport =
   (JasperReport)JRLoader.loadObject(caminho_arquivo + nome_arquivo);
   Map parameters = new HashMap();
   parameters.put(Caminho, caminho_arquivo);
   JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
   parameters, this.getRelatorioBois());
  
  
   //--
  
   //Exporting to File (outputStream)
   ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
   JasperExportManager.exportReportToPdfStream(jasperPrint, pdfStream);
  
   HttpServletResponse response = (HttpServletResponse)
   FacesContext.getCurrentInstance().getExternalContext().getResponse();
   response.setContentType(application/pdf);
   response.setHeader(Content-Disposition, inline;
   filename=myPDF.pdf);
   response.setContentLength(pdfStream.size());
   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 ;
  
   }catch(JRException e){
   System.out.println(entrou no catch geraReportBois);
  
   e.printStackTrace();
   }
   return null;
   }
  
  
  
  
  
  !DSPAM:47f3d27e207721697119596!
 
 
 -
 To start a new topic, e-mail: users@tomcat.apache.org
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]




Re: How can I refresh tomcat in the java code?

2008-04-03 Thread Alan Chaney

.

Hi Guilherme

I can see that English isn't your first language and I have a lot of 
respect for anyone who is trying to work on technical things in a 
foreign language - I could never do it!


To help our communication I have tried to explain below what I think it 
is that you are trying to do. I may have misunderstood what it is that 
you are doing so I apologize if what I am saying is wrong.


I've joined this thread a bit late, but looking at the previous emails 
it seems to me that your need is that a user should be able to download 
a pdf file which has been generated by your server?


This is 'dynamic content'. The server responds to the request for a file 
by creating an OutputStream of pdf data



Your use case is that the user clicks on a link in a web page and the 
PDF file appears in their browser?


Here's what I would expect the sequence of events to be:

1. The user clicks on the link in the browser. The link has as its href 
for example www.mycompany/xyz.pdf


2. The browser generates an http GET request with the url 
www,mycompany/xzy.pdf and sends it out over the net.


3. Your container detects this request, looks up the appropriate servlet
in its web.xml and calls the HttpServlet 'doGet' method.

4. Your servlet responds to this request and generates the pdf in a 
temporary file.


5. You set any response headers that you need to set.

6. You read the temporary file as a byte InputStream and write this to 
the servlet OutputStream.


7. The container takes the data from the output stream and transmits 
across the wire back to the browser. It inserts any headers you have 
specified (and a few others) at the beginning.



8. You return from the doGet.


That's it. Done!



So the stream of data which is returned as the response to .../xyz.pdf 
IS the data you want displayed. You don't need to send a redirect to 
xyz.pdf because you have already responded to the request.


The exact point at which the container (Tomcat) starts to transmit data 
is up to the container. You can force it to send data by issuing a 
'flush'. However, once it has started to respond to the specific request 
you cannot issue things like a redirect. I'm simplifying a bit here.


Looking at your code there doesn't appear to be the doGet method - I 
assumed initially that you were calling your class from within the doGet

of a servlet. Is this the case?

Have you checked the tomcat logs? I would have expected the server to 
have thrown an exception when you attempted to send a redirect after you 
have already written data.







Guilherme Orioli wrote:

Didn't get it... it just doesn't work... what do I need to use instead of
the response.redirect ?

2008/4/2, Alan Chaney [EMAIL PROTECTED]:

You don't need the redirect. The response to the request IS the pdf file.

HTH


Guilherme Orioli wrote:


It just doesn't show the Download dialog on the screen when i click the
button...

2008/4/2, Guilherme Orioli [EMAIL PROTECTED]:


ok... here's what i'm doing... in system out, something like a pdf
file is
printed... itś probably there... just don't know how to show it from
the
button i'm clicking on:

public String geraReportBois(){
try{

//Generating the report
String caminho_arquivo = new File().getAbsolutePath() +
/workspace/safeTrace/WebContent/reports/cliente/frigorifico/;
String nome_arquivo = reportBois.jasper;
JasperReport jasperReport =
(JasperReport)JRLoader.loadObject(caminho_arquivo + nome_arquivo);
Map parameters = new HashMap();
parameters.put(Caminho, caminho_arquivo);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
parameters, this.getRelatorioBois());


//--

//Exporting to File (outputStream)
ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
JasperExportManager.exportReportToPdfStream(jasperPrint, pdfStream);

HttpServletResponse response = (HttpServletResponse)
FacesContext.getCurrentInstance().getExternalContext().getResponse();
response.setContentType(application/pdf);
response.setHeader(Content-Disposition, inline;
filename=myPDF.pdf);
response.setContentLength(pdfStream.size());
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 ;

}catch(JRException e){
System.out.println(entrou no catch geraReportBois);

e.printStackTrace();
}
return null;
}









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




!DSPAM:47f4c55058681264652389!



-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL 

Re: How can I refresh tomcat in the java code?

2008-04-03 Thread Christopher Schultz

-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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How can I refresh tomcat in the java code?

2008-04-03 Thread Alan Chaney

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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



!DSPAM:47f4dff582799080218370!



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



Re: How can I refresh tomcat in the java code?

2008-04-03 Thread Christopher Schultz

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Alan,

Alan Chaney wrote:
| 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.

He's returning a String from the (Java) method, not the HTTP request.

| 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.

Right. This will certainly work, but probably not well. This is why
projects like Open Reports offer scheduling and batching so that you
aren't tied to the request/response HTTP model. When you do things
asynchronously, you can do them when the load on the server is low, or,
better still, do it on another server that isn't handling loads of user
requests.

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

I think this was the OP's original desire, but everyone pushed him
towards generating content directly to the servlet output stream.
Unfortunately, Tomcat seems to take a snapshot of the content it serves
as the webapp comes up, and it doesn't believe that new content can be
added during the life of the webapp. That was the original question (see
the subject line): how can I tell Tomcat to refresh its content snapshot?

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkf05t8ACgkQ9CaO5/Lv0PDUfwCfVvvMu4zodnjNxTRc2UrVRb0O
+CwAn33hs1elwqVBZY4NO6kIzICkVEhS
=bXEw
-END PGP SIGNATURE-

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



Re: How can I refresh tomcat in the java code?

2008-04-03 Thread Guilherme Orioli
Christopher,

You got it right. I was trying to generate the content, write it into server
disk and redirect it to the user.

Everyone recomended me to generate it and send it as a response.
If that's the only option, I can accept that. If there's a way to refresh
the content under tomcat server folder, it would be better.

The problem with the recomended option is: It doesn't send the content to be
downloaded.
The system.out was just a test to see if the file was generated correctly.
It seems to be, since it prints tons of unknown chars. ^^
What this code I sent previously tries to do is:
1) Generate the pdf report (working fine)
2) Create a ByteArrayOutputStream with it (working fine)
3) Show it to be downloaded by the user (not working)

This code is located on a managed bean. The method is invoked when a
h:commandButton is pressed. That's why I return a String.

Hope you guys can help me now. Sorry for the english. I finished my course
four years ago and haven't practiced since then...

Gui Orioli.

2008/4/3, Christopher Schultz [EMAIL PROTECTED]:

 -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: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]




Re: How can I refresh tomcat in the java code?

2008-04-03 Thread Christopher Schultz

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Guilherme,

Guilherme Orioli wrote:

| Everyone recommended me to generate it and send it as a response.
| If that's the only option, I can accept that. If there's a way to refresh
| the content under tomcat server folder, it would be better.

There's no way that I know, short of reloading the entire webapp (which
is probably no what you want to do).

Another option would be to generate the content into a directory outside
your webapp (which is a good idea, anyway, since reloading the webapp
from a WAR would probably delete your generated content) and serve the
files yourself using a simple servlet that serves files out of a
particular directory.

There is full code for such a servlet that was posted (by me!) to the
list within the last 7 days or so with the subject displaying an image
from outside the webapps directory. Check it out.

| The problem with the recommended option is: It doesn't send the
content to be
| downloaded.

It should be. You must have something else going on that is not working.

| The system.out was just a test to see if the file was generated correctly.
| It seems to be, since it prints tons of unknown chars. ^^

Well, what did you expect? ;)

| What this code I sent previously tries to do is:
| 1) Generate the pdf report (working fine)
| 2) Create a ByteArrayOutputStream with it (working fine)
| 3) Show it to be downloaded by the user (not working)

Which browser? Displaying in the browser window, or forcing a download?
It could even be a browser issue, especially if you are using Adobe's
PDF plug-in and Mozilla Firefox -- they don't play well together for
some reason.

| This code is located on a managed bean. The method is invoked when a
| h:commandButton is pressed. That's why I return a String.

Ugh. Do you mean EJB? sigh

| Hope you guys can help me now.

I'm sure we can, but it might take some time. Be patient with us ;)

| Sorry for the English.

Your English is just fine. I hope we're not using too many phrases that
don't translate very well.

- -chris

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkf1D3sACgkQ9CaO5/Lv0PA4MwCeKaF+Dz78BVY7tb10u492uxeK
lNAAniAw2bQKYN/HG2vZIx/QS8WJELcM
=iSqR
-END PGP SIGNATURE-

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



Re: How can I refresh tomcat in the java code?

2008-04-02 Thread Frank W. Zammetti
Typically when you're generating dynamic content like that, you don't
serve it in the same way as a file on the file system does.  Instead you
usually serve it from memory, or from a database if you had need to store
it somewhere.

If you deploy within an EAR you'll find that writing to the file system
doesn't work as expected, at least within the context of the webapp... you
can do it if you tie your EAR to the environment it's running in, i.e.,
paths and such, but most people will tell you that's a Bad Idea(tm).

My point is that you're probably asking the wrong question... I think the
right question is how can you serve dynamically-generated content that is
transient, i.e., not persisted to the file system.  To answer that we'd
have to know what kind of content it is, how it's generated, etc.

Frank

-- 
Frank W. Zammetti
Author of Practical DWR 2 Projects
  and JavaScript, DOM Scripting and Ajax Projects
  and Practical Ajax Projects With Java Technology
  for info: apress.com/book/search?searchterm=zammettiact=search
Java Web Parts - javawebparts.sourceforge.net
 Supplying the wheel, so you don't have to reinvent it!
My look ma, I have a blog too! blog: zammetti.com/blog

On Wed, April 2, 2008 10:55 am, Guilherme Orioli wrote:
 I'm developing a system that will generate a  file dynamically, and i want
 to make it possible to be downloaded from server after it's created. The
 problem is that when i link the file, the response i get is that it
 doesn't
 exist.
 After a few tests we've figured out that if the file existed previously
 from
 loading tomcat, it's possible to get the file. So, if i reload tomcat, i
 can
 get it... I was wondering if i can refresh the tomcat in the java code.




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



Re: How can I refresh tomcat in the java code?

2008-04-02 Thread Guilherme Orioli
Ok... I've made some research on that too... I'm actually generating a
report (.pdf file) with jasper, and it already enables me to export it to an
outputstrem, as in this code:

memoryPDF = new FileOutputStream(test);
this.bytes =
JasperRunManager.runReportToPdf(jasperReport,parameters,this.getReport());
JasperExportManager.exportReportToPdfStream(bytes,memoryPDF);

This code is located in a method on my bean, which is on the action of a
h:commandButton/.  After creating the file, i don't know what to do to
send it as response.
What i was doing when i had the document on server before Tomcat startup
was:

HttpServletResponse response = (HttpServletResponse)
FacesContext.getCurrentInstance().getExternalContext().getResponse();
response.sendRedirect(test);

If you could help me sending this file created to be downloaded, it would be
a lot of help...


RE: How can I refresh tomcat in the java code?

2008-04-02 Thread Caldarale, Charles R
 From: Guilherme Orioli [mailto:[EMAIL PROTECTED] 
 Subject: Re: How can I refresh tomcat in the java code?
 
 memoryPDF = new FileOutputStream(test);

Don't create a FileOutputStream, use ServletResponse.getOutputStream()
instead.  Make sure you set the content type to application/pdf, of
course.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

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



RE: How can I refresh tomcat in the java code?

2008-04-02 Thread Frank W. Zammetti
What he said :)

FYI, serving PDFs in particular can be a bloody mess because of Acrobat
STILL not being able to get their s**t together when it comes to their
browser plug-in.

I wrote a Wiki entry on the Struts Wiki some time ago that might help:

http://wiki.apache.org/struts/ServingPdfDocuments?highlight=%28pdf%29

It's not really specific to Struts, so should help.

Frank

-- 
Frank W. Zammetti
Author of Practical DWR 2 Projects
  and JavaScript, DOM Scripting and Ajax Projects
  and Practical Ajax Projects With Java Technology
  for info: apress.com/book/search?searchterm=zammettiact=search
Java Web Parts - javawebparts.sourceforge.net
 Supplying the wheel, so you don't have to reinvent it!
My look ma, I have a blog too! blog: zammetti.com/blog

On Wed, April 2, 2008 1:24 pm, Caldarale, Charles R wrote:
 From: Guilherme Orioli [mailto:[EMAIL PROTECTED]
 Subject: Re: How can I refresh tomcat in the java code?

 memoryPDF = new FileOutputStream(test);

 Don't create a FileOutputStream, use ServletResponse.getOutputStream()
 instead.  Make sure you set the content type to application/pdf, of
 course.

  - Chuck


 THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
 MATERIAL and is thus for use only by the intended recipient. If you
 received this in error, please contact the sender and delete the e-mail
 and its attachments from all computers.

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





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



RE: How can I refresh tomcat in the java code?

2008-04-02 Thread Caldarale, Charles R
 From: Frank W. Zammetti [mailto:[EMAIL PROTECTED] 
 Subject: RE: How can I refresh tomcat in the java code?
 
 FYI, serving PDFs in particular can be a bloody mess because 
 of Acrobat STILL not being able to get their s**t together
 when it comes to their browser plug-in.

I finally gave up and just configured Firefox to download PDFs rather
than opening them up in the same app window with the plugin.  Got rid of
a lot of problems.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

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



Re: How can I refresh tomcat in the java code?

2008-04-02 Thread Guilherme Orioli
ok... here's what i'm doing... in system out, something like a pdf file is
printed... itś probably there... just don't know how to show it from the
button i'm clicking on:

public String geraReportBois(){
try{

//Generating the report
String caminho_arquivo = new File().getAbsolutePath() +
/workspace/safeTrace/WebContent/reports/cliente/frigorifico/;
String nome_arquivo = reportBois.jasper;
JasperReport jasperReport =
(JasperReport)JRLoader.loadObject(caminho_arquivo + nome_arquivo);
Map parameters = new HashMap();
parameters.put(Caminho, caminho_arquivo);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
parameters, this.getRelatorioBois());
//--

//Exporting to File (outputStream)
ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
JasperExportManager.exportReportToPdfStream(jasperPrint, pdfStream);

HttpServletResponse response = (HttpServletResponse)
FacesContext.getCurrentInstance().getExternalContext().getResponse();
response.setContentType(application/pdf);
response.setHeader(Content-Disposition, inline; filename=myPDF.pdf);
response.setContentLength(pdfStream.size());
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 ;

}catch(JRException e){
System.out.println(entrou no catch geraReportBois);

e.printStackTrace();
}
return null;
}


Re: How can I refresh tomcat in the java code?

2008-04-02 Thread Guilherme Orioli
It just doesn't show the Download dialog on the screen when i click the
button...

2008/4/2, Guilherme Orioli [EMAIL PROTECTED]:

 ok... here's what i'm doing... in system out, something like a pdf file is
 printed... itś probably there... just don't know how to show it from the
 button i'm clicking on:

 public String geraReportBois(){
 try{

 //Generating the report
 String caminho_arquivo = new File().getAbsolutePath() +
 /workspace/safeTrace/WebContent/reports/cliente/frigorifico/;
 String nome_arquivo = reportBois.jasper;
 JasperReport jasperReport =
 (JasperReport)JRLoader.loadObject(caminho_arquivo + nome_arquivo);
 Map parameters = new HashMap();
 parameters.put(Caminho, caminho_arquivo);
 JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
 parameters, this.getRelatorioBois());

 //--

 //Exporting to File (outputStream)
 ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
 JasperExportManager.exportReportToPdfStream(jasperPrint, pdfStream);

 HttpServletResponse response = (HttpServletResponse)
 FacesContext.getCurrentInstance().getExternalContext().getResponse();
 response.setContentType(application/pdf);
 response.setHeader(Content-Disposition, inline; filename=myPDF.pdf);
 response.setContentLength(pdfStream.size());
 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 ;

 }catch(JRException e){
 System.out.println(entrou no catch geraReportBois);

 e.printStackTrace();
 }
 return null;
 }






Re: How can I refresh tomcat in the java code?

2008-04-02 Thread Alan Chaney

You don't need the redirect. The response to the request IS the pdf file.

HTH


Guilherme Orioli wrote:

It just doesn't show the Download dialog on the screen when i click the
button...

2008/4/2, Guilherme Orioli [EMAIL PROTECTED]:

ok... here's what i'm doing... in system out, something like a pdf file is
printed... itś probably there... just don't know how to show it from the
button i'm clicking on:

public String geraReportBois(){
try{

//Generating the report
String caminho_arquivo = new File().getAbsolutePath() +
/workspace/safeTrace/WebContent/reports/cliente/frigorifico/;
String nome_arquivo = reportBois.jasper;
JasperReport jasperReport =
(JasperReport)JRLoader.loadObject(caminho_arquivo + nome_arquivo);
Map parameters = new HashMap();
parameters.put(Caminho, caminho_arquivo);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
parameters, this.getRelatorioBois());

//--

//Exporting to File (outputStream)
ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
JasperExportManager.exportReportToPdfStream(jasperPrint, pdfStream);

HttpServletResponse response = (HttpServletResponse)
FacesContext.getCurrentInstance().getExternalContext().getResponse();
response.setContentType(application/pdf);
response.setHeader(Content-Disposition, inline; filename=myPDF.pdf);
response.setContentLength(pdfStream.size());
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 ;

}catch(JRException e){
System.out.println(entrou no catch geraReportBois);

e.printStackTrace();
}
return null;
}






!DSPAM:47f3d27e207721697119596!



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