diff options
author | tzefferer <tzefferer@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c> | 2007-07-27 08:57:46 +0000 |
---|---|---|
committer | tzefferer <tzefferer@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c> | 2007-07-27 08:57:46 +0000 |
commit | 62c954ee75e852f8599083591c64fb0381c0c989 (patch) | |
tree | 07fcfc6a1d418c2ecd4dc770a56e1f78290c17f8 /src/main/java | |
parent | 27255eff6215e6648f5406cfee1508c28ccc11ef (diff) | |
download | pdf-as-3-62c954ee75e852f8599083591c64fb0381c0c989.tar.gz pdf-as-3-62c954ee75e852f8599083591c64fb0381c0c989.tar.bz2 pdf-as-3-62c954ee75e852f8599083591c64fb0381c0c989.zip |
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@163 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java | 73 |
1 files changed, 73 insertions, 0 deletions
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);
+ }
+
+}
|