001 /* 002 * Cobertura - http://cobertura.sourceforge.net/ 003 * 004 * Copyright (C) 2009 Amit Nithianandan 005 * Copyright (C) 2009 John Lewis 006 * 007 * Note: This file is dual licensed under the GPL and the Apache 008 * Source License. 009 * 010 * Cobertura is free software; you can redistribute it and/or modify 011 * it under the terms of the GNU General Public License as published 012 * by the Free Software Foundation; either version 2 of the License, 013 * or (at your option) any later version. 014 * 015 * Cobertura is distributed in the hope that it will be useful, but 016 * WITHOUT ANY WARRANTY; without even the implied warranty of 017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 018 * General Public License for more details. 019 * 020 * You should have received a copy of the GNU General Public License 021 * along with Cobertura; if not, write to the Free Software 022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 023 * USA 024 */ 025 package net.sourceforge.cobertura.webapp; 026 027 import java.io.IOException; 028 import java.io.PrintStream; 029 030 import javax.servlet.ServletException; 031 import javax.servlet.http.HttpServlet; 032 import javax.servlet.http.HttpServletRequest; 033 import javax.servlet.http.HttpServletResponse; 034 035 public class FlushCoberturaServlet extends HttpServlet 036 { 037 038 /** 039 * 040 */ 041 private static final long serialVersionUID = 1L; 042 043 @Override 044 protected void doGet(HttpServletRequest req, HttpServletResponse resp) 045 throws ServletException, IOException 046 { 047 try { 048 String className = "net.sourceforge.cobertura.coveragedata.ProjectData"; 049 String methodName = "saveGlobalProjectData"; 050 Class saveClass = Class.forName(className); 051 java.lang.reflect.Method saveMethod = saveClass.getDeclaredMethod(methodName, new Class[0]); 052 saveMethod.invoke(null,new Object[0]); 053 } catch (Throwable t) { 054 PrintStream ps = new PrintStream(resp.getOutputStream()); 055 ps.println("<HTML><BODY><P>Could not save Cobertura data. Make sure cobertura.jar is in the web server's lib directory: " + t.getLocalizedMessage()); 056 ps.print("<P>"); 057 t.printStackTrace(ps); 058 ps.println("</BODY></HTML>"); 059 resp.flushBuffer(); 060 } 061 } 062 063 @Override 064 protected void doPost(HttpServletRequest req, HttpServletResponse resp) 065 throws ServletException, IOException 066 { 067 doGet(req, resp); 068 } 069 070 }