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"; } } }