From 82ac22ffefde9efe00255b008a5cbf892fb09063 Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Tue, 19 Aug 2014 10:27:01 +0200 Subject: Removed Annotation based servlet configuration, added Version Servlet --- .../at/gv/egiz/simpleSigning/VersionServlet.java | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 simpleSigning/src/main/java/at/gv/egiz/simpleSigning/VersionServlet.java (limited to 'simpleSigning/src/main/java/at/gv/egiz/simpleSigning/VersionServlet.java') diff --git a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/VersionServlet.java b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/VersionServlet.java new file mode 100644 index 0000000..4e03834 --- /dev/null +++ b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/VersionServlet.java @@ -0,0 +1,86 @@ +package at.gv.egiz.simpleSigning; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.jar.Attributes; +import java.util.jar.Manifest; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class VersionServlet extends HttpServlet { + + /** + * + */ + private static final long serialVersionUID = 6716170050447201588L; + + @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 { + StringBuilder sb = new StringBuilder(); + sb.append("{\"version\": \""); + sb.append(getVersion()); + sb.append("\", \"scm\": \""); + sb.append(getSCMRevision()); + sb.append("\"}"); + + resp.setContentType("application/json"); + OutputStream os = resp.getOutputStream(); + os.write(sb.toString().getBytes()); + os.close(); + } + + /** + * Gets the PDF-AS SCM Revision + * + * @return + */ + public String getSCMRevision() { + try { + ServletContext application = getServletConfig().getServletContext(); + InputStream inputStream = application + .getResourceAsStream("/META-INF/MANIFEST.MF"); + Manifest manifest = new Manifest(inputStream); + Attributes attributes = manifest.getMainAttributes(); + String impVersion = attributes.getValue("Specification-Version"); + return impVersion; + } catch (Throwable e) { + return "UNKOWN"; + } + } + + /** + * Gets the PDF-AS Version + * + * @return PDF-AS Verison string + */ + public String getVersion() { + try { + ServletContext application = getServletConfig().getServletContext(); + InputStream inputStream = application + .getResourceAsStream("/META-INF/MANIFEST.MF"); + Manifest manifest = new Manifest(inputStream); + Attributes attributes = manifest.getMainAttributes(); + String impVersion = attributes.getValue("Implementation-Version"); + return impVersion; + } catch (Throwable e) { + return "UNKOWN"; + } + } +} -- cgit v1.2.3