From 62c954ee75e852f8599083591c64fb0381c0c989 Mon Sep 17 00:00:00 2001 From: tzefferer Date: Fri, 27 Jul 2007 08:57:46 +0000 Subject: git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@163 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../egov/egiz/web/servlets/ProvidePDFServlet.java | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java (limited to 'src/main/java/at/knowcenter/wag/egov/egiz/web') diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java new file mode 100644 index 0000000..cd4cf43 --- /dev/null +++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java @@ -0,0 +1,73 @@ +package at.knowcenter.wag.egov.egiz.web.servlets; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.knowcenter.wag.egov.egiz.web.FormFields; +import at.knowcenter.wag.egov.egiz.web.PDFContainer; + +public class ProvidePDFServlet extends HttpServlet { + + /** + * SVUID. + */ + private static final long serialVersionUID = 1L; + + /** + * The log. + */ + private static Log log = LogFactory.getLog(ProvidePDFServlet.class); + + public static Set signedDocuments = Collections.synchronizedSet(new HashSet()); + + public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + + long pdfId = Long.parseLong(request.getParameter(FormFields.FIELD_PDF_ID)); + + Iterator it = signedDocuments.iterator(); + + while(it.hasNext()) { + PDFContainer current = (PDFContainer) it.next(); + if(current.id == pdfId) { + try { + byte[] pdf = current.pdf; + + response.setContentType("application/pdf"); + response.setContentLength(pdf.length); + + InputStream is = new ByteArrayInputStream(pdf); + final int bufferSize = 1024; + byte[] buffer = new byte[bufferSize]; + int len = -1; + while ((len = is.read(buffer)) != -1) { + response.getOutputStream().write(buffer, 0, len); + } + response.getOutputStream().flush(); + signedDocuments.remove(current); + } catch(IOException e) { + log.warn("IO excepton while providing pdf document: " + e.getMessage()); + } + } + } + } + + public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + doPost(request, response); + } + +} -- cgit v1.2.3