diff options
author | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-12-01 12:23:47 +0100 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-12-02 10:09:35 +0100 |
commit | e929b5f4c6d9351b29150e6c1843f06806ee7b00 (patch) | |
tree | c6ecc4e5f6c3da6ef381a3d852c0a2211ca060e2 /pdf-as-web-status/src/main/java/at/gv/egiz/status/servlet | |
parent | 6398c85d80213f316dd0f9e4be10e34b54b1f5f9 (diff) | |
download | pdf-as-4-e929b5f4c6d9351b29150e6c1843f06806ee7b00.tar.gz pdf-as-4-e929b5f4c6d9351b29150e6c1843f06806ee7b00.tar.bz2 pdf-as-4-e929b5f4c6d9351b29150e6c1843f06806ee7b00.zip |
added status servlet to pdf-as-web
Diffstat (limited to 'pdf-as-web-status/src/main/java/at/gv/egiz/status/servlet')
-rw-r--r-- | pdf-as-web-status/src/main/java/at/gv/egiz/status/servlet/StatusServlet.java | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/pdf-as-web-status/src/main/java/at/gv/egiz/status/servlet/StatusServlet.java b/pdf-as-web-status/src/main/java/at/gv/egiz/status/servlet/StatusServlet.java new file mode 100644 index 00000000..6790fccc --- /dev/null +++ b/pdf-as-web-status/src/main/java/at/gv/egiz/status/servlet/StatusServlet.java @@ -0,0 +1,120 @@ +package at.gv.egiz.status.servlet; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.ServletConfig; +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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.gv.egiz.status.TestResult; +import at.gv.egiz.status.content.ResponseBuilder; +import at.gv.egiz.status.content.ResponseBuilder.ContentType; +import at.gv.egiz.status.impl.TestManager; + +/** + * Servlet implementation class StatusServlet + */ +@WebServlet(name="statusServlet", urlPatterns={"/status"}) +public class StatusServlet extends HttpServlet { + + private static final long serialVersionUID = 1201254769913428186L; + + public static final String PARAM_CONTENT_TYPE = "content"; + public static final String PARAM_FORCE = "force"; + public static final String PARAM_DETAILS = "details"; + public static final String PARAM_DETAILS_TRUE = "true"; + public static final String PARAM_TEST = "test"; + + private final Logger log = LoggerFactory.getLogger(StatusServlet.class); + + private TestManager manager; + + private ResponseBuilder builder; + + private boolean showDetails = false; + + /** + * @see HttpServlet#HttpServlet() + */ + public StatusServlet() { + super(); + + manager = new TestManager(); + builder = new ResponseBuilder(); + } + + /** + * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig) + */ + @Override + public void init(ServletConfig config) throws ServletException { + super.init(config); + + // TODO: Environment Parameter to show details -> showDetails + } + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + this.doProcess(request, response); + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + this.doProcess(request, response); + } + + protected void doProcess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + String content = request.getParameter(PARAM_CONTENT_TYPE); + + if(content == null) { + content = ContentType.HTML.toString(); + } + + log.debug("Producing Content: " + content); + + // Parameter to force execution + boolean force = true; + + String forceExec = request.getParameter(PARAM_FORCE); + + if(forceExec != null) { + if(forceExec.equalsIgnoreCase("false")) { + force = false; + } + } + boolean showingDetails = showDetails; + String detail = request.getParameter(PARAM_DETAILS); + if(detail != null) { + showingDetails = detail.equalsIgnoreCase(PARAM_DETAILS_TRUE); + } + + // Parameter for specific test + String test = request.getParameter(PARAM_TEST); + + Map<String, TestResult> results = null; + + if(test != null) { + results = new HashMap<String, TestResult>(); + TestResult result = this.manager.runTest(test, force); + if(result != null) { + results.put(test, result); + } + } else { + results = this.manager.runAllTests(force); + } + + this.builder.generate(request, response, results, showingDetails, content); + } +} |