aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/SignServlet.java
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/SignServlet.java')
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/SignServlet.java192
1 files changed, 98 insertions, 94 deletions
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/SignServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/SignServlet.java
index 1c594dd..c60ecf0 100644
--- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/SignServlet.java
+++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/SignServlet.java
@@ -83,7 +83,7 @@ import com.lowagie.text.DocumentException;
* This method is the sign servlet for the pdf-as web application. It takes get
* and post requests fill out jsp templates and give the user feedback about the
* results of the sign process
- *
+ *
* @author wlackner
* @author wprinz
*/
@@ -100,9 +100,9 @@ public class SignServlet extends HttpServlet
*/
private static Log log = LogFactory.getLog(SignServlet.class);
private static Log statLog = LogFactory.getLog("statistic");
-
-
-
+
+
+
public static final String SUBMITFORM_SIGNATURE_TYPE_KEY = "signupload.jsp:signatureType";
public static final String SUBMITFORM_SIGNATURE_MODE_KEY = "signupload.jsp:signatureMode";
public static final String SUBMITFORM_SIGNATURE_DEVICE_KEY = "signupload.jsp:signatureKey";
@@ -113,10 +113,10 @@ public class SignServlet extends HttpServlet
public static final String SUBMITFORM_FILE_KEY = "signupload.jsp:fileKey";
public static final String SUBMITFORM_FILENAME_KEY = "signupload.jsp:filenameKey";
public static final String SUBMITFORM_PREVIEW = "signupload.jsp:previewKey";
-
-
-
+
+
+
//Added by rpiazzi to know if an error occured within IFrame because this calls for
//a different display of the error
public static final String ERROR_WITHIN_IFRAME = "error_within_iframe";
@@ -124,7 +124,7 @@ public class SignServlet extends HttpServlet
public static final String HEIGHT_SIGN_DIV = "height_sign_div";
//Added by rpiazzi
public static HttpSession session = null;
-
+
protected void dispatch(HttpServletRequest request, HttpServletResponse response, String resource) throws ServletException, IOException
{
dispatch(request, response, resource, getServletContext());
@@ -141,7 +141,7 @@ public class SignServlet extends HttpServlet
/**
* Processes the sign upload.
- *
+ *
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
@@ -150,12 +150,12 @@ public class SignServlet extends HttpServlet
UploadedData ud = null;
ExternAppInformation exappinf = null;
SignaturePositioning sigpos = null;
-
-
+
+
// for performance measurement
- long startTime = 0;
+ long startTime = 0;
if (statLog.isInfoEnabled()) {
- startTime = System.currentTimeMillis();
+ startTime = System.currentTimeMillis();
}
// check if pdf-as has been called by external webapp
@@ -176,7 +176,7 @@ public class SignServlet extends HttpServlet
String sig_pos_x = (String) request.getParameter(FormFields.FIELD_SIGPOS_X);
String sig_pos_w = (String) request.getParameter(FormFields.FIELD_SIGPOS_W);
String note = (String) request.getParameter(FormFields.FIELD_NOTE_ENABLED);
-
+
//Added by rpiazzi
log.debug("Received external request from "+request.getRemoteAddr());
log.debug("Parameter preview: "+preview);
@@ -195,7 +195,7 @@ public class SignServlet extends HttpServlet
log.debug("Parameter sig_pos_w: "+sig_pos_w);
log.debug("Parameter note: "+note);
//end added
-
+
// added by tknall
if (sig_pos_y != null && sig_pos_p != null && sig_pos_x != null) {
if (sig_pos_w != null) {
@@ -222,14 +222,14 @@ public class SignServlet extends HttpServlet
log.debug("No signature position provided.");
}
-
+
// fixed by tknall: if we already have parameters "&" must be used instead of "?"
- String paramSeparator = (pdf_url.indexOf("?") != -1) ? "&" : "?";
+ String paramSeparator = (pdf_url.indexOf("?") != -1) ? "&" : "?";
String query = pdf_url + "/" + filename + paramSeparator + FormFields.FIELD_PDF_ID + "=" + pdf_id;
//query = pdf_url;
-
+
log.debug("Query string for loading pdf: "+query);
-
+
// wprinz: rem: this allocation is useless
// byte[] extern_pdf = new byte[Integer.parseInt(pdf_length)];
URL source_url = new URL(query);
@@ -261,14 +261,14 @@ public class SignServlet extends HttpServlet
ud_extern.note=true;
ud_extern.sig_type = ud_extern.sig_type + "_NOTE";
}
-
-
+
+
ud_extern.pdfa = false;
-
+
ud = ud_extern;
-
+
exappinf = new ExternAppInformation(invoke_url, pdf_id, session_id, invoke_error_url);
-
+
}
else
{
@@ -276,7 +276,7 @@ public class SignServlet extends HttpServlet
{
// tzefferer: modified
// UploadedData ud = retrieveUploadedDataFromRequest(request);
-
+
UploadedData ud_form = retrieveUploadedDataFromRequest(request);
ud = ud_form;
// end modify
@@ -285,7 +285,7 @@ public class SignServlet extends HttpServlet
catch (PdfAsException e)
{
log.error(e);
-
+
//Added by rpiazzi to check if this attribute is still null
HttpSession session = request.getSession();
String error_within_iframe = (String)session.getAttribute(SUBMITFORM_SIGNATURE_DEVICE_KEY);
@@ -293,18 +293,18 @@ public class SignServlet extends HttpServlet
session.setAttribute(SignServlet.ERROR_WITHIN_IFRAME, "no");
}
//end added
-
+
prepareDispatchToErrorPage(e, request);
dispatch(request, response, "/jsp/error.jsp");
-
-
-
-
+
+
+
+
return;
}
catch (FileUploadException e) {
log.error(e);
-
+
//Added by rpiazzi to check if this attribute is still null
HttpSession session = request.getSession();
String error_within_iframe = (String)session.getAttribute(SUBMITFORM_SIGNATURE_DEVICE_KEY);
@@ -312,7 +312,7 @@ public class SignServlet extends HttpServlet
session.setAttribute(SignServlet.ERROR_WITHIN_IFRAME, "no");
}
//end added
-
+
request.setAttribute("error", e.getMessage());
request.setAttribute("cause", e.getCause());
request.setAttribute("resourcebundle", Boolean.TRUE);
@@ -320,7 +320,7 @@ public class SignServlet extends HttpServlet
}
catch (IOException e) {
log.error(e);
-
+
//Added by rpiazzi to check if this attribute is still null
HttpSession session = request.getSession();
String error_within_iframe = (String)session.getAttribute(SUBMITFORM_SIGNATURE_DEVICE_KEY);
@@ -328,7 +328,7 @@ public class SignServlet extends HttpServlet
session.setAttribute(SignServlet.ERROR_WITHIN_IFRAME, "no");
}
//end added
-
+
request.setAttribute("error", e.getMessage());
request.setAttribute("cause", e.getCause());
request.setAttribute("resourcebundle", Boolean.TRUE);
@@ -343,19 +343,19 @@ public class SignServlet extends HttpServlet
SignSessionInformation si = new SignSessionInformation(); // SessionTable.generateSessionInformationObject();
si.connector = ud.sig_app;
-
+
if ((ud.mobileTestEnabled) && (si.connector.equals("mobile"))) {
si.connector = Constants.SIGNATURE_DEVICE_MOBILETEST;
session.setAttribute(SignServlet.SUBMITFORM_SIGNATURE_DEVICE_KEY, si.connector);
}
-
+
si.application = "sign";
si.mode = ud.sig_mode;
si.pdfDataSource = ud.pdfDataSource;
si.type = ud.sig_type;
-
+
si.filename = formatFileName(ud.file_name);
-
+
si.download_inline = ud.download_inline;
si.pdfa = ud.pdfa;
si.note = ud.note;
@@ -365,6 +365,9 @@ public class SignServlet extends HttpServlet
si.pos = sigpos;
// end add
+ // added afitzek
+ si.startTime = startTime;
+
log.info("Putting signature data into session " + session.getId());
session.setAttribute(SessionAttributes.ATTRIBUTE_SESSION_INFORMATION, si);
@@ -393,18 +396,19 @@ public class SignServlet extends HttpServlet
return;
}*/
-
-
+
+
SignServletHelper.finishSign(si, request, response, getServletContext());
-
+
+ // afitzek: moved to DataURL to provide status information OK - ERROR
// for performance measurement
- if (statLog.isInfoEnabled()) {
+ /*if (statLog.isInfoEnabled()) {
long endTime = System.currentTimeMillis();
-// String toReport = "SIGN;" + si.mode + ";" + si.filename + ";"+ fileSize + ";" +
- String toReport = "SIGN;" + si.mode + ";" + si.connector + ";" + si.pdfDataSource.getLength() + ";" + (endTime - startTime);
-
+// String toReport = "SIGN;" + si.mode + ";" + si.filename + ";"+ fileSize + ";" +
+ String toReport = "SIGN;" + si.mode + ";" + si.connector + ";" + si.pdfDataSource.getLength() + ";" + (endTime - startTime);
+
statLog.info(toReport);
- }
+ }*/
}
catch (PresentableException e)
{
@@ -443,7 +447,7 @@ public class SignServlet extends HttpServlet
FileItem source_fi = null;
FileItem sig_type_fi = null;
FileItem sig_app_fi = null;
-
+
boolean pdfaEnabled=false;
boolean noteEnabled=false;
String sig_type="";
@@ -452,21 +456,21 @@ public class SignServlet extends HttpServlet
String doc_file_name;
DataSource pdfDataSource;
boolean mobileTestEnabled=false;
-
+
Iterator it = items.iterator();
session = request.getSession(true);
-
-
-
+
+
+
//Added by rpiazzi. If servlet was called for preview data was already written into
//session.
//Now commented out because the preview function is no more supported
/*if ((((FileItem)items.get(0)).getFieldName().equals(SignServlet.SUBMITFORM_PREVIEW))) {
FileItem fi = (FileItem)items.get(1);
-
+
sig_app_fi = fi;
session.setAttribute(SUBMITFORM_SIGNATURE_DEVICE_KEY, sig_app_fi.getString("UTF-8"));
-
+
if (((String)session.getAttribute(SUBMITFORM_PDFA_KEY))!=null) {
if (((String)session.getAttribute(SUBMITFORM_PDFA_KEY)).equals("on")) {
pdfaEnabled = true;
@@ -477,18 +481,18 @@ public class SignServlet extends HttpServlet
noteEnabled = true;
}
}
-
+
sig_type = (String)session.getAttribute(SUBMITFORM_SIGNATURE_TYPE_KEY);
sig_app = sig_app_fi.getString("UTF-8");
-
+
mode = (String)session.getAttribute(SUBMITFORM_SIGNATURE_MODE_KEY);
doc_file_name = (String)session.getAttribute(SUBMITFORM_FILENAME_KEY);
pdfDataSource = (DataSource)session.getAttribute(SUBMITFORM_FILE_KEY);
-
+
}
//end added
else {*/
-
+
//Added by rpiazzi to check wheter local bku button was hit. In this case the parameters
//were already put into session because before local bku, online bku has to be called
//and therefore this servlet was already called.
@@ -502,14 +506,14 @@ public class SignServlet extends HttpServlet
}
positionLocal++;
}
-
+
if (localFound) {
-
+
session.setAttribute(SignServlet.ERROR_WITHIN_IFRAME, "no");
pdfaEnabled = "on".equalsIgnoreCase((String)session.getAttribute(SUBMITFORM_PDFA_KEY));
sig_type = (String)session.getAttribute(SUBMITFORM_SIGNATURE_TYPE_KEY);
noteEnabled = "on".equalsIgnoreCase((String)session.getAttribute(SUBMITFORM_NOTE_KEY));
-
+
session.setAttribute(SUBMITFORM_SIGNATURE_DEVICE_KEY, "bku");
sig_app = "bku";
mode = (String)session.getAttribute(SUBMITFORM_SIGNATURE_MODE_KEY);
@@ -525,7 +529,7 @@ public class SignServlet extends HttpServlet
{
FileItem item = (FileItem) it.next();
log.debug("item = " + item.getFieldName()); //$NON-NLS-1$
-
+
if (log.isDebugEnabled())
{
if (item.isFormField())
@@ -539,7 +543,7 @@ public class SignServlet extends HttpServlet
log.debug(" filesize = " + item.getSize()); //$NON-NLS-1$
}
}
-
+
if (item.getFieldName().equals(FormFields.FIELD_SIGNATURE_TYPE))
{
sig_type_fi = item;
@@ -580,7 +584,7 @@ public class SignServlet extends HttpServlet
file_upload_fi = item;
}
continue;
-
+
}
//Added by rpiazzi to ignore the form fields for the inactive mode
@@ -589,14 +593,14 @@ public class SignServlet extends HttpServlet
continue;
}*/
//end added
-
+
/*Commented out by rpiazzi because not more needed
* if (item.getFieldName().equals(FormFields.FIELD_DOWNLOAD))
{
download_fi = item;
continue;
}*/
-
+
if (FormFields.FIELD_PDFA_ENABLED.equals(item.getFieldName())) {
if (item.getString("UTF-8")!=null) {
session.setAttribute(SUBMITFORM_PDFA_KEY, "on");
@@ -608,7 +612,7 @@ public class SignServlet extends HttpServlet
}
continue;
}
-
+
if (FormFields.FIELD_SOURCE_FREETEXT.equals(item.getFieldName())) {
freeText_fi = item;
String value = freeText_fi.getString("UTF-8");
@@ -617,13 +621,13 @@ public class SignServlet extends HttpServlet
}
continue;
}
-
+
if (FormFields.FIELD_SOURCE.equals(item.getFieldName())) {
source_fi = item;
session.setAttribute(SUBMITFORM_SOURCE_KEY, item.getString("UTF-8"));
continue;
}
-
+
//Added by rpiazzi. Feature added for inserting note into signature block
if (FormFields.FIELD_NOTE_ENABLED.equals(item.getFieldName())) {
if (item.getString("UTF-8")!=null) {
@@ -637,14 +641,14 @@ public class SignServlet extends HttpServlet
continue;
}
//end added
-
+
//Added by rpiazzi to let later jsp's know the height of the div elements
if (FormFields.FIELD_HEIGHT_SIGNDIV.equals(item.getFieldName())) {
session.setAttribute(HEIGHT_SIGN_DIV, item.getString("UTF-8"));
continue;
}
//end added
-
+
if (FormFields.FIELD_MOBILETEST_ENABLED.equals(item.getFieldName())) {
if (item.getString("UTF-8")!=null) {
if (item.getString("UTF-8").equals("on")) {
@@ -653,7 +657,7 @@ public class SignServlet extends HttpServlet
}
continue;
}
-
+
throw new ServletException("Unrecognized POST data."); //$NON-NLS-1$
}
@@ -669,7 +673,7 @@ public class SignServlet extends HttpServlet
throw new ServletException("The mode '" + mode + "' is unrecognized."); //$NON-NLS-1$ //$NON-NLS-2$
}
-
+
//Commented out by rpiazzi because not more needed
/*boolean download_inline = true;
if (download_fi.getString("UTF-8").equals(FormFields.VALUE_DOWNLOAD_ATTACHMENT)) //$NON-NLS-1$
@@ -677,7 +681,7 @@ public class SignServlet extends HttpServlet
download_inline = false;
}*/
-
+
// distinguish between file and freetext
if (source_fi.getString("UTF-8").equals(FormFields.VALUE_SOURCE_FILE)) {
log.debug("Processing file.");
@@ -700,7 +704,7 @@ public class SignServlet extends HttpServlet
{
pdfDataSource = new ByteArrayPdfDataSource(IOUtils.toByteArray(file_upload_fi.getInputStream()));
session.setAttribute(SUBMITFORM_FILE_KEY, pdfDataSource);
- session.setAttribute(SUBMITFORM_FILENAME_KEY, doc_file_name);
+ session.setAttribute(SUBMITFORM_FILENAME_KEY, doc_file_name);
}
catch (IOException e)
{
@@ -719,16 +723,16 @@ public class SignServlet extends HttpServlet
} catch (IOException e) {
throw new PDFDocumentException(201, "Unable to create PDF document.", e);
}
-
+
//}
// byte[] pdf = file_upload_fi.get();
}
}
-
-
-
-
-
+
+
+
+
+
UploadedData ud = new UploadedData();
@@ -747,13 +751,13 @@ public class SignServlet extends HttpServlet
ud.sig_type += "_NOTE";
session.setAttribute(SUBMITFORM_SIGNATURE_TYPE_KEY, ud.sig_type);
}
-
+
if (mobileTestEnabled) {
ud.mobileTestEnabled=true;
}
-
+
//end added
-
+
return ud;
}
@@ -769,7 +773,7 @@ public class SignServlet extends HttpServlet
request.setAttribute("error", "Fehler " + pe.getErrorCode());
String cause = ErrorCodeHelper.getMessageForErrorCode(pe.getErrorCode());
-
+
if (pe instanceof ExternalErrorException)
{
ExternalErrorException eee = (ExternalErrorException) pe;
@@ -791,7 +795,7 @@ public class SignServlet extends HttpServlet
request.setAttribute("cause", "Der Platzhalter des Feldes " + phe.getField() + " ist um " + phe.getMissing() + " Bytes zu kurz. " + cause);
}
-
+
//Added by rpiazzi to know if error happened when request was within iframe
//In this case the visualization of the error has to be done differently
/*HttpSession session = request.getSession();
@@ -802,8 +806,8 @@ public class SignServlet extends HttpServlet
request.setAttribute(ERROR_WITHIN_IFRAME, "yes");
}*/
//end added
-
-
+
+
// }
// else
// {
@@ -814,7 +818,7 @@ public class SignServlet extends HttpServlet
/**
* Formats the file name so that it is suitable for content disposition.
- *
+ *
* @param file_name
* The file name.
* @return Returns the formatted file name.
@@ -863,7 +867,7 @@ public class SignServlet extends HttpServlet
}
// end add
-
+
protected static class UploadedData
{
protected boolean preview = false;
@@ -881,13 +885,13 @@ public class SignServlet extends HttpServlet
protected String file_name = null;
protected DataSource pdfDataSource = null;
-
+
protected boolean mobileTestEnabled = false;
-
+
//added by rpiazzi
protected boolean note = false;
// protected byte[] pdf = null;
}
-}
-
+}
+