protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
sendJacocoData(req, resp, true);
}
private void sendJacocoData(HttpServletRequest req, HttpServletResponse resp, boolean resetAgent) throws IOException {
final IAgent agent = getAgent();
if (agent == null) {
final String msg = "The Jacoco agent MBean is not available\n\n";
resp.sendError(HttpServletResponse.SC_NOT_FOUND, msg + getUsageInfo());
} else {
resp.setContentType("application/octet-stream");
final String sessionId = req.getParameter(PARAM_SESSION_ID);
log.info("Getting JaCoCo execution data, resetAgent={}", resetAgent);
byte[] data = agent.getExecutionData(resetAgent);
if(sessionId != null) {
log.info("Setting JaCoCo sessionId={}", sessionId);
agent.setSessionId(sessionId);
}
resp.getOutputStream().write(data);
resp.getOutputStream().flush();
}
}