diff options
Diffstat (limited to 'simpleSigning/src/main/java/at/gv/egiz/simpleSigning/FinishSignature.java')
-rw-r--r-- | simpleSigning/src/main/java/at/gv/egiz/simpleSigning/FinishSignature.java | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/FinishSignature.java b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/FinishSignature.java new file mode 100644 index 0000000..33ad8fd --- /dev/null +++ b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/FinishSignature.java @@ -0,0 +1,94 @@ +package at.gv.egiz.simpleSigning; + +import java.io.IOException; +import java.io.OutputStream; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.io.FileUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.gv.egiz.simpleSigning.helper.SessionHelper; + +@WebServlet("/Finish") +public class FinishSignature extends HttpServlet { + + /** + * + */ + private static final long serialVersionUID = 7338000172211889255L; + + private static final String PARAM_PDFURL = "pdfurl"; + + private static final Logger logger = LoggerFactory + .getLogger(FinishSignature.class); + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + this.doProcess(req, resp); + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + this.doProcess(req, resp); + } + + protected void doProcess(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + try { + logger.info("[" + req.getSession().getId() + + "]: finishing Signature"); + + String pdfUrl = req.getParameter(PARAM_PDFURL); + + logger.info("[" + req.getSession().getId() + "]: EventID {}", + SessionHelper.getEventID(req)); + logger.info("[" + req.getSession().getId() + "]: PDFURL: {}", + pdfUrl); + logger.info("[" + req.getSession().getId() + "]: TargetURL: {}", + SessionHelper.getTargetURL(req)); + + // Generate JS Code to postMessage to EventId with Success + + String success = FileUtils.readFileToString(FileUtils + .toFile(PDFASJsServlet.class + .getResource("/js/success_response.js"))); + + success = success.replace("##REPLACE##EVENTID##", + SessionHelper.getEventID(req)); + success = success.replace("##REPLACE##URL##", pdfUrl); + success = success.replace("##REPLACE##TARGETURL##", + SessionHelper.getTargetURL(req)); + + String postman = FileUtils + .readFileToString(FileUtils.toFile(PDFASJsServlet.class + .getResource("/js/postman.js"))); + + String combined = postman + success; + + String html = FileUtils.readFileToString(FileUtils + .toFile(PDFASJsServlet.class + .getResource("/html/script_exec.html"))); + + html = html.replace("##REPLACE##SCRIPT##", combined); + + SessionHelper.killSession(req); + + resp.setContentType("text/html"); + OutputStream os = resp.getOutputStream(); + os.write(html.getBytes()); + os.close(); + } catch (Throwable e) { + logger.error("[" + req.getSession().getId() + + "]: failed to finish signature", e); + throw new ServletException("Generic Exception"); + } + } +} |