1 13 14 package org.ejbca.ui.web.pub.cluster; 15 16 import java.sql.Connection ; 17 import java.sql.Statement ; 18 19 import javax.servlet.ServletConfig ; 20 import javax.servlet.http.HttpServletRequest ; 21 22 import org.apache.log4j.Logger; 23 import org.ejbca.core.ejb.JNDINames; 24 import org.ejbca.ui.web.protocol.IHealtChecker; 25 import org.ejbca.util.JDBCUtil; 26 27 28 29 41 42 public class ExtOCSPHealthCheck implements IHealthCheck { 43 44 private static Logger log = Logger.getLogger(ExtOCSPHealthCheck.class); 45 private static IHealtChecker healtChecker; 46 47 private int minfreememory = 0; 48 private String checkDBString = null; 49 static public void setHealtChecker(IHealtChecker hc) { 50 healtChecker = hc; 51 } 52 53 public void init(ServletConfig config) { 54 minfreememory = Integer.parseInt(config.getInitParameter("MinimumFreeMemory")) * 1024 * 1024; 55 checkDBString = config.getInitParameter("checkDBString"); 56 } 57 58 59 public String checkHealth(HttpServletRequest request) { 60 log.debug("Starting HealthCheck health check requested by : " + request.getRemoteAddr()); 61 String errormessage = ""; 62 63 errormessage += checkDB(); 64 if(errormessage.equals("")){ 65 errormessage += checkMemory(); 66 errormessage += checkOCSPSignTokens(); 67 68 } 69 70 if(errormessage.equals("")){ 71 errormessage = null; 73 } 74 75 return errormessage; 76 } 77 78 private String checkMemory(){ 79 String retval = ""; 80 if(minfreememory >= Runtime.getRuntime().freeMemory()){ 81 retval = "\nError Virtual Memory is about to run out, currently free memory :" + Runtime.getRuntime().freeMemory(); 82 } 83 84 return retval; 85 } 86 87 private String checkDB(){ 88 String retval = ""; 89 try{ 90 Connection con = JDBCUtil.getDBConnection(JNDINames.DATASOURCE); 91 Statement statement = con.createStatement(); 92 statement.execute(checkDBString); 93 JDBCUtil.close(con); 94 }catch(Exception e){ 95 retval = "\nError creating connection to EJBCA Database."; 96 log.error("Error creating connection to EJBCA Database.",e); 97 } 98 return retval; 99 } 100 101 private String checkOCSPSignTokens(){ 102 if ( healtChecker!=null ) 103 return healtChecker.healtCheck(); 104 else 105 return "No OCSP servlet started"; 106 } 107 } 108 | Popular Tags |