1 package org.kuali.ole.sys.web.servlet;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.io.StringWriter;
6 import java.util.Collection;
7
8 import javax.servlet.http.HttpServlet;
9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11
12 import org.kuali.ole.coa.businessobject.Chart;
13 import org.kuali.ole.sys.OLEConstants;
14 import org.kuali.ole.sys.context.SpringContext;
15 import org.kuali.rice.kew.api.doctype.DocumentType;
16 import org.kuali.rice.kew.api.doctype.DocumentTypeService;
17 import org.kuali.rice.kim.api.identity.Person;
18 import org.kuali.rice.krad.service.BusinessObjectService;
19
20 public class KualiHeartbeatServlet extends HttpServlet {
21 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KualiHeartbeatServlet.class);
22
23
24
25 private static final long serialVersionUID = 4901222949286730892L;
26
27 @Override
28 public void doGet(HttpServletRequest req, HttpServletResponse resp){
29 this.doPost(req, resp);
30 }
31 @Override
32 public void doPost(HttpServletRequest req, HttpServletResponse resp){
33 StringBuilder sb = new StringBuilder(200);
34 boolean errors = false;
35 sb.append("<html><head><title>KFS Heartbeat Monitor</title></head><body>");
36 try {
37 Collection<Chart> hbResult = SpringContext.getBean(BusinessObjectService.class).findAll(Chart.class);
38
39 if ( hbResult == null || hbResult.isEmpty() ) {
40 sb.append( "ERROR: NO CHARTS RETRIEVED");
41 errors = true;
42 } else {
43
44 Person p = hbResult.iterator().next().getFinCoaManager();
45 if ( p == null ) {
46 sb.append( "POTENTIAL PROBLEM: CHART MANAGER CALL TO KIM IMPLEMENTATION RETURNED NULL");
47 errors = true;
48 }
49 }
50
51 DocumentType docDTO = SpringContext.getBean(DocumentTypeService.class).getDocumentTypeByName(OLEConstants.ROOT_DOCUMENT_TYPE);
52 if ( docDTO == null ) {
53 sb.append( "POTENTIAL PROBLEM: " + OLEConstants.ROOT_DOCUMENT_TYPE + " document type not found. Missing KFS Document hierarchy." );
54 errors = true;
55 }
56 if ( !errors ) {
57 sb.append( "LUB-DUB,LUB-DUB");
58 }
59 } catch ( Exception ex ){
60 sb.append( "Exception running heartbeat monitor: " + ex.getClass() + ": " + ex.getMessage() );
61 StringWriter sw = new StringWriter(1000);
62 PrintWriter pw = new PrintWriter( sw );
63 ex.printStackTrace( pw );
64 sb.append( sw.toString() );
65 LOG.fatal( "Failed to detect heartbeat. Apply paddles stat! beeeeeeeeeeeeeeeeeeeeeeeeeeep It's dead Jim.", ex);
66 } finally {
67 sb.append( "</body></html>");
68 try {
69 resp.getWriter().println(sb.toString());
70 resp.addHeader("Content-Type", "text/html");
71 } catch (IOException ex) {
72 LOG.error( "Failure writing to heartbeat servlet output stream:", ex );
73 }
74 }
75 }
76 }