KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > appserver > debugger > presentation > StatusFrame


1 /*-----------------------------------------------------------------------------
2  * Enhydra Java Application Server
3  * Copyright 1997-2000 Lutris Technologies, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  * must display the following acknowledgement:
16  * This product includes Enhydra software developed by Lutris
17  * Technologies, Inc. and its contributors.
18  * 4. Neither the name of Lutris Technologies nor the names of its contributors
19  * may be used to endorse or promote products derived from this software
20  * without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY LUTRIS TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL LUTRIS TECHNOLOGIES OR CONTRIBUTORS BE
26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *-----------------------------------------------------------------------------
34  * $Id: StatusFrame.java,v 1.1 2004/04/06 15:24:32 rale Exp $
35  *-----------------------------------------------------------------------------
36  */

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 JavaDoc;
54 /**
55  */

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 JavaDoc {
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 JavaDoc {
71         if (comms.sessionData == null)
72             return;
73         String JavaDoc idStr = comms.request.getParameter("id");
74      
75         if (idStr != null) {
76             int id = -1;
77             try {
78                 id = Integer.parseInt(idStr);
79             } catch (NumberFormatException JavaDoc e) {
80             }
81             if (id != -1) {
82                  ServletMonitor sm=ServletMonitorFactory.getServletMonitor("com.lutris.appserver.debugger.business.ServletMonitorImpl");
83   
84                 Hashtable JavaDoc trans =
85                                     sm.getTransactionRecord(id);
86                  if (trans != null)
87                 
88                     comms.sessionData.set("trans", trans);
89                   comms.sessionData.set("dirty", new Boolean JavaDoc(true));
90             }
91         }
92     }
93
94
95     private Hashtable JavaDoc getTrans(HttpPresentationComms comms)
96             throws Exception JavaDoc {
97         if (comms.sessionData == null)
98             return null;
99         Hashtable JavaDoc trans =
100                    (Hashtable JavaDoc) 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 JavaDoc {
111         if (comms.sessionData == null)
112             return;
113         String JavaDoc panelStr = comms.request.getParameter("panel");
114         if (panelStr != null)
115             comms.sessionData.set("panel", new Integer JavaDoc(panelStr));
116     }
117
118
119     private int getPanel(HttpPresentationComms comms) throws Exception JavaDoc {
120         if (comms.sessionData == null)
121             return SHOW_REQUEST;
122         Integer JavaDoc panel = (Integer JavaDoc) comms.sessionData.get("panel");
123         if (panel == null) {
124             panel = new Integer JavaDoc(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 JavaDoc {
134         possiblySetTrans(comms);
135         possiblySetPanel(comms);
136         
137     
138         
139         if (noTrans(comms)) {
140             emitIntroPage(comms);
141             return;
142         }
143         Hashtable JavaDoc 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 JavaDoc {
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 JavaDoc {
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 JavaDoc trans)
188                  throws Exception JavaDoc {
189         String JavaDoc 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 JavaDoc trans)
206                  throws Exception JavaDoc {
207                      String JavaDoc 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 JavaDoc)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 JavaDoc trans)
226                  throws Exception JavaDoc {
227                      String JavaDoc 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 JavaDoc pre =(String JavaDoc)trans.get("S");
238        
239         // The debug framework should not let this be null, but just in case...
240
if (pre == null)
241             pre = "<i>No session data found.</i>";
242         else if (pre.equals(""))
243             pre = "<i>Empty</i>";
244         String JavaDoc post =(String JavaDoc)trans.get("S1");
245         // The debug framework should not let this be null, but just in case...
246
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 JavaDoc trans)
262                  throws Exception JavaDoc {
263                      String JavaDoc 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 JavaDoc {
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