By Date: <-- -->
By Thread: <-- -->

FileOutputStream problem




Hi All,

My application is a web based one; this one allow my customers to:
- receive invoice by mail;
- get an on-line view

On-line view is running fine!
I want to use the same servlet (pdfInvoiceGeneratorPL) to allow them to received their invoices by mail.

Basically, customer access their 'on-line view', by clicking in a link with 2 parameters; something like this:
/pdfInvoiceGeneratorPL?id=1&plus, where id is the invoiceID and plus, a parameters to know that an 'on-line view' is requesting.

One more time, this funcionnality is ok, running very well!

My problem is: I want to re-use this servlet to implement the e-mail sending functionnality.
I want the system send when an url like this /pdfInvoiceGeneratorPL?id=1
NOTE: no plus in parameter!!! Just to differentiate funcionnalities!

I need help!
How can I do?

Thanks in advanced!



HERE IS MY CODE:

public class pdfInvoiceGeneratorPL extends HttpServlet {
    protected Document document = null;
    protected Paragraph paragraph = null;
    protected Chunk chunk = null;
    protected PdfPCell cell = null;
    protected Phrase phrase = null;
   
    /** Creates a new instance of pdfInvoiceGeneratorPL */
    public pdfInvoiceGeneratorPL() {
        super();
    }
   
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException,
            java.io.IOException {
        String plus = "";
        document = new Document();
        paragraph = new Paragraph();
       
        DocumentException ex = null;
       
        ByteArrayOutputStream baos = null;
       
        try {
    baos = generatePDFDocumentBytes(request, this.getServletContext());
               
    response.setHeader("Cache-Control", "max-age=30");
            response.setContentType ("application/pdf");
    response.setHeader("Content-disposition", "inline; filename=mypdf.pdf");
    response.setContentLength(baos.size());

    ServletOutputStream sos = response.getOutputStream ();
            baos.writeTo(sos);
               
            sos.flush();
        } catch (DocumentException de) {
            response.setContentType("text/html");
            PrintWriter writer = response.getWriter();
            writer.println(this.getClass().getName() + " caught an exception: " + de.getClass().getName() + "<br>");
            writer.println("<pre>");
            de.printStackTrace(writer);
            writer.println("</pre>");
        } finally {
            if (baos != null) {
                baos.reset();
            }
        }
    }
   
    protected ByteArrayOutputStream generatePDFDocumentBytes(
            final HttpServletRequest req,
            final ServletContext ctx)
            throws DocumentException {

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter documentWriter = null;
       
        try {
    documentWriter = PdfWriter.getInstance(document, baos); - OK
           
            document.setPageSize(PageSize.LETTER);
            document.open();
           
            paragraph.setLeading(10);
           
            utilities.addChunkToDocument(document, paragraph, "text", font_1, Element.ALIGN_RIGHT);
    // ... more content to write
        } catch (BadElementException ex) {
            throw new RuntimeException();
        } catch (MalformedURLException m) {
        } catch (IOException ioe) {
        } catch (DocumentException de) {
            baos.reset();
            throw de;
        } finally {
            if (document != null) {
                document.close();
            }
           
            if (documentWriter != null) {
                documentWriter.close();
            }
        }
       
        if (baos.size() < 1) {
            throw new DocumentException("document has "+ baos.size()+ " bytes");
        }
       
        return baos;
    }
}

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
iText-questions (at) lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/