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 --- simpleSigning/build.gradle | 42 ++++++----- .../at/gv/egiz/simpleSigning/ErrorSignature.java | 2 - .../at/gv/egiz/simpleSigning/FinishSignature.java | 2 - .../at/gv/egiz/simpleSigning/JQueryServlet.java | 2 - .../at/gv/egiz/simpleSigning/PDFASJsServlet.java | 1 - .../java/at/gv/egiz/simpleSigning/Provider.java | 2 - .../at/gv/egiz/simpleSigning/StartSignature.java | 6 +- .../at/gv/egiz/simpleSigning/VersionServlet.java | 86 ++++++++++++++++++++++ simpleSigning/src/main/webapp/WEB-INF/web.xml | 72 ++++++++++++++++++ 9 files changed, 184 insertions(+), 31 deletions(-) create mode 100644 simpleSigning/src/main/java/at/gv/egiz/simpleSigning/VersionServlet.java diff --git a/simpleSigning/build.gradle b/simpleSigning/build.gradle index 58d3680..084b739 100644 --- a/simpleSigning/build.gradle +++ b/simpleSigning/build.gradle @@ -4,20 +4,32 @@ apply plugin: 'eclipse-wtp' apply plugin: 'war' sourceCompatibility = 1.6 -version = '1.0-RC1' +version = '1.0-RC2' +revision = getCheckedOutGitCommitHash() -jar { - manifest { - attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': version - } + +war { + manifest { + attributes provider: 'EGIZ', 'Specification-Version': getCheckedOutGitCommitHash(), 'Implementation-Title': 'Einfach Signieren', 'Implementation-Version': version + } } -repositories { - mavenCentral() +repositories { mavenCentral() } + + +def getCheckedOutGitCommitHash() { + def gitFolder = "$projectDir/../.git/" + def takeFromHash = 40 + def head = new File(gitFolder + "HEAD").text.split(":") // .git/HEAD + def isCommit = head.length == 1 + if(isCommit) return head[0].trim().take(takeFromHash) + + def refHead = new File(gitFolder + head[1].trim()) + refHead.text.trim().take takeFromHash } dependencies { - compile group: 'commons-collections', name: 'commons-collections', version: '3.2' + compile group: 'commons-collections', name: 'commons-collections', version: '3.2' compile group: 'commons-fileupload', name: 'commons-fileupload', version: '1.2' compile group: 'org.apache.commons', name: 'commons-io', version: '1.3.2' compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.5' @@ -25,17 +37,13 @@ dependencies { //compile group: 'org.apache.pdfbox', name: 'pdfbox', version: '1.8.5' compile 'com.lowagie:itext:4.2.0' providedCompile 'javax.servlet:javax.servlet-api:3.1.0' - testCompile group: 'junit', name: 'junit', version: '4.+' + testCompile group: 'junit', name: 'junit', version: '4.+' } -test { - systemProperties 'property': 'value' -} +test { systemProperties 'property': 'value' } uploadArchives { - repositories { - flatDir { - dirs 'repos' - } - } + repositories { + flatDir { dirs 'repos' } + } } diff --git a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/ErrorSignature.java b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/ErrorSignature.java index c8128b0..0ebeeab 100644 --- a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/ErrorSignature.java +++ b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/ErrorSignature.java @@ -5,7 +5,6 @@ import java.io.OutputStream; import java.net.URLDecoder; import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -16,7 +15,6 @@ import org.slf4j.LoggerFactory; import at.gv.egiz.simpleSigning.helper.SessionHelper; -@WebServlet("/Error") public class ErrorSignature extends HttpServlet { /** diff --git a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/FinishSignature.java b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/FinishSignature.java index 33ad8fd..f8cc26a 100644 --- a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/FinishSignature.java +++ b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/FinishSignature.java @@ -4,7 +4,6 @@ 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; @@ -15,7 +14,6 @@ import org.slf4j.LoggerFactory; import at.gv.egiz.simpleSigning.helper.SessionHelper; -@WebServlet("/Finish") public class FinishSignature extends HttpServlet { /** diff --git a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/JQueryServlet.java b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/JQueryServlet.java index 87693b5..96a8cc3 100644 --- a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/JQueryServlet.java +++ b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/JQueryServlet.java @@ -4,14 +4,12 @@ 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; -@WebServlet("/jquery.js") public class JQueryServlet extends HttpServlet { /** diff --git a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/PDFASJsServlet.java b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/PDFASJsServlet.java index 4ea456e..b2a6201 100644 --- a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/PDFASJsServlet.java +++ b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/PDFASJsServlet.java @@ -1,6 +1,5 @@ package at.gv.egiz.simpleSigning; -import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; diff --git a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/Provider.java b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/Provider.java index 7cde301..918956e 100644 --- a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/Provider.java +++ b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/Provider.java @@ -4,7 +4,6 @@ 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; @@ -14,7 +13,6 @@ import org.slf4j.LoggerFactory; import at.gv.egiz.simpleSigning.helper.SessionHelper; -@WebServlet("/Provide") public class Provider extends HttpServlet { /** * diff --git a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/StartSignature.java b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/StartSignature.java index e88e85a..e018499 100644 --- a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/StartSignature.java +++ b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/StartSignature.java @@ -4,14 +4,11 @@ import java.io.IOException; import java.io.OutputStream; import java.net.MalformedURLException; import java.net.URL; -import java.util.Iterator; 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 javax.servlet.http.Part; import org.apache.commons.fileupload.FileItemIterator; import org.apache.commons.fileupload.FileItemStream; @@ -21,12 +18,11 @@ import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.gv.egiz.simpleSigning.helper.SessionHelper.Type; import at.gv.egiz.simpleSigning.cfg.Configuration; import at.gv.egiz.simpleSigning.helper.PDFHelper; import at.gv.egiz.simpleSigning.helper.SessionHelper; +import at.gv.egiz.simpleSigning.helper.SessionHelper.Type; -@WebServlet(urlPatterns = { "/Start" }) public class StartSignature extends HttpServlet { private static final Logger logger = LoggerFactory 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"; + } + } +} diff --git a/simpleSigning/src/main/webapp/WEB-INF/web.xml b/simpleSigning/src/main/webapp/WEB-INF/web.xml index 83c9904..4e292a8 100644 --- a/simpleSigning/src/main/webapp/WEB-INF/web.xml +++ b/simpleSigning/src/main/webapp/WEB-INF/web.xml @@ -15,7 +15,55 @@ at.gv.egiz.simpleSigning.PDFASJsServlet 0 + + + StartSignature + StartSignature + + at.gv.egiz.simpleSigning.StartSignature + 0 + + + + Provider + Provider + + at.gv.egiz.simpleSigning.Provider + 0 + + + + JQueryServlet + JQueryServlet + + at.gv.egiz.simpleSigning.JQueryServlet + 0 + + + FinishSignature + FinishSignature + + at.gv.egiz.simpleSigning.FinishSignature + 0 + + + + ErrorSignature + ErrorSignature + + at.gv.egiz.simpleSigning.ErrorSignature + 0 + + + + VersionServlet + VersionServlet + + at.gv.egiz.simpleSigning.VersionServlet + 0 + + -- cgit v1.2.3