aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java
diff options
context:
space:
mode:
authortknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2010-03-16 12:07:29 +0000
committertknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2010-03-16 12:07:29 +0000
commit11b5950be66bcc9d6f0bb28d3fc9d211bc70f4d9 (patch)
tree5a48a33069a318e269245998ecf89b387f331f67 /src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java
parentda4926845267ca8bedf34917bd3bfb94aeafa153 (diff)
downloadpdf-as-3-11b5950be66bcc9d6f0bb28d3fc9d211bc70f4d9.tar.gz
pdf-as-3-11b5950be66bcc9d6f0bb28d3fc9d211bc70f4d9.tar.bz2
pdf-as-3-11b5950be66bcc9d6f0bb28d3fc9d211bc70f4d9.zip
Catching OutOfMemory exceptions, returning appropriate error message/code
Binary signature: bug concerning indirect pdf objects fixed SignaturePositioning improved (Signature position can be declared by String which is parsed) Some more error codes (Out of memory, Invalid signature position) iText utility for creation of pdf files added ConfigUtils updated (destination of configuration to be extracted can now be chosen) PDFASUtils updated (more tools) WebApplication: Freetext pdf creation implemented WebApplication: XSS security updates git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@580 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java')
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java102
1 files changed, 75 insertions, 27 deletions
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java
index c946225..69b237f 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java
@@ -33,18 +33,26 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import com.lowagie.text.DocumentException;
+
import at.gv.egiz.pdfas.exceptions.ErrorCode;
import at.gv.egiz.pdfas.exceptions.ErrorCodeHelper;
import at.gv.egiz.pdfas.exceptions.external.ExternalErrorException;
import at.gv.egiz.pdfas.framework.input.PdfDataSource;
+import at.gv.egiz.pdfas.impl.input.ByteArrayPdfDataSourceImpl;
+import at.gv.egiz.pdfas.itext.IText;
+import at.gv.egiz.pdfas.utils.ConfigUtils;
+import at.gv.egiz.pdfas.utils.PDFASUtils;
import at.gv.egiz.pdfas.utils.WebUtils;
import at.gv.egiz.pdfas.web.SignSessionInformation;
import at.gv.egiz.pdfas.web.helper.SignServletHelper;
@@ -235,6 +243,7 @@ public class SignServlet extends HttpServlet
try
{
+
// tzefferer: modified
// UploadedData ud = retrieveUploadedDataFromRequest(request);
UploadedData ud_form = retrieveUploadedDataFromRequest(request);
@@ -244,9 +253,7 @@ public class SignServlet extends HttpServlet
}
catch (Exception e)
{
- // Error retrieving data
-// request.setAttribute("error", "Fehler beim Upload der Daten");
-// request.setAttribute("cause", "Beim Upload der Daten ist ein Fehler aufgetreten.");
+ log.error(e);
request.setAttribute("error", "signservlet.error");
request.setAttribute("cause", "signservlet.cause");
request.setAttribute("resourcebundle", Boolean.TRUE);
@@ -344,8 +351,11 @@ public class SignServlet extends HttpServlet
FileItem mode_fi = null;
FileItem file_upload_fi = null;
FileItem download_fi = null;
+ FileItem freeText = null;
+ FileItem pdfa = null;
Iterator it = items.iterator();
+ HttpSession session = request.getSession();
while (it.hasNext())
{
FileItem item = (FileItem) it.next();
@@ -374,18 +384,21 @@ public class SignServlet extends HttpServlet
if (item.getFieldName().equals(FormFields.FIELD_SIGNATURE_TYPE))
{
sig_type_fi = item;
+ session.setAttribute(UpdateFormServlet.UPLOADFORM_SIGNATURE_TYPE_KEY, sig_type_fi.getString("UTF-8"));
continue;
}
if (item.getFieldName().equals(FormFields.FIELD_CONNECTOR))
{
sig_app_fi = item;
+ session.setAttribute(UpdateFormServlet.UPLOADFORM_SIGNATURE_DEVICE_KEY, sig_app_fi.getString("UTF-8"));
continue;
}
if (item.getFieldName().equals(FormFields.FIELD_MODE))
{
mode_fi = item;
+ session.setAttribute(UpdateFormServlet.UPLOADFORM_SIGNATURE_MODE_KEY, mode_fi.getString("UTF-8"));
continue;
}
@@ -402,14 +415,30 @@ public class SignServlet extends HttpServlet
}
if (FormFields.FIELD_PDFA_ENABLED.equals(item.getFieldName())) {
+ pdfa = item;
+ session.setAttribute(UpdateFormServlet.UPLOADFORM_PDFA_KEY, pdfa.getString("UTF-8"));
+ continue;
+ }
+
+ if (FormFields.FIELD_FREETEXT.equals(item.getFieldName())) {
+ freeText = item;
+ String value = freeText.getString("UTF-8");
+ if (value != null) {
+ session.setAttribute(UpdateFormServlet.UPLOADFORM_FREETEXT_KEY, value);
+ }
+ continue;
+ }
+
+ if (FormFields.FIELD_SOURCE.equals(item.getFieldName())) {
+ session.setAttribute(UpdateFormServlet.UPLOADFORM_SOURCE_KEY, item.getString("UTF-8"));
continue;
}
- throw new ServletException("unrecognized POST data."); //$NON-NLS-1$
+ throw new ServletException("Unrecognized POST data."); //$NON-NLS-1$
}
- if (preview_fi == null || sig_type_fi == null || sig_app_fi == null || file_upload_fi == null || download_fi == null)
+ if (preview_fi == null || sig_type_fi == null || sig_app_fi == null || (file_upload_fi == null && freeText== null) || download_fi == null)
{
throw new ServletException("Insufficient data provided in request"); //$NON-NLS-1$
}
@@ -436,28 +465,47 @@ public class SignServlet extends HttpServlet
String sig_type = sig_type_fi.getString("UTF-8"); //$NON-NLS-1$
String sig_app = sig_app_fi.getString("UTF-8"); //$NON-NLS-1$
- String doc_file_name = TempDirHelper.extractFileNameSuffix(file_upload_fi.getName());
- log.debug("file content type =" + file_upload_fi.getContentType()); //$NON-NLS-1$
-
- String extension = VerifyServlet.extractExtension(doc_file_name);
- if (extension != null && !extension.equals("pdf")) //$NON-NLS-1$
- {
- throw new PDFDocumentException(201, "The provided file '" + doc_file_name + "' doesn't have the PDF extension (.pdf)."); //$NON-NLS-1$//$NON-NLS-2$
- }
-
- if (file_upload_fi.getSize() <= 0)
- {
- throw new PDFDocumentException(250, "The document is empty."); //$NON-NLS-1$
- }
-
- PdfDataSource pdfDataSource = null;
- try
- {
- pdfDataSource = TempDirHelper.placePdfIntoTempDir(file_upload_fi.getInputStream(), doc_file_name);
- }
- catch (IOException e)
- {
- throw new PDFDocumentException(201, "Couldn't store the file in the temp dir.", e);
+ PdfDataSource pdfDataSource;
+ String doc_file_name;
+ // distinguish between file and freetext
+ if (file_upload_fi != null) {
+ log.debug("Processing file.");
+ doc_file_name = TempDirHelper.extractFileNameSuffix(file_upload_fi.getName());
+ log.debug("file content type =" + file_upload_fi.getContentType()); //$NON-NLS-1$
+
+ String extension = VerifyServlet.extractExtension(doc_file_name);
+ if (extension != null && !extension.equals("pdf")) //$NON-NLS-1$
+ {
+ throw new PDFDocumentException(201, "The provided file '" + doc_file_name + "' doesn't have the PDF extension (.pdf)."); //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ if (file_upload_fi.getSize() <= 0)
+ {
+ throw new PDFDocumentException(250, "The document is empty."); //$NON-NLS-1$
+ }
+
+ try
+ {
+ pdfDataSource = TempDirHelper.placePdfIntoTempDir(file_upload_fi.getInputStream(), doc_file_name);
+ }
+ catch (IOException e)
+ {
+ throw new PDFDocumentException(201, "Couldn't store the file in the temp dir.", e);
+ }
+ } else {
+ log.debug("Processing free text.");
+ try {
+ boolean pdfaEnabled = pdfa != null && "true".equalsIgnoreCase(pdfa.getString());
+ byte[] freeTextPDF = IText.createPDF(freeText.getString("UTF-8"), pdfaEnabled);
+
+ pdfDataSource = new ByteArrayPdfDataSourceImpl(freeTextPDF);
+ doc_file_name = IText.DEFAULT_FILENAME;
+ } catch (DocumentException e) {
+ throw new PDFDocumentException(201, "Unable to create PDF document.", e);
+ } catch (IOException e) {
+ throw new PDFDocumentException(201, "Unable to create PDF document.", e);
+ }
+
}
// byte[] pdf = file_upload_fi.get();