diff options
author | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2015-07-14 13:27:56 +0200 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2015-07-14 13:27:56 +0200 |
commit | 030ad8ea8455922ad59c095d3a9ecbfc462ff69f (patch) | |
tree | 3fb0ab24b8432dae25efab6ef3e3b77bd623b1d5 /pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PDFPositioningDataServlet.java | |
parent | 38a852e11c1edd313ab0882ac7bda00a82546fbb (diff) | |
download | pdf-as-4-030ad8ea8455922ad59c095d3a9ecbfc462ff69f.tar.gz pdf-as-4-030ad8ea8455922ad59c095d3a9ecbfc462ff69f.tar.bz2 pdf-as-4-030ad8ea8455922ad59c095d3a9ecbfc462ff69f.zip |
many fixes for html5 js viewer integration
Diffstat (limited to 'pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PDFPositioningDataServlet.java')
-rw-r--r-- | pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PDFPositioningDataServlet.java | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PDFPositioningDataServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PDFPositioningDataServlet.java new file mode 100644 index 00000000..95307c9c --- /dev/null +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PDFPositioningDataServlet.java @@ -0,0 +1,70 @@ +package at.gv.egiz.pdfas.web.servlets; + +import java.io.IOException; +import java.io.OutputStream; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.gv.egiz.pdfas.common.exceptions.PdfAsException; +import at.gv.egiz.pdfas.web.helper.PdfAsHelper; + +public class PDFPositioningDataServlet extends HttpServlet { + + /** + * + */ + private static final long serialVersionUID = -8729046942909293640L; + + public static final String PARAM_TOKEN = "token"; + + private static final Logger logger = LoggerFactory + .getLogger(PDFPositioningDataServlet.class); + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse + * response) + */ + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + this.process(request, response); + } + + protected void process(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + try { + logger.debug("Access to pdf data"); + String token = request.getParameter(PARAM_TOKEN); + + if (token == null) { + logger.warn("No access token provided"); + throw new PdfAsException("No access token provided"); + } + + logger.debug("Access to pdf data with token: {}", token); + + byte[] pdfData = PdfAsHelper.getPdfData(request); + + if(pdfData == null) { + logger.warn("No PDF Data available or token does not match"); + throw new PdfAsException("No PDF Data available"); + } + + response.setContentType("application/pdf"); + OutputStream os = response.getOutputStream(); + os.write(pdfData); + os.close(); + } catch (Throwable e) { + PdfAsHelper.clearPdfData(request); + logger.error("Failed to access pdf data for positioning!"); + PdfAsHelper.setSessionException(request, response, e.getMessage(), + e); + PdfAsHelper.gotoError(getServletContext(), request, response); + } + } +} |