package com.ix**s.uitest.servlet;
import java.io.BufferedWriter;import java.io.File;import java.io.FileWriter;import java.io.IOException;import java.text.SimpleDateFormat;import java.util.Date;
import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;
/** * This class listens to all the GETs and POSTs. It's main function is to read the JavaScript * errors and log them to a log file. * @author paul.felice * */public class JsGrabberServlet extends HttpServlet {
private static final long serialVersionUID = 1307842006715835042L;
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { }
@Override protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // TODO Auto-generated method stub super.doDelete(req, resp); }
@Override protected void doHead(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // TODO Auto-generated method stub super.doHead(req, resp); }
@Override protected void doOptions(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException { // TODO Auto-generated method stub super.doOptions(arg0, arg1); }
@Override protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // TODO Auto-generated method stub super.doPut(req, resp); }
@Override protected void doTrace(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException { // TODO Auto-generated method stub super.doTrace(arg0, arg1); }
@Override protected long getLastModified(HttpServletRequest req) { // TODO Auto-generated method stub return super.getLastModified(req); }
@Override protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException { // TODO Auto-generated method stub super.service(arg0, arg1); }
@Override public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { // TODO Auto-generated method stub super.service(req, res); }
@Override protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
// Reading the Javascript error String errorMsg = request.getParameter("errorMsg"); String sourceMsg = request.getParameter("sourceMsg"); String lineNum = request.getParameter("lineNum");
//Create a File, if file is already there append to it. File f = new File("JsErrors.log"); if(!f.exists()){ f.createNewFile(); } BufferedWriter br = new BufferedWriter(new FileWriter(f, true));
// Defining the time and date format SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); // Constructing the String String s = sdf.format(new Date()) + "|" + errorMsg + "|" + sourceMsg + "|" + lineNum; //Writing to file br.write(s+System.lineSeparator()); br.close(); //respond ok response.setStatus(HttpServletResponse.SC_OK); }}<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.ix**s.utils</groupId> <artifactId>utils</artifactId> <version>1.0</version> <relativePath>../pom.xml</relativePath> </parent> <artifactId>js-error-grabber</artifactId> <name>js-error-grabber</name> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>com.thetransactioncompany</groupId> <artifactId>cors-filter</artifactId> <version>1.7.1</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> <debug>true</debug> <debuglevel>lines,vars,source</debuglevel> </configuration> </plugin> <!--<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>emma-maven-plugin</artifactId> <version>1.0-alpha-3</version> <inherited>true</inherited> <executions> <execution> <phase>process-classes</phase> <goals> <goal>instrument</goal> </goals> </execution> </executions> </plugin> --> </plugins> <finalName>js-error-grabber</finalName> </build></project>mvn clean installset CATALINA_OPTS= "-javaagent:${mydir}\jacoco-0.6.3.201306030806\lib\jacocoagent.jar"
now I run:
java -cp .;org.jacoco.core-0.6.3.201306030806.jar;org.jacoco.report-0.6.3.201306030806.jar;asm-all-4.1.jar org.jacoco.ReportGenerator .
I get the coverage reported in the coveragereport directory
but index.html looks like this: