From cdfd4153809a9f1f5fed903b06e19f92cdd10d1a Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Tue, 22 Jul 2014 10:14:21 +0200 Subject: einfach Signieren first commit --- .../at/gv/egiz/simpleSigning/ErrorSignature.java | 124 +++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 simpleSigning/src/main/java/at/gv/egiz/simpleSigning/ErrorSignature.java (limited to 'simpleSigning/src/main/java/at/gv/egiz/simpleSigning/ErrorSignature.java') diff --git a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/ErrorSignature.java b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/ErrorSignature.java new file mode 100644 index 0000000..446d1c1 --- /dev/null +++ b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/ErrorSignature.java @@ -0,0 +1,124 @@ +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("/Error") +public class ErrorSignature extends HttpServlet { + + /** + * + */ + private static final long serialVersionUID = 7338000172211889255L; + + public static final String PARAM_ERROR = "error"; + public static final String PARAM_CAUSE = "cause"; + + private static final Logger logger = LoggerFactory + .getLogger(ErrorSignature.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() + + "]: error Signature"); + + String error = req.getParameter(PARAM_ERROR); + + if (error == null) { + if (req.getAttribute(PARAM_ERROR) != null) { + error = req.getAttribute(PARAM_ERROR).toString(); + } + } + + if (error == null) { + error = "UNKNOWN ERROR"; + } + + logger.info("[" + req.getSession().getId() + "]: Error: {}", + error); + + String cause = req.getParameter(PARAM_CAUSE); + + if (cause == null) { + if (req.getAttribute(PARAM_CAUSE) != null) { + cause = req.getAttribute(PARAM_CAUSE).toString(); + } + } + + if (cause == null) { + cause = "UNKNOWN CAUSE"; + } + + logger.info("[" + req.getSession().getId() + "]: Cause: {}", + cause); + + + String errorJS = FileUtils.readFileToString(FileUtils + .toFile(PDFASJsServlet.class + .getResource("/js/error_response.js"))); + + String targetURL = SessionHelper.getTargetURL(req); + + if (targetURL == null) { + targetURL = "invalidURL"; + } + + logger.info("[" + req.getSession().getId() + "]: TargetURL: {}", + targetURL); + + errorJS = errorJS.replace("##REPLACE##ERROR##", error); + errorJS = errorJS.replace("##REPLACE##CAUSE##", cause); + errorJS = errorJS.replace("##REPLACE##TARGETURL##", targetURL); + + String postman = FileUtils + .readFileToString(FileUtils.toFile(PDFASJsServlet.class + .getResource("/js/postman.js"))); + + String combined = postman + errorJS; + + 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 error signature", e); + throw new ServletException("Generic Exception"); + } + } +} -- cgit v1.2.3