aboutsummaryrefslogtreecommitdiff
path: root/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/VersionServlet.java
diff options
context:
space:
mode:
Diffstat (limited to 'simpleSigning/src/main/java/at/gv/egiz/simpleSigning/VersionServlet.java')
-rw-r--r--simpleSigning/src/main/java/at/gv/egiz/simpleSigning/VersionServlet.java86
1 files changed, 86 insertions, 0 deletions
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";
+ }
+ }
+}