diff options
author | netconomy <netconomy@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c> | 2007-08-17 06:10:56 +0000 |
---|---|---|
committer | netconomy <netconomy@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c> | 2007-08-17 06:10:56 +0000 |
commit | 3d982813b34f6f230baf4a467cdc37ec92a77595 (patch) | |
tree | 85319d39cee2ded1bb7a2b2dd9e8ea37e3778248 /src/main/java/at/knowcenter/wag/egov/egiz/web/servlets | |
parent | 07f6c8f33b2d700276fe6ec6339ff836c8710131 (diff) | |
download | pdf-as-3-3d982813b34f6f230baf4a467cdc37ec92a77595.tar.gz pdf-as-3-3d982813b34f6f230baf4a467cdc37ec92a77595.tar.bz2 pdf-as-3-3d982813b34f6f230baf4a467cdc37ec92a77595.zip |
Performance
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@167 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src/main/java/at/knowcenter/wag/egov/egiz/web/servlets')
6 files changed, 549 insertions, 547 deletions
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/DataURLServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/DataURLServlet.java index 72f7c2d..2844c6d 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/DataURLServlet.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/DataURLServlet.java @@ -4,11 +4,11 @@ package at.knowcenter.wag.egov.egiz.web.servlets;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
@@ -16,26 +16,31 @@ 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 at.gv.egiz.pdfas.exceptions.framework.SignatorException;
+import at.gv.egiz.pdfas.framework.SignatorFactory;
+import at.gv.egiz.pdfas.framework.signator.Signator;
+import at.gv.egiz.pdfas.web.SignSessionInformation;
+import at.gv.egiz.pdfas.web.VerifySessionInformation;
+import at.gv.egiz.pdfas.web.helper.SessionHelper;
+import at.gv.egiz.pdfas.web.helper.SignServletHelper;
+import at.gv.egiz.pdfas.web.helper.TempDirHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import at.knowcenter.wag.egov.egiz.PdfASID;
+import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException;
+import at.knowcenter.wag.egov.egiz.exceptions.InvalidIDException;
import at.knowcenter.wag.egov.egiz.exceptions.PresentableException;
-import at.knowcenter.wag.egov.egiz.framework.Signator;
-import at.knowcenter.wag.egov.egiz.framework.SignatorFactory;
+import at.knowcenter.wag.egov.egiz.exceptions.SignatorFactoryException;
import at.knowcenter.wag.egov.egiz.pdf.SignatureHolder;
import at.knowcenter.wag.egov.egiz.sig.SignatureResponse;
import at.knowcenter.wag.egov.egiz.sig.connectors.ConnectorChooser;
import at.knowcenter.wag.egov.egiz.sig.connectors.LocalConnector;
import at.knowcenter.wag.egov.egiz.sig.connectors.bku.BKUPostConnection;
-import at.knowcenter.wag.egov.egiz.sig.connectors.bku.EnvelopedBase64BKUConnector;
-import at.knowcenter.wag.egov.egiz.sig.connectors.bku.LocRefDetachedBKUConnector;
import at.knowcenter.wag.egov.egiz.web.FormFields;
import at.knowcenter.wag.egov.egiz.web.LocalRequest;
-import at.knowcenter.wag.egov.egiz.web.SessionAttributes;
-import at.knowcenter.wag.egov.egiz.web.SessionInformation;
/**
* @author wprinz
@@ -71,9 +76,10 @@ public class DataURLServlet extends HttpServlet }
protected void dispatchToResults(List results, HttpServletRequest request,
- HttpServletResponse response) throws ServletException, IOException
+ HttpServletResponse response, String backToListURL) throws ServletException, IOException
{
request.setAttribute("results", results);
+ request.setAttribute("btlurl", backToListURL);
dispatch(request, response, "/jsp/results.jsp");
}
@@ -85,122 +91,171 @@ public class DataURLServlet extends HttpServlet {
log.debug("Data URL is accessed."); //$NON-NLS-1$
- HttpSession session = request.getSession(false);
- if (session == null)
+ try
{
- String msg = "There is no session associated with this request."; //$NON-NLS-1$
- log.error(msg);
- throw new ServletException(msg);
- }
+ Object sessionObject = SessionHelper.getSession(request);
+
+ checkRequestCharacterEncoding(request);
+
+ if (sessionObject instanceof SignSessionInformation)
+ {
+ SignSessionInformation si = (SignSessionInformation)sessionObject;
+ processSign(request, response, si);
+ }
+ else
+ {
+ VerifySessionInformation si = (VerifySessionInformation) sessionObject;
+ processVerify(request, response, si);
+ }
- SessionInformation si = (SessionInformation) session.getAttribute(SessionAttributes.ATTRIBUTE_SESSION_INFORMATION);
- if (si == null)
+ }
+ catch (PresentableException e)
{
- String msg = "The session is not found or no longer valid."; //$NON-NLS-1$
- log.error(msg);
- throw new ServletException(msg);
+ log.error(e);
+ SignServlet.prepareDispatchToErrorPage(e, request);
+ dispatch(request, response, "/jsp/error.jsp");
}
- try
+ log.debug("DataURL access finished."); //$NON-NLS-1$
+ }
+
+ protected void checkRequestCharacterEncoding(HttpServletRequest request) throws UnsupportedEncodingException
+ {
+ log.debug("Request character encoding = " + request.getCharacterEncoding()); //$NON-NLS-1$
+// if (request.getCharacterEncoding() == null || request.getCharacterEncoding().equals("UTF-8")) //$NON-NLS-1$
+ if (request.getCharacterEncoding() == null || request.getCharacterEncoding().length() <= 0) //$NON-NLS-1$
+ {
+ log.error("The BKU didn't set a character encoding for the request."); //$NON-NLS-1$
+
+ log.warn("Manually setting character encoding to UTF-8"); //$NON-NLS-1$
+ request.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
+ }
+ }
+
+ protected boolean isNullResponse(String xml_response)
+ {
+ return xml_response.indexOf("NullOperationResponse") >= 0;
+ }
+
+ protected void processSign(HttpServletRequest request, HttpServletResponse response, SignSessionInformation si) throws ServletException, IOException, ConnectorException, SignatorException, SignatorFactoryException
+ {
+ log.trace("processSign");
+
+ String xml_response = request.getParameter("XMLResponse"); //$NON-NLS-1$
+ log.debug("xml_response = " + xml_response); //$NON-NLS-1$
+
+ if (isNullResponse(xml_response))
{
- log.debug("Request character encoding = " + request.getCharacterEncoding()); //$NON-NLS-1$
- if (request.getCharacterEncoding() == null || request.getCharacterEncoding().equals("UTF-8")) //$NON-NLS-1$
- {
- log.error("The BKU didn't set a character encoding for the request."); //$NON-NLS-1$
+ log.debug("Received a NullOperationResponse -> answering with the first request."); //$NON-NLS-1$
- log.warn("Manually setting character encoding to UTF-8"); //$NON-NLS-1$
- request.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
- }
+ assert si.outputAvailable == false;
+ assert si.response_properties == null;
+
+ log.debug("There are still requests to be performed -> answering with request."); //$NON-NLS-1$
- String xml_response = request.getParameter("XMLResponse"); //$NON-NLS-1$
- log.debug("xml_response = " + xml_response); //$NON-NLS-1$
+ LocalRequest local_request = si.localRequest;
- if (isNullResponse(xml_response))
- {
- log.debug("Received a NullOperationResponse -> answering with the first request."); //$NON-NLS-1$
+ String request_string = local_request.getRequestString();
- assert si.current_operation == 0;
- }
- else
+ response.setContentType("text/xml");
+ response.setCharacterEncoding("UTF-8");
+ response.getWriter().println(request_string);
+ }
+ else
+ {
+ log.debug("Recieved a normal response -> storing the response."); //$NON-NLS-1$
+
+ Properties response_properties = new Properties();
+ response_properties.setProperty(BKUPostConnection.RESPONSE_STRING_KEY, xml_response);
+ si.response_properties = response_properties;
+
+ log.debug("All requests have been processed -> processing the responses."); //$NON-NLS-1$
+
+ // Sign
+
+ if (!si.outputAvailable)
{
- log.debug("Recieved a normal response -> storing the response."); //$NON-NLS-1$
+ LocalConnector c = ConnectorChooser.chooseLocalConnectorForSign(si.connector, si.type, "loc ref content not needed here"); //$NON-NLS-1$
+
+ si.si.setSignSignatureObject(c.analyzeSignResponse(si.response_properties));
- Properties response_properties = new Properties();
- response_properties.setProperty(BKUPostConnection.RESPONSE_STRING_KEY, xml_response);
- si.response_properties[si.current_operation] = response_properties;
+ PdfASID algorithm = FormFields.translateSignatureModeToPdfASID(si.mode);
+ Signator signator = SignatorFactory.createSignator(algorithm);
- si.current_operation++;
+ si.output = TempDirHelper.createTempDataSink(si.filename + "_signed.pdf");
+
+ signator.finishSign(si.si, si.output);
+
+ si.outputAvailable = true;
}
- if (si.current_operation < si.requests.length)
- {
- log.debug("There are still requests to be performed -> answering with request #" + si.current_operation); //$NON-NLS-1$
+ SignServletHelper.returnSignResponse(si, response);
- LocalRequest local_request = si.requests[si.current_operation];
+ }
+ }
+
+ protected void processVerify(HttpServletRequest request, HttpServletResponse response, VerifySessionInformation si) throws ServletException, IOException, ConnectorException, InvalidIDException
+ {
+ log.trace("processVerify");
+
+ String xml_response = request.getParameter("XMLResponse"); //$NON-NLS-1$
+ log.debug("xml_response = " + xml_response); //$NON-NLS-1$
- String request_string = local_request.getRequestString();
+ if (isNullResponse(xml_response))
+ {
+ log.debug("Received a NullOperationResponse -> answering with the first request."); //$NON-NLS-1$
- response.setContentType("text/xml");
- response.setCharacterEncoding("UTF-8");
- response.getWriter().println(request_string);
- }
- else
- {
- log.debug("All requests have been processed -> processing the responses."); //$NON-NLS-1$
+ assert si.currentLocalOperation.current_operation == 0;
+ }
+ else
+ {
+ log.debug("Recieved a normal response -> storing the response."); //$NON-NLS-1$
- if (si.application.equals("sign"))
- {
- // Sign
-
- if (si.sign_result == null)
- {
- LocalConnector c = ConnectorChooser.chooseLocalConnectorForSign(si.connector, si.type, "loc ref content not needed here"); //$NON-NLS-1$
+ Properties response_properties = new Properties();
+ response_properties.setProperty(BKUPostConnection.RESPONSE_STRING_KEY, xml_response);
- si.iui.signed_signature_object = c.analyzeSignResponse(si.response_properties[0]);
+ si.currentLocalOperation.finishCurrentOperation(response_properties);
+ }
- PdfASID algorithm = FormFields.translateSignatureModeToPdfASID(si.mode);
- Signator signator = SignatorFactory.createSignator(algorithm);
+ if (!si.currentLocalOperation.isFinished())
+ {
+ log.debug("There are still requests to be performed -> answering with request #" + si.currentLocalOperation.current_operation); //$NON-NLS-1$
- si.sign_result = signator.finishSign(si.iui);
- }
+ LocalRequest local_request = si.currentLocalOperation.getCurrentLocalRequest();
- SignServlet.returnSignResponse(si, response);
- }
- else
+ String request_string = local_request.getRequestString();
+
+ response.setContentType("text/xml");
+ response.setCharacterEncoding("UTF-8");
+ response.getWriter().println(request_string);
+ }
+ else
+ {
+ log.debug("All requests have been processed -> processing the responses."); //$NON-NLS-1$
+
+
+ List results = new ArrayList();
+
+ for (int i = 0; i < si.currentLocalOperation.response_properties.length; i++)
{
- // Verify
+ SignatureHolder sh = (SignatureHolder) si.currentLocalOperation.holders_to_be_verified.get(i);
+
+ PdfASID sig_kz = sh.getSignatureObject().getKZ();
+ String sig_id = sh.getSignatureObject().getSignationIds();
- List results = new ArrayList();
-
- for (int i = 0; i < si.response_properties.length; i++)
- {
- SignatureHolder sh = (SignatureHolder) si.signature_holders.get(i);
-
- PdfASID sig_kz = sh.getSignatureObject().getKZ();
- String sig_id = sh.getSignatureObject().getSignationIds();
-
- LocalConnector c = ConnectorChooser.chooseLocalConnectorForVerify(si.connector, sig_kz, sig_id, si.type, "loc ref content not needed here"); //$NON-NLS-1$
-
- SignatureResponse sig_resp = c.analyzeVerifyResponse(si.response_properties[i]);
- results.add(sig_resp);
- }
-
- dispatchToResults(results, request, response);
+ LocalConnector c = ConnectorChooser.chooseLocalConnectorForVerify(si.connector, sig_kz, sig_id, si.type, "loc ref content not needed here"); //$NON-NLS-1$
+
+ SignatureResponse sig_resp = c.analyzeVerifyResponse(si.currentLocalOperation.response_properties[i]);
+ results.add(sig_resp);
}
- }
- }
- catch (PresentableException e)
- {
- log.error(e);
- SignServlet.prepareDispatchToErrorPage(e, request);
- dispatch(request, response, "/jsp/error.jsp");
- }
+
+ si.currentLocalOperation = null;
- log.debug("DataURL access finished."); //$NON-NLS-1$
- }
+ URL btlURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), request.getContextPath() + "/jsp/verifylist.jsp");
+ String backToListURL = response.encodeURL(btlURL.toString());
+
+ dispatchToResults(results, request, response, backToListURL);
+ }
- protected boolean isNullResponse(String xml_response)
- {
- return xml_response.indexOf("NullOperationResponse") >= 0;
}
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/RetrieveSignatureDataServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/RetrieveSignatureDataServlet.java index 402170c..6653a60 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/RetrieveSignatureDataServlet.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/RetrieveSignatureDataServlet.java @@ -5,22 +5,29 @@ package at.knowcenter.wag.egov.egiz.web.servlets; import java.io.IOException;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletContext;
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 at.gv.egiz.pdfas.impl.input.TextDataSourceImpl;
+import at.gv.egiz.pdfas.exceptions.web.SessionExpiredException;
+import at.gv.egiz.pdfas.framework.input.DataSource;
+import at.gv.egiz.pdfas.web.SignSessionInformation;
+import at.gv.egiz.pdfas.web.VerifySessionInformation;
+import at.gv.egiz.pdfas.web.helper.SessionHelper;
+import at.gv.egiz.pdfas.utils.StreamUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import at.knowcenter.wag.egov.egiz.PdfAS;
+import at.knowcenter.wag.egov.egiz.pdf.BinarySignatureHolder;
import at.knowcenter.wag.egov.egiz.pdf.SignatureHolder;
import at.knowcenter.wag.egov.egiz.sig.SignatureData;
import at.knowcenter.wag.egov.egiz.sig.SignatureDataImpl;
-import at.knowcenter.wag.egov.egiz.sig.SignatureObject;
-import at.knowcenter.wag.egov.egiz.tools.CodingHelper;
-import at.knowcenter.wag.egov.egiz.web.SessionAttributes;
-import at.knowcenter.wag.egov.egiz.web.SessionInformation;
/**
* Retrieves the Signature Data from the session and returns it.
@@ -40,61 +47,103 @@ public class RetrieveSignatureDataServlet extends HttpServlet */
private static Log log = LogFactory.getLog(RetrieveSignatureDataServlet.class);
+ protected void dispatch(HttpServletRequest request,
+ HttpServletResponse response, String resource) throws ServletException, IOException
+ {
+ dispatch(request, response, resource, getServletContext());
+ }
+
+ protected static void dispatch(HttpServletRequest request,
+ HttpServletResponse response, String resource, ServletContext context) throws ServletException, IOException
+ {
+ response.setContentType("text/html");
+ response.setCharacterEncoding("UTF-8");
+
+ RequestDispatcher disp = context.getRequestDispatcher(resource);
+ disp.forward(request, response);
+ }
+
/**
- * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+ * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
+ * javax.servlet.http.HttpServletResponse)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
log.debug("Request for receiving signature data."); //$NON-NLS-1$
-
- HttpSession session = request.getSession(false);
- if (session == null)
+
+ try
{
- String msg = "There is no session associated with this request."; //$NON-NLS-1$
- log.error(msg);
- throw new ServletException(msg);
+ Object sessionObject = SessionHelper.getSession(request);
+
+ if (sessionObject instanceof SignSessionInformation)
+ {
+ SignSessionInformation si = (SignSessionInformation) sessionObject;
+ processSign(request, response, si);
}
-
- SessionInformation si = (SessionInformation) session.getAttribute(SessionAttributes.ATTRIBUTE_SESSION_INFORMATION);
- if (si == null)
+ else
{
- String msg = "The session is not found or no longer valid."; //$NON-NLS-1$
- log.error(msg);
- throw new ServletException(msg);
+ VerifySessionInformation si = (VerifySessionInformation) sessionObject;
+ processVerify(request, response, si);
}
-
+ }
+ catch (SessionExpiredException e)
+ {
+ log.error(e);
+ SignServlet.prepareDispatchToErrorPage(e, request);
+ dispatch(request, response, "/jsp/error.jsp");
+ }
+ }
+
+ protected void processSign(HttpServletRequest request, HttpServletResponse response, SignSessionInformation si) throws ServletException, IOException
+ {
+ writeSignatureData(si.si.getSignatureData(), response);
+ }
+
+ protected void processVerify(HttpServletRequest request, HttpServletResponse response, VerifySessionInformation si) throws ServletException, IOException
+ {
SignatureData sd = null;
- if (si.application.equals("sign"))
+
+ SignatureHolder holder = null;
+
+ if (si.currentLocalOperation != null)
{
- sd = si.iui.signature_data;
+ holder = si.currentLocalOperation.getCurrentSignatureHolder();
}
else
{
- SignatureHolder holder = (SignatureHolder) si.signature_holders.get(si.current_operation);
- SignatureObject s = holder.getSignatureObject();
-
- // TODO make better
- String text_to_be_verified = holder.getSignedText();
- if (holder.getSignatureObject().isBinary())
- {
- byte[] data = CodingHelper.decodeBase64(text_to_be_verified);
- sd = new SignatureDataImpl(data, "application/pdf");
- }
- else
- {
- sd = new SignatureDataImpl(text_to_be_verified.getBytes("UTF-8"), "text/plain", "UTF-8");
- }
-
+ holder = si.moa_holder;
}
+
+ log.debug("holder = " + holder.toString());
- log.debug("Writing " + sd.getMimeType() + " data:"); //$NON-NLS-1$ //$NON-NLS-2$
+ sd = PdfAS.convertSignatureHolderToSignatureData(holder);
+// if (holder.getSignatureObject().isBinary())
+// {
+// BinarySignatureHolder bsh = (BinarySignatureHolder) holder;
+// // byte[] data = CodingHelper.decodeBase64(text_to_be_verified);
+// sd = new SignatureDataImpl(bsh.getSignedPdf(), "application/pdf");
+// }
+// else
+// {
+// String text_to_be_verified = holder.getSignedText();
+// DataSource ds = new TextDataSourceImpl(text_to_be_verified);
+// sd = new SignatureDataImpl(ds, "text/plain", "UTF-8");
+// }
+ log.debug("sd = " + sd.toString() + ", " + sd.getDataSource().getClass().getName() + ", " + sd.getDataSource().getLength() + ", " + sd.getMimeType() + ", " + sd.getCharacterEncoding());
+
+ writeSignatureData(sd, response);
+ }
+
+ protected void writeSignatureData(SignatureData sd, HttpServletResponse response) throws IOException
+ {
+ log.trace("Writing " + sd.getMimeType() + " data:"); //$NON-NLS-1$ //$NON-NLS-2$
+
response.setContentType(sd.getMimeType());
response.setCharacterEncoding(sd.getCharacterEncoding());
- response.getOutputStream().write(sd.getData());
-
- log.debug("Writing SignatureData finished."); //$NON-NLS-1$
- }
+ StreamUtils.writeInputStreamToOutputStream(sd.getDataSource().createInputStream(), response.getOutputStream());
+ // response.getOutputStream().write(sd.getData());
-
+ log.trace("Writing SignatureData finished."); //$NON-NLS-1$
+ }
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignPreviewServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignPreviewServlet.java index 1d8ee0b..aec4f25 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignPreviewServlet.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignPreviewServlet.java @@ -24,13 +24,11 @@ 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 at.knowcenter.wag.egov.egiz.exceptions.ErrorCodeException;
+import at.gv.egiz.pdfas.web.SignSessionInformation;
+import at.gv.egiz.pdfas.web.helper.SessionHelper;
+import at.gv.egiz.pdfas.web.helper.SignServletHelper;
import at.knowcenter.wag.egov.egiz.exceptions.PresentableException;
-import at.knowcenter.wag.egov.egiz.web.FormFields;
-import at.knowcenter.wag.egov.egiz.web.SessionAttributes;
-import at.knowcenter.wag.egov.egiz.web.SessionInformation;
/**
* @author wprinz
@@ -55,34 +53,13 @@ public class SignPreviewServlet extends HttpServlet protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
- SessionInformation si = null;
try
{
- HttpSession session = request.getSession(false);
- if (session == null)
- {
- throw new ErrorCodeException(600, "The session is missing.");
- }
-
- si = (SessionInformation) session.getAttribute(SessionAttributes.ATTRIBUTE_SESSION_INFORMATION);
- if (si == null)
- {
- throw new ErrorCodeException(600, "The session is not found or is no longer valid.");
- }
-
- }
- catch (PresentableException e)
- {
- e.printStackTrace();
- SignServlet.prepareDispatchToErrorPage(e, request);
- dispatch(request, response, "/jsp/error.jsp");
-
- return;
- }
-
- try
- {
- SignServlet.finishSign(si, request, response, getServletContext());
+ Object sessionObject = SessionHelper.getSession(request);
+
+ SignSessionInformation si = (SignSessionInformation) sessionObject;
+
+ SignServletHelper.finishSign(si, request, response, getServletContext());
}
catch (PresentableException e)
{
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 54be8df..3f1342d 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 @@ -22,12 +22,10 @@ import java.io.ByteArrayOutputStream; import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
-import java.util.Properties;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
@@ -35,7 +33,14 @@ 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 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.impl.input.FileBasedPdfDataSourceImpl;
+import at.gv.egiz.pdfas.web.SignSessionInformation;
+import at.gv.egiz.pdfas.web.helper.SignServletHelper;
+import at.gv.egiz.pdfas.web.helper.TempDirHelper;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
@@ -43,39 +48,16 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.log4j.Logger;
import at.knowcenter.wag.egov.egiz.PdfAS;
-import at.knowcenter.wag.egov.egiz.PdfASID;
-import at.knowcenter.wag.egov.egiz.cfg.ConfigLogger;
import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
-import at.knowcenter.wag.egov.egiz.exceptions.ErrorCodeException;
import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
import at.knowcenter.wag.egov.egiz.exceptions.PlaceholderException;
import at.knowcenter.wag.egov.egiz.exceptions.PresentableException;
-import at.knowcenter.wag.egov.egiz.framework.SignResult;
-import at.knowcenter.wag.egov.egiz.framework.Signator;
-import at.knowcenter.wag.egov.egiz.framework.SignatorFactory;
-import at.knowcenter.wag.egov.egiz.framework.signators.DetachedSignator_1_0_0;
import at.knowcenter.wag.egov.egiz.pdf.TablePos;
-import at.knowcenter.wag.egov.egiz.sig.ConnectorFactory;
-import at.knowcenter.wag.egov.egiz.sig.SignatureData;
-import at.knowcenter.wag.egov.egiz.sig.SignatureDataImpl;
-import at.knowcenter.wag.egov.egiz.sig.connectors.Connector;
-import at.knowcenter.wag.egov.egiz.sig.connectors.ConnectorChooser;
-import at.knowcenter.wag.egov.egiz.sig.connectors.LocalConnector;
-import at.knowcenter.wag.egov.egiz.sig.connectors.bku.DetachedBKUConnector;
-import at.knowcenter.wag.egov.egiz.sig.connectors.bku.EnvelopedBase64BKUConnector;
-import at.knowcenter.wag.egov.egiz.sig.connectors.bku.LocRefDetachedBKUConnector;
-import at.knowcenter.wag.egov.egiz.sig.connectors.moa.DetachedLocRefMOAConnector;
-import at.knowcenter.wag.egov.egiz.tools.CodingHelper;
import at.knowcenter.wag.egov.egiz.web.ExternAppInformation;
import at.knowcenter.wag.egov.egiz.web.FormFields;
-import at.knowcenter.wag.egov.egiz.web.LocalRequest;
-import at.knowcenter.wag.egov.egiz.web.LocalRequestHelper;
-import at.knowcenter.wag.egov.egiz.web.PDFContainer;
import at.knowcenter.wag.egov.egiz.web.SessionAttributes;
-import at.knowcenter.wag.egov.egiz.web.SessionInformation;
/**
* This method is the sign servlet for the pdf-as web application. It takes get
@@ -97,15 +79,13 @@ public class SignServlet extends HttpServlet * The log.
*/
private static Log log = LogFactory.getLog(SignServlet.class);
-
- protected void dispatch(HttpServletRequest request,
- HttpServletResponse response, String resource) throws ServletException, IOException
+
+ protected void dispatch(HttpServletRequest request, HttpServletResponse response, String resource) throws ServletException, IOException
{
dispatch(request, response, resource, getServletContext());
}
- protected static void dispatch(HttpServletRequest request,
- HttpServletResponse response, String resource, ServletContext context) throws ServletException, IOException
+ protected static void dispatch(HttpServletRequest request, HttpServletResponse response, String resource, ServletContext context) throws ServletException, IOException
{
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
@@ -181,10 +161,11 @@ public class SignServlet extends HttpServlet UploadedData ud = null;
ExternAppInformation exappinf = null;
TablePos pos = null;
-
+
// check if pdf-as has been called by external webapp
- if(request.getParameter(FormFields.FIELD_PDF_URL) != null) {
-
+ if (request.getParameter(FormFields.FIELD_PDF_URL) != null)
+ {
+
String preview = (String) request.getParameter(FormFields.FIELD_PREVIEW);
String sig_type = (String) request.getParameter(FormFields.FIELD_SIGNATURE_TYPE);
String sig_app = (String) request.getParameter(FormFields.FIELD_CONNECTOR);
@@ -197,65 +178,74 @@ public class SignServlet extends HttpServlet String session_id = (String) request.getParameter(FormFields.FIELD_SESSION_ID);
String sig_pos_y = (String) request.getParameter(FormFields.FIELD_SIGPOS_Y);
String sig_pos_p = (String) request.getParameter(FormFields.FIELD_SIGPOS_P);
-
- try {
- pos = new TablePos("y:" + sig_pos_y +";p:" + sig_pos_p);
- } catch (PDFDocumentException e) {
+
+ try
+ {
+ pos = new TablePos("y:" + sig_pos_y + ";p:" + sig_pos_p);
+ }
+ catch (PDFDocumentException e)
+ {
log.warn("Uanable to create signature position object: " + e.getMessage());
}
-
- String query = pdf_url + "&" + FormFields.FIELD_PDF_ID + "=" + pdf_id;
-
- byte[] extern_pdf = new byte[Integer.parseInt(pdf_length)];
+
+ String query = pdf_url + "&" + FormFields.FIELD_PDF_ID + "=" + pdf_id;
+
+ // wprinz: rem: this allocation is useless
+ // byte[] extern_pdf = new byte[Integer.parseInt(pdf_length)];
URL source_url = new URL(query);
InputStream is = source_url.openStream();
- extern_pdf = toByteArray(is);
-
- // set UploadedData object...
+ // extern_pdf = toByteArray(is);
+
+ // set UploadedData object...
UploadedData ud_extern = new UploadedData();
ud_extern.file_name = filename;
- ud_extern.pdf = extern_pdf;
+ ud_extern.pdfDataSource = TempDirHelper.placePdfIntoTempDir(is, filename);
+ // ud_extern.pdf = extern_pdf;
ud_extern.preview = preview.equalsIgnoreCase("true") ? true : false;
ud_extern.sig_app = sig_app;
ud_extern.sig_mode = sig_mode;
ud_extern.sig_type = sig_type;
-
+
ud = ud_extern;
-
- exappinf = new ExternAppInformation(invoke_url,pdf_id, session_id);
+
+ exappinf = new ExternAppInformation(invoke_url, pdf_id, session_id);
}
- else {
-
+ else
+ {
+
try
{
// tzefferer: modified
- //UploadedData ud = retrieveUploadedDataFromRequest(request);
+ // UploadedData ud = retrieveUploadedDataFromRequest(request);
UploadedData ud_form = retrieveUploadedDataFromRequest(request);
ud = ud_form;
// end modify
-
- } catch(Exception e) {
+
+ }
+ 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.");
dispatch(request, response, "/jsp/error.jsp");
}
}
- try {
+ try
+ {
- PdfAS.applyStrictMode(ud.pdf);
+ PdfAS.applyStrictMode(ud.pdfDataSource);
- SessionInformation si = new SessionInformation(); // SessionTable.generateSessionInformationObject();
+ SignSessionInformation si = new SignSessionInformation(); // SessionTable.generateSessionInformationObject();
si.connector = ud.sig_app;
si.application = "sign";
si.mode = ud.sig_mode;
- si.pdf = ud.pdf;
+ si.pdfDataSource = ud.pdfDataSource;
si.type = ud.sig_type;
si.filename = formatFileName(ud.file_name);
si.download_inline = ud.download_inline;
-
+
// added tzefferer:
si.exappinf = exappinf;
si.pos = pos;
@@ -270,7 +260,7 @@ public class SignServlet extends HttpServlet // si.user_name = user_name;
// si.user_password = user_password;
- prepareSign(si);
+ SignServletHelper.prepareSign(si);
if (ud.preview)
{
@@ -285,7 +275,7 @@ public class SignServlet extends HttpServlet return;
}
- finishSign(si, request, response, getServletContext());
+ SignServletHelper.finishSign(si, request, response, getServletContext());
}
catch (PresentableException e)
{
@@ -296,13 +286,13 @@ public class SignServlet extends HttpServlet }
// tzefferer:added
- public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ {
doPost(request, response);
}
// end add
-
- protected UploadedData retrieveUploadedDataFromRequest(
- HttpServletRequest request) throws ServletException, UnsupportedEncodingException, FileUploadException, PDFDocumentException
+
+ protected UploadedData retrieveUploadedDataFromRequest(HttpServletRequest request) throws ServletException, UnsupportedEncodingException, FileUploadException, PDFDocumentException
{
DiskFileItemFactory fif = new DiskFileItemFactory();
fif.setRepository(SettingsReader.getTemporaryDirectory());
@@ -413,12 +403,22 @@ public class SignServlet extends HttpServlet throw new PDFDocumentException(201, "The provided file '" + doc_file_name + "' doesn't have the PDF extension (.pdf)."); //$NON-NLS-1$//$NON-NLS-2$
}
- byte[] pdf = file_upload_fi.get();
if (file_upload_fi.getSize() <= 0)
{
throw new PDFDocumentException(250, "The document is empty."); //$NON-NLS-1$
}
+ FileBasedPdfDataSourceImpl 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.");
+ }
+ // byte[] pdf = file_upload_fi.get();
+
UploadedData ud = new UploadedData();
ud.preview = preview;
@@ -427,129 +427,55 @@ public class SignServlet extends HttpServlet ud.sig_app = sig_app;
ud.sig_mode = mode;
ud.file_name = doc_file_name;
- ud.pdf = pdf;
+ ud.pdfDataSource = pdfDataSource;
return ud;
}
- /**
- * Prepares the sign.
- *
- * <p>
- * This prepares the data for both being signed or being previewed.
- * </p>
- *
- * @param si
- * The SessionInformation to be prepared.
- * @throws PresentableException
- * f.e.
- */
- public static void prepareSign(SessionInformation si) throws PresentableException
- {
- log.debug("prepareSign:"); //$NON-NLS-1$
-
- PdfASID algorithm = FormFields.translateSignatureModeToPdfASID(si.mode);
- Signator signator = SignatorFactory.createSignator(algorithm);
-
- //tzefferer: modified
- //si.iui = signator.prepareSign(si.pdf, si.type, null, ConnectorFactory.needsSIG_ID(si.connector));
- si.iui = signator.prepareSign(si.pdf, si.type, si.pos, ConnectorFactory.needsSIG_ID(si.connector));
- // end modify
- log.debug("prepareSign finished."); //$NON-NLS-1$
- }
-
- /**
- * Finishes the sign.
- *
- * <p>
- * For non local connectors this concludes the sign process, signs the
- * document and returns the result. For local connectors this initializes the
- * local sign process and redirects to following servlets.
- * </p>
- *
- * @param si
- * The SessionInformation.
- * @param request
- * The servlet request for dispatching.
- * @param response
- * The servlet response for dispatching.
- * @param context
- * The servlet context for dispatching.
- * @throws PresentableException
- * f.e.
- * @throws IOException
- * f. e.
- * @throws ServletException
- * f. e.
- */
- public static void finishSign(SessionInformation si,
- HttpServletRequest request, HttpServletResponse response,
- ServletContext context) throws PresentableException, IOException, ServletException
- {
- log.debug("finishSign:"); //$NON-NLS-1$
-
- log.debug("connector = " + si.connector); //$NON-NLS-1$
- if (ConnectorFactory.isConnectorLocal(si.connector))
- {
- log.debug("Connector is local -> dispatching to local processing."); //$NON-NLS-1$
-
- String dispatch_to = LocalRequestHelper.processLocalSign(si, request, response);
- dispatch(request, response, dispatch_to, context);
- return;
- }
- log.debug("Connector is not local -> finishing the sign."); //$NON-NLS-1$
-
- PdfASID algorithm = FormFields.translateSignatureModeToPdfASID(si.mode);
- Signator signator = SignatorFactory.createSignator(algorithm);
- log.debug("RequestURL = " + request.getRequestURL());
- log.debug("ContextPath = " + request.getContextPath());
- String host = request.getServerName();
- URL signature_data_URL = new URL(request.getScheme(), host, request.getServerPort(), request.getContextPath() + "/RetrieveSignatureData");
- String signature_data_url = response.encodeURL(signature_data_URL.toString());
- Connector c = ConnectorChooser.chooseWebConnectorForSign(si.connector, si.type, signature_data_url);
- si.iui.signed_signature_object = c.doSign(si.iui.signature_data);
- si.sign_result = signator.finishSign(si.iui);
- returnSignResponse(si, response);
-
- log.debug("finishSign finished."); //$NON-NLS-1$
- }
-
- public static void prepareDispatchToErrorPage(PresentableException pe,
- HttpServletRequest request)
+ public static void prepareDispatchToErrorPage(PresentableException pe, HttpServletRequest request)
{
- if (pe instanceof ErrorCodeException)
- {
- ErrorCodeException ece = (ErrorCodeException) pe;
- request.setAttribute("error", "Fehler " + ece.getErrorCode());
+ request.setAttribute("PresentableException", pe);
+// if (pe instanceof ErrorCodeException)
+// {
+ request.setAttribute("error", "Fehler " + pe.getErrorCode());
- String cause = ece.getErrorCodeMessage();
- if (ece.hasExternalErrorMessage())
+ String cause = ErrorCodeHelper.getMessageForErrorCode(pe.getErrorCode());
+
+ if (pe instanceof ExternalErrorException)
{
- cause = ece.getExternalErrorCode() + ": " + ece.getExternalErrorMessage();
+ ExternalErrorException eee = (ExternalErrorException) pe;
+ cause = eee.getExternalErrorCode() + ": " + eee.getExternalErrorMessage();
}
request.setAttribute("cause", cause);
- if (pe instanceof PlaceholderException)
+ if (pe.getErrorCode() == ErrorCode.PLACEHOLDER_EXCEPTION)
{
- PlaceholderException phe = (PlaceholderException) ece;
+ PlaceholderException phe = null;
+ if (pe instanceof PlaceholderException)
+ {
+ phe = (PlaceholderException) pe;
+ }
+ else
+ {
+ phe = (PlaceholderException) pe.getCause();
+ }
- request.setAttribute("cause", "Der Platzhalter des Feldes " + phe.getField() + " ist um " + phe.getMissing() + " Bytes zu kurz. " + ece.getErrorCodeMessage());
+ request.setAttribute("cause", "Der Platzhalter des Feldes " + phe.getField() + " ist um " + phe.getMissing() + " Bytes zu kurz. " + cause);
}
- }
- else
- {
- request.setAttribute("error", "PresentableException");
- request.setAttribute("cause", pe.toString());
- }
+// }
+// else
+// {
+// request.setAttribute("error", "PresentableException");
+// request.setAttribute("cause", pe.toString());
+// }
}
- public void dispatchToPreview(String document_text, String connector,
- String mode, String signature_type, String submit_url,
- HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ public void dispatchToPreview(String document_text, String connector, String mode, String signature_type, String submit_url, HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException
{
request.setAttribute("document_text", document_text);
request.setAttribute("connector", connector);
@@ -576,112 +502,40 @@ public class SignServlet extends HttpServlet return file_name_only;
}
- /**
- * Formats the file name according to the SignResult.
- *
- * @param file_name
- * The file name.
- * @param sign_result
- * The sign result.
- * @return Returns the formatted file name.
- */
- public static String formatFileNameForSignResult(String file_name,
- SignResult sign_result)
- {
- String output = file_name + "_signed";
- if (sign_result.getMimeType().equals(DetachedSignator_1_0_0.MIME_TYPE))
- {
- output += ".xml";
- }
- else
- {
- output += ".pdf";
- }
- return output;
- }
- /**
- * Returns the data in the SignResult with proper content disposition.
- *
- * @param si
- * SessionInformation.
- * @param response
- * The servlet response.
- * @throws IOException
- * The IO Exception.
- */
- public static void returnSignResponse(SessionInformation si,
- HttpServletResponse response) throws IOException
- {
- SignResult sign_result = si.sign_result;
-
- String file_name = formatFileNameForSignResult(si.filename, sign_result);
-
- // tzefferer: added condition
- if (si.exappinf == null) {
-
- // The name parameter is actually deprecated in favour of
- // Content-Disposition filename
- // Unfortunately Acrobat reader does recognize neither of these parameters
- // with its inline save-as. It always takes the page name.
- response.setContentType(sign_result.getMimeType() + "; name=\"" + file_name + "\"");
- if (si.download_inline)
- {
- response.addHeader("Content-Disposition", "inline; filename=\"" + file_name + "\"");
- }
- else
- {
- response.addHeader("Content-Disposition", "attachment; filename=\"" + file_name + "\"");
- }
- response.getOutputStream().write(sign_result.getData());
- // tzefferer: added else-block
- } else {
- SignResult sr = si.sign_result;
- byte[] signed_pdf = sr.getData();
- PDFContainer entry = new PDFContainer(signed_pdf, si.exappinf.pdf_id);
- ProvidePDFServlet.signedDocuments.add(entry);
-
- // notify webapp...
- String invoke_url = si.exappinf.invoke_url;
-
- String providePDFServlet = "ProvidePDF";
- String pdf_id = String.valueOf(si.exappinf.pdf_id);
- String session_id = si.exappinf.session_id;
-
- // build URL
- int ind = invoke_url.indexOf("?");
- String query = invoke_url.substring(0, ind) + ";jsessionid=" + session_id + invoke_url.substring(ind) + "&" + FormFields.FIELD_PDF_URL + "=" + providePDFServlet + "&" + FormFields.FIELD_PDF_ID + "=" + pdf_id + "&" + FormFields.FIELD_FILE_LENGTH + "=" + signed_pdf.length;
- response.sendRedirect(query);
-
- }
- }
-
-
// tzefferer: added
- public static byte[] toByteArray(InputStream inputStream) throws IOException {
-
- if(inputStream == null) {
+ public static byte[] toByteArray(InputStream inputStream) throws IOException
+ {
+
+ if (inputStream == null)
+ {
return null;
}
-
+
ByteArrayOutputStream out = new ByteArrayOutputStream(8192);
int n;
byte[] buffer = new byte[2048];
BufferedInputStream bufIn = new BufferedInputStream(inputStream);
- try {
- while ((n = bufIn.read(buffer)) != -1) {
+ try
+ {
+ while ((n = bufIn.read(buffer)) != -1)
+ {
out.write(buffer, 0, n);
}
- } finally {
- if(bufIn != null) {
+ }
+ finally
+ {
+ if (bufIn != null)
+ {
bufIn.close();
}
}
return out.toByteArray();
}
+
// end add
protected static class UploadedData
@@ -698,6 +552,7 @@ public class SignServlet extends HttpServlet protected String file_name = null;
- protected byte[] pdf = null;
+ protected FileBasedPdfDataSourceImpl pdfDataSource = null;
+ // protected byte[] pdf = null;
}
}
\ No newline at end of file diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyPreviewServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyPreviewServlet.java index 150b592..732e6cc 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyPreviewServlet.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyPreviewServlet.java @@ -20,6 +20,7 @@ package at.knowcenter.wag.egov.egiz.web.servlets; import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
@@ -30,19 +31,22 @@ 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.log4j.Logger;
-
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import at.gv.egiz.pdfas.framework.input.TextDataSource;
+import at.gv.egiz.pdfas.utils.StreamUtils;
+import at.gv.egiz.pdfas.web.VerifySessionInformation;
+import at.gv.egiz.pdfas.web.helper.SessionHelper;
+import at.gv.egiz.pdfas.web.helper.TempDirHelper;
import at.knowcenter.wag.egov.egiz.PdfAS;
import at.knowcenter.wag.egov.egiz.PdfASID;
-import at.knowcenter.wag.egov.egiz.cfg.ConfigLogger;
import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
-import at.knowcenter.wag.egov.egiz.exceptions.ErrorCodeException;
import at.knowcenter.wag.egov.egiz.exceptions.InvalidIDException;
import at.knowcenter.wag.egov.egiz.exceptions.PresentableException;
import at.knowcenter.wag.egov.egiz.exceptions.SignatureException;
@@ -55,8 +59,6 @@ import at.knowcenter.wag.egov.egiz.sig.SignatureObject; import at.knowcenter.wag.egov.egiz.sig.SignatureTypes;
import at.knowcenter.wag.egov.egiz.web.FormFields;
import at.knowcenter.wag.egov.egiz.web.LocalRequestHelper;
-import at.knowcenter.wag.egov.egiz.web.SessionAttributes;
-import at.knowcenter.wag.egov.egiz.web.SessionInformation;
/**
* @author wprinz
@@ -71,7 +73,7 @@ public class VerifyPreviewServlet extends HttpServlet /**
* The logger.
*/
- private static final Logger logger_ = ConfigLogger.getLogger(VerifyPreviewServlet.class);
+ private static final Log logger_ = LogFactory.getLog(VerifyPreviewServlet.class);
protected void dispatch(HttpServletRequest request,
HttpServletResponse response, String resource) throws ServletException, IOException
@@ -82,7 +84,29 @@ public class VerifyPreviewServlet extends HttpServlet RequestDispatcher disp = getServletContext().getRequestDispatcher(resource);
disp.forward(request, response);
}
+
+ protected void dispatchToPreview(HttpServletRequest request, HttpServletResponse response, int verify_which)throws ServletException, IOException
+ {
+ request.setAttribute(FormFields.FIELD_VERIFY_WHICH, new Integer(verify_which));
+ request.setAttribute("btlurl", formBackToListURL(request, response));
+ dispatch(request, response, "/jsp/verifypreview.jsp");
+
+ }
+ protected void dispatchToDataOk(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
+ {
+ request.setAttribute("btlurl", formBackToListURL(request, response));
+ dispatch(request, response, "/jsp/dataok.jsp");
+ }
+
+ protected String formBackToListURL(HttpServletRequest request, HttpServletResponse response) throws MalformedURLException
+ {
+ URL btlURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), request.getContextPath() + "/jsp/verifylist.jsp");
+ String backToListURL = response.encodeURL(btlURL.toString());
+
+ return backToListURL;
+ }
+
protected static String generateNamePrefix(int num)
{
return SIG_INPUT_PREFIX + num + "_";
@@ -249,6 +273,10 @@ public class VerifyPreviewServlet extends HttpServlet {
continue;
}
+ if (SignatureTypes.SIG_KZ.equals(key) && value == null)
+ {
+ continue;
+ }
value = value.replaceAll("\\s", " ");
value = value.replaceAll("\\\"", "\\\"");
@@ -281,6 +309,10 @@ public class VerifyPreviewServlet extends HttpServlet {
continue;
}
+ if (SignatureTypes.SIG_KZ.equals(key) && value == null)
+ {
+ continue;
+ }
writer.println(" <tr>");
writer.println(" <td width=\"10%\"><span class=\"sca\">" + caption + ":</span></td>");
@@ -355,10 +387,11 @@ public class VerifyPreviewServlet extends HttpServlet }
protected void dispatchToResults(List results, HttpServletRequest request,
- HttpServletResponse response, boolean backbutton) throws ServletException, IOException
+ HttpServletResponse response, boolean backbutton, String backToListURL) throws ServletException, IOException
{
request.setAttribute("results", results);
request.setAttribute("backbutton", backbutton ? "true" : "false");
+ request.setAttribute("btlurl", backToListURL);
dispatch(request, response, "/jsp/results.jsp");
}
@@ -459,37 +492,12 @@ public class VerifyPreviewServlet extends HttpServlet protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
- SessionInformation si = null;
- HttpSession session = null;
- try
- {
- session = request.getSession(false);
- // String session_id_string = request.getParameter("session");
- if (session == null)
- {
- throw new ErrorCodeException(600, "The session is missing.");
- }
-
- si = (SessionInformation) session.getAttribute(SessionAttributes.ATTRIBUTE_SESSION_INFORMATION);
- // long session_id = Long.parseLong(session_id_string);
- // si = SessionTable.get(session_id);
- if (si == null)
- {
- throw new ErrorCodeException(600, "The session is not found or is no longer valid.");
- }
-
- }
- catch (PresentableException e)
- {
- e.printStackTrace();
- SignServlet.prepareDispatchToErrorPage(e, request);
- dispatch(request, response, "/jsp/error.jsp");
-
- return;
- }
-
try
{
+ Object sessionObject = SessionHelper.getSession(request);
+
+ VerifySessionInformation si = (VerifySessionInformation)sessionObject;
+
int verify_which = -1;
boolean preview = false;
@@ -526,7 +534,7 @@ public class VerifyPreviewServlet extends HttpServlet }
SignatureHolder holder = (SignatureHolder) si.signature_holders.get(verify_which);
- si.current_operation = verify_which;
+// si.current_operation = verify_which;
holders_to_verify = new ArrayList();
holders_to_verify.add(holder);
@@ -536,15 +544,17 @@ public class VerifyPreviewServlet extends HttpServlet {
BinarySignatureHolder binary_holder = (BinarySignatureHolder) holder;
response.setContentType("application/pdf");
- response.getOutputStream().write(binary_holder.getSignedPdf(), 0, binary_holder.getSignedPdfLength());
+ StreamUtils.writeInputStreamToOutputStream(binary_holder.getSignedPdf().createInputStream(), response.getOutputStream());
+// response.getOutputStream().write(binary_holder.getSignedPdf(), 0, binary_holder.getSignedPdfLength());
}
else
// if (holder.getSignatureObject().isTextual())
{
// formatPreview(holders_to_verify, si.connector, request,
// response);
- request.setAttribute(FormFields.FIELD_VERIFY_WHICH, new Integer(verify_which));
- dispatch(request, response, "/jsp/verifypreview.jsp");
+// request.setAttribute(FormFields.FIELD_VERIFY_WHICH, new Integer(verify_which));
+
+ dispatchToPreview(request, response, verify_which);
}
return;
@@ -554,10 +564,12 @@ public class VerifyPreviewServlet extends HttpServlet if (ConnectorFactory.isConnectorLocal(si.connector))
{
- List temp_holder = new ArrayList(si.signature_holders);
-
- si.copy_of_signature_holders = temp_holder;
- si.signature_holders = holders_to_verify;
+ // what is this for? si.signature_holders must not be modified after extraction
+ // TODO this seems to be buggy bug fixing - remove
+// List temp_holder = new ArrayList(si.signature_holders);
+//
+// si.copy_of_signature_holders = temp_holder;
+// si.signature_holders = holders_to_verify;
String dispatch_to = LocalRequestHelper.processLocalVerify(si, holders_to_verify, request, response);
dispatch(request, response, dispatch_to);
@@ -575,7 +587,9 @@ public class VerifyPreviewServlet extends HttpServlet {
backbutton = false;
}
- dispatchToResults(results, request, response, backbutton);
+ URL btlURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), request.getContextPath() + "/jsp/verifylist.jsp");
+ String backToListURL = response.encodeURL(btlURL.toString());
+ dispatchToResults(results, request, response, backbutton, backToListURL);
}
catch (PresentableException e)
@@ -588,41 +602,17 @@ public class VerifyPreviewServlet extends HttpServlet protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
- SessionInformation si = null;
- HttpSession session = null;
- try
- {
- session = request.getSession(false);
- // String session_id_string = request.getParameter("session");
- if (session == null)
- {
- throw new ErrorCodeException(600, "The session is missing.");
- }
-
- si = (SessionInformation) session.getAttribute(SessionAttributes.ATTRIBUTE_SESSION_INFORMATION);
- // long session_id = Long.parseLong(session_id_string);
- // si = SessionTable.get(session_id);
- if (si == null)
- {
- throw new ErrorCodeException(600, "The session is not found or is no longer valid.");
- }
-
- }
- catch (PresentableException e)
- {
- e.printStackTrace();
- SignServlet.prepareDispatchToErrorPage(e, request);
- dispatch(request, response, "/jsp/error.jsp");
-
- return;
- }
-
DiskFileItemFactory fif = new DiskFileItemFactory();
fif.setRepository(SettingsReader.getTemporaryDirectory());
ServletFileUpload sfu = new ServletFileUpload(fif);
try
{
+ Object sessionObject = SessionHelper.getSession(request);
+
+ VerifySessionInformation si = (VerifySessionInformation)sessionObject;
+
+
String text_to_be_verified = null;
SignatureObject signature_object = new SignatureObject();
@@ -671,13 +661,17 @@ public class VerifyPreviewServlet extends HttpServlet logger_.debug("sig_obj_number" + key + " = " + value);
}
- SignatureHolder new_holder = new TextualSignatureHolder(text_to_be_verified, signature_object);
+ SignatureHolder old_holder = (SignatureHolder) si.signature_holders.get(verify_which);
+ TempDirHelper.deleteDataSourceIfFileBased(old_holder.getDataSource());
+
+ TextDataSource tds = TempDirHelper.placeTextIntoTempDir(text_to_be_verified, "_previewholder.utf8.txt");
+ SignatureHolder new_holder = new TextualSignatureHolder(tds, signature_object);
si.signature_holders.set(verify_which, new_holder);
if (verify == false)
{
- dispatch(request, response, "/dataok.html");
+ dispatchToDataOk(request, response);
return;
}
@@ -707,7 +701,10 @@ public class VerifyPreviewServlet extends HttpServlet String loc_ref_url = response.encodeURL(loc_ref_URL.toString());
List results = PdfAS.verifySignatureHoldersWeb(holders_to_verify, si, loc_ref_url);
- dispatchToResults(results, request, response, true);
+
+ URL btlURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), request.getContextPath() + "/jsp/verifylist.jsp");
+ String backToListURL = response.encodeURL(btlURL.toString());
+ dispatchToResults(results, request, response, true, backToListURL);
}
catch (FileUploadException e)
{
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyServlet.java index b53a9a1..bb6a13f 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyServlet.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyServlet.java @@ -36,16 +36,22 @@ import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import at.gv.egiz.pdfas.framework.config.SettingsHelper;
+import at.gv.egiz.pdfas.framework.input.DataSource;
+import at.gv.egiz.pdfas.framework.input.ExtractionStage;
+import at.gv.egiz.pdfas.framework.input.PdfDataSource;
+import at.gv.egiz.pdfas.framework.input.TextDataSource;
+import at.gv.egiz.pdfas.framework.vfilter.VerificationFilterParameters;
+import at.gv.egiz.pdfas.web.VerifySessionInformation;
+import at.gv.egiz.pdfas.web.helper.TempDirHelper;
import at.knowcenter.wag.egov.egiz.PdfAS;
import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
import at.knowcenter.wag.egov.egiz.exceptions.PresentableException;
-import at.knowcenter.wag.egov.egiz.framework.VerificationFilter;
import at.knowcenter.wag.egov.egiz.sig.ConnectorFactory;
import at.knowcenter.wag.egov.egiz.web.FormFields;
import at.knowcenter.wag.egov.egiz.web.LocalRequestHelper;
import at.knowcenter.wag.egov.egiz.web.SessionAttributes;
-import at.knowcenter.wag.egov.egiz.web.SessionInformation;
/**
* This method is the verify servlet for the pdf-as web application. It takes
@@ -68,8 +74,7 @@ public class VerifyServlet extends HttpServlet */
private static Log log = LogFactory.getLog(SignServlet.class);
- protected void dispatch(HttpServletRequest request,
- HttpServletResponse response, String resource) throws ServletException, IOException
+ protected void dispatch(HttpServletRequest request, HttpServletResponse response, String resource) throws ServletException, IOException
{
response.setContentType("text/html"); //$NON-NLS-1$
response.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
@@ -78,8 +83,7 @@ public class VerifyServlet extends HttpServlet disp.forward(request, response);
}
- protected void dispatchToResults(List results, HttpServletRequest request,
- HttpServletResponse response) throws ServletException, IOException
+ protected void dispatchToResults(List results, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
request.setAttribute("results", results); //$NON-NLS-1$
dispatch(request, response, "/jsp/results.jsp"); //$NON-NLS-1$
@@ -97,16 +101,20 @@ public class VerifyServlet extends HttpServlet {
UploadedData ud = retrieveUploadedDataFromRequest(request);
- List signature_holders = extractSignatureHoldersFromFile(ud.file_name, ud.file_data);
-
- SessionInformation si = new SessionInformation(); // SessionTable.generateSessionInformationObject();
+ VerifySessionInformation si = new VerifySessionInformation();
si.connector = ud.sig_app;
si.application = "verify";
si.mode = null;
- si.pdf = null;
+ si.inputDataSource = ud.dataSource;
si.type = null;
- si.user_name = null;
- si.user_password = null;
+// si.user_name = null;
+// si.user_password = null;
+
+ // List signature_holders = extractSignatureHoldersFromFile(ud.file_name,
+ // ud.file_data);
+ List signature_holders = extractSignatureHolders(ud.dataSource);
+
+ TempDirHelper.storeTextSignatureHoldersIfApplicable(signature_holders, "_textholder.utf8.txt");
si.signature_holders = signature_holders;
@@ -123,7 +131,7 @@ public class VerifyServlet extends HttpServlet if (ConnectorFactory.isConnectorLocal(si.connector))
{
String dispatch_to = LocalRequestHelper.processLocalVerify(si, si.signature_holders, request, response);
-
+
dispatch(request, response, dispatch_to);
return;
}
@@ -151,9 +159,8 @@ public class VerifyServlet extends HttpServlet }
}
-
- protected UploadedData retrieveUploadedDataFromRequest(
- HttpServletRequest request) throws ServletException, UnsupportedEncodingException, FileUploadException, PDFDocumentException
+
+ protected UploadedData retrieveUploadedDataFromRequest(HttpServletRequest request) throws ServletException, UnsupportedEncodingException, FileUploadException, PDFDocumentException
{
DiskFileItemFactory fif = new DiskFileItemFactory();
fif.setRepository(SettingsReader.getTemporaryDirectory());
@@ -165,6 +172,9 @@ public class VerifyServlet extends HttpServlet FileItem connector_fi = null;
// FileItem mode_fi = null;
FileItem preview_fi = null;
+
+ String characterEncoding = request.getCharacterEncoding();
+ log.debug("request character encoding = " + characterEncoding);
{
Iterator it = items.iterator();
@@ -229,7 +239,7 @@ public class VerifyServlet extends HttpServlet String preview_str = preview_fi.getString("UTF-8"); //$NON-NLS-1$
if (!preview_str.equals(FormFields.VALUE_TRUE) && !preview_str.equals(FormFields.VALUE_FALSE))
{
- throw new ServletException("The preview '" + preview_str + "' is unrecognized."); //$NON-NLS-1$//$NON-NLS-2$
+ throw new ServletException("The preview '" + preview_str + "' is unrecognized."); //$NON-NLS-1$//$NON-NLS-2$
}
boolean preview = false;
if (preview_str.equals(FormFields.VALUE_TRUE))
@@ -238,40 +248,59 @@ public class VerifyServlet extends HttpServlet }
// process the request
- log.debug("file content type =" + upload_fi.getContentType()); //$NON-NLS-1$
- log.debug("file size = " + upload_fi.getSize()); //$NON-NLS-1$
- if (upload_fi.getSize() <= 0)
- {
- throw new PDFDocumentException(250, "The document is empty."); //$NON-NLS-1$
- }
- byte[] document_bytes = upload_fi.get();
+ DataSource dataSource = convertUploadToDataSource(upload_fi);
UploadedData ud = new UploadedData();
ud.preview = preview;
ud.sig_app = connector;
ud.file_name = upload_fi.getName();
- ud.file_data = document_bytes;
+ ud.dataSource = dataSource;
+ // ud.file_data = document_bytes;
return ud;
}
-
- protected List extractSignatureHoldersFromFile (String file_name, byte [] data) throws UnsupportedEncodingException, PresentableException
+
+ protected DataSource convertUploadToDataSource(FileItem upload_fi) throws PDFDocumentException
{
- VerificationFilter vf = new VerificationFilter();
- List signature_holders = null;
+ log.debug("file content type =" + upload_fi.getContentType()); //$NON-NLS-1$
+ log.debug("file size = " + upload_fi.getSize()); //$NON-NLS-1$
+ if (upload_fi.getSize() <= 0)
+ {
+ throw new PDFDocumentException(250, "The document is empty."); //$NON-NLS-1$
+ }
- String extension = extractExtension(file_name);
+ if (upload_fi.getContentType() != null && upload_fi.getContentType().equals("application/pdf"))
+ {
+ try
+ {
+ PdfDataSource pdfDataSource = TempDirHelper.placePdfIntoTempDir(upload_fi.getInputStream(), upload_fi.getName());
+ return pdfDataSource;
+ }
+ catch (IOException e)
+ {
+ throw new PDFDocumentException(201, "The document could not be placed in the temp dir.", e); //$NON-NLS-1$
+ }
+ // byte[] document_bytes = upload_fi.get();
+ }
- String raw_text = null;
- if (file_name == null || (extension != null && extension.equals("txt"))) //$NON-NLS-1$
+ try
{
- raw_text = new String(data, "UTF-8"); //$NON-NLS-1$
- signature_holders = vf.extractSignaturesFromPlainText(raw_text);
+ String text = new String(upload_fi.get(), "UTF-8"); //$NON-NLS-1$
+ TextDataSource textDataSource = TempDirHelper.placeTextIntoTempDir(text, upload_fi.getName());
+ return textDataSource;
}
- else
+ catch (IOException e)
{
- signature_holders = vf.extractSignaturesFromPdf(data);
+ throw new PDFDocumentException(201, e);
}
+ }
+
+ protected List extractSignatureHolders(DataSource dataSource) throws PresentableException
+ {
+ VerificationFilterParameters parameters = SettingsHelper.readVerificationFilterParametersFromSettings();
+
+ ExtractionStage es = new ExtractionStage();
+ List signature_holders = es.extractSignatureHolders(dataSource, parameters);
if (signature_holders.size() == 0)
{
@@ -281,6 +310,45 @@ public class VerifyServlet extends HttpServlet return signature_holders;
}
+ // TODO obsolete method - remove
+ // protected List extractSignatureHoldersFromFile(String file_name, byte[]
+ // data) throws UnsupportedEncodingException, PresentableException
+ // {
+ // VerificationFilterParameters parameters = new
+ // VerificationFilterParametersImpl(false, false, true);
+ // ExtractionStage es = new ExtractionStage();
+ // // VerificationFilter vf = new VerificationFilter();
+ // List signature_holders = null;
+ //
+ // String extension = extractExtension(file_name);
+ //
+ // String raw_text = null;
+ // if (file_name == null || (extension != null && extension.equals("txt")))
+ // //$NON-NLS-1$
+ // {
+ // raw_text = new String(data, "UTF-8"); //$NON-NLS-1$
+ //
+ // signature_holders = es.extractSignatureHolders(new
+ // TextDataSourceImpl(raw_text), parameters);
+ // // signature_holders = vf.extractSignaturesFromPlainText(raw_text);
+ // }
+ // else
+ // {
+ // signature_holders = es.extractSignatureHolders(new
+ // ByteArrayPdfDataSourceImpl(data), parameters);
+ //
+ // // signature_holders = vf.extractSignaturesFromPdf(data);
+ // }
+ //
+ // if (signature_holders.size() == 0)
+ // {
+ // throw new PDFDocumentException(206, "PDF document not signed.");
+ // //$NON-NLS-1$
+ // }
+ //
+ // return signature_holders;
+ // }
+
/**
* Extracts the extension from a file name string.
*
@@ -317,6 +385,7 @@ public class VerifyServlet extends HttpServlet protected String file_name = null;
- protected byte[] file_data = null;
+ protected DataSource dataSource = null;
+ // protected byte[] file_data = null;
}
}
\ No newline at end of file |