1 37 38 39 40 41 package com.lutris.appserver.debugger.presentation; 42 43 44 import com.lutris.appserver.server.*; 45 import com.lutris.appserver.server.httpPresentation.*; 46 import com.lutris.appserver.debugger.Debugger; 47 48 import com.lutris.appserver.debugger.spec.*; 49 50 51 import javax.servlet.*; 52 import javax.servlet.http.*; 53 import java.util.Hashtable ; 54 56 public class StatusFrame implements HttpPresentation { 57 58 private static final int SHOW_REQUEST = 0; 59 private static final int SHOW_TRACE = 1; 60 private static final int SHOW_SESSIONDATA = 2; 61 private static final int SHOW_RESPONSE = 3; 62 63 private boolean noTrans(HttpPresentationComms comms) throws Exception { 64 if (comms.sessionData == null) 65 return true; 66 return !comms.sessionData.containsKey("dirty"); 67 } 68 69 private void possiblySetTrans(HttpPresentationComms comms) 70 throws Exception { 71 if (comms.sessionData == null) 72 return; 73 String idStr = comms.request.getParameter("id"); 74 75 if (idStr != null) { 76 int id = -1; 77 try { 78 id = Integer.parseInt(idStr); 79 } catch (NumberFormatException e) { 80 } 81 if (id != -1) { 82 ServletMonitor sm=ServletMonitorFactory.getServletMonitor("com.lutris.appserver.debugger.business.ServletMonitorImpl"); 83 84 Hashtable trans = 85 sm.getTransactionRecord(id); 86 if (trans != null) 87 88 comms.sessionData.set("trans", trans); 89 comms.sessionData.set("dirty", new Boolean (true)); 90 } 91 } 92 } 93 94 95 private Hashtable getTrans(HttpPresentationComms comms) 96 throws Exception { 97 if (comms.sessionData == null) 98 return null; 99 Hashtable trans = 100 (Hashtable ) comms.sessionData.get("trans"); 101 102 103 if (trans == null) 104 comms.sessionData.remove("trans"); 105 return trans; 106 } 107 108 109 private void possiblySetPanel(HttpPresentationComms comms) 110 throws Exception { 111 if (comms.sessionData == null) 112 return; 113 String panelStr = comms.request.getParameter("panel"); 114 if (panelStr != null) 115 comms.sessionData.set("panel", new Integer (panelStr)); 116 } 117 118 119 private int getPanel(HttpPresentationComms comms) throws Exception { 120 if (comms.sessionData == null) 121 return SHOW_REQUEST; 122 Integer panel = (Integer ) comms.sessionData.get("panel"); 123 if (panel == null) { 124 panel = new Integer (SHOW_REQUEST); 125 comms.sessionData.set("panel", panel); 126 } 127 return panel.intValue(); 128 } 129 130 131 132 133 public void run(HttpPresentationComms comms) throws Exception { 134 possiblySetTrans(comms); 135 possiblySetPanel(comms); 136 137 138 139 if (noTrans(comms)) { 140 emitIntroPage(comms); 141 return; 142 } 143 Hashtable trans = getTrans(comms); 144 int panel = getPanel(comms); 145 if (trans == null) { 146 emitNotFoundPage(comms); 147 return; 148 } 149 if (panel == SHOW_REQUEST) { 150 emitRequestPage(comms, trans); 151 return; 152 } else if (panel == SHOW_TRACE) { 153 return; 154 } else if (panel == SHOW_SESSIONDATA) { 155 emitSessionPage(comms, trans); 156 return; 157 } else if (panel == SHOW_RESPONSE) { 158 emitResponsePage(comms, trans); 159 return; 160 } 161 emitErrorPage(comms); 162 } 163 164 165 private void emitIntroPage(HttpPresentationComms comms) throws Exception { 166 comms.response.setContentType("text/html"); 167 comms.response.getOutputStream().print( 168 "<HTML><HEAD></HEAD><BODY>" + 169 "<p><p><p><center><i>No Transaction Selected</i></center>" + 170 "</BODY></HTML>"); 171 } 172 173 174 private void emitNotFoundPage(HttpPresentationComms comms) 175 throws Exception { 176 comms.response.setContentType("text/html"); 177 comms.response.getOutputStream().print( 178 "<HTML><HEAD></HEAD><BODY>" + 179 "<p><center><h1><b>Transaction not found.</b></h1><P>" + 180 "Perhaps it is too old and has been flushed out of the queue." + 181 "</center>" + 182 "</BODY></HTML>"); 183 } 184 185 186 private void emitRequestPage(HttpPresentationComms comms, 187 Hashtable trans) 188 throws Exception { 189 String id = comms.request.getParameter("id"); 190 comms.response.setContentType("text/html"); 191 HttpPresentationOutputStream out = comms.response.getOutputStream(); 192 out.println("<HTML><HEAD></HEAD><BODY>"); 193 out.println("<B>Request</B>"); 194 out.println("<a HREF=StatusFrame.po?panel=" + 195 SHOW_SESSIONDATA + "&id="+id +">Session Data</a>"); 196 out.println("<a HREF=StatusFrame.po?panel=" + 197 SHOW_RESPONSE + "&id="+id +">Response</a>"); 198 out.println(HttpDebug.getRequestDebugInfo(trans)); 199 out.println("<p><font size=-1><i>This debugger is part of the <a HREF=http://www.enhydra.org target=eWindow>Enhydra</a> project.</i></font>"); 200 out.println("</BODY></HTML>"); 201 } 202 203 204 private void emitTracePage(HttpPresentationComms comms, 205 Hashtable trans) 206 throws Exception { 207 String id = comms.request.getParameter("id"); 208 comms.response.setContentType("text/html"); 209 HttpPresentationOutputStream out = comms.response.getOutputStream(); 210 out.println("<HTML><HEAD></HEAD><BODY>"); 211 out.println("<a HREF=StatusFrame.po?panel=" + 212 SHOW_REQUEST + "&id="+id +">Request</a>"); 213 out.println("<B>Trace</B>"); 214 out.println("<a HREF=StatusFrame.po?panel=" + 215 SHOW_SESSIONDATA + "&id="+id +">Session Data</a>"); 216 out.println("<a HREF=StatusFrame.po?panel=" + 217 SHOW_RESPONSE + "&id="+id +">Response</a>"); 218 out.println(HttpDebug.formatTraceDebugInfo((String )trans.get("ResponseTrace"))); 219 out.println("<p><font size=-1><i>This debugger is part of the <a HREF=http://www.enhydra.org target=eWindow>Enhydra</a> project.</i></font>"); 220 out.println("</BODY></HTML>"); 221 } 222 223 224 private void emitSessionPage(HttpPresentationComms comms, 225 Hashtable trans) 226 throws Exception { 227 String id = comms.request.getParameter("id"); 228 comms.response.setContentType("text/html"); 229 HttpPresentationOutputStream out = comms.response.getOutputStream(); 230 out.println("<HTML><HEAD></HEAD><BODY>"); 231 out.println("<a HREF=StatusFrame.po?panel=" + 232 SHOW_REQUEST + "&id="+id +">Request</a>"); 233 out.println("<B>Session Data</B>"); 234 out.println("<a HREF=StatusFrame.po?panel=" + 235 SHOW_RESPONSE + "&id="+id +">Response</a>"); 236 237 String pre =(String )trans.get("S"); 238 239 if (pre == null) 241 pre = "<i>No session data found.</i>"; 242 else if (pre.equals("")) 243 pre = "<i>Empty</i>"; 244 String post =(String )trans.get("S1"); 245 if (post == null) 247 post = "<i>No session data found.</i>"; 248 else if (post.equals("")) 249 post = "<i>Empty</i>"; 250 out.println(HttpDebug.formatSessionInfo(pre, "Session Data Before")); 251 out.println(HttpDebug.formatSessionInfo(post, "Session Data After")); 252 if (pre == null && 253 post == null) 254 out.println("<p><i>(Session Data is only available with <a HREF=http://www.enhydra.com>Enhydra</a> applications)</i>"); 255 out.println("<p><font size=-1><i>This debugger is part of the <a HREF=http://www.enhydra.org target=eWindow>Enhydra</a> project.</i></font>"); 256 out.println("</BODY></HTML>"); 257 } 258 259 260 private void emitResponsePage(HttpPresentationComms comms, 261 Hashtable trans) 262 throws Exception { 263 String id = comms.request.getParameter("id"); 264 comms.response.setContentType("text/html"); 265 HttpPresentationOutputStream out = comms.response.getOutputStream(); 266 out.println("<HTML><HEAD></HEAD><BODY>"); 267 out.println("<a HREF=StatusFrame.po?panel=" + 268 SHOW_REQUEST + "&id="+id +">Request</a>"); 269 out.println("<a HREF=StatusFrame.po?panel=" + 270 SHOW_SESSIONDATA + "&id="+id +">Session Data</a>"); 271 out.println("<B>Response</B>"); 272 273 out.println(HttpDebug.getResponseDebugInfo(trans)); 274 out.println("<p><font size=-1><i>This debugger is part of the <a HREF=http://www.enhydra.org target=eWindow>Enhydra</a> project.</i></font>"); 275 out.println("</BODY></HTML>"); 276 } 277 278 279 280 private void emitErrorPage(HttpPresentationComms comms) throws Exception { 281 comms.response.setContentType("text/html"); 282 comms.response.getOutputStream().print( 283 "<HTML><HEAD></HEAD><BODY>" + 284 "<P><center><h1><b>Internal Error In Debugger</b></h1></center>" + 285 "</BODY></HTML>"); 286 } 287 288 289 } 290 | Popular Tags |