diff options
-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);
+ }
+
+}
|