KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.lutris.appserver.debugger.presentation;
2
3 import com.lutris.html.*;
4 import com.lutris.http.HttpStatus;
5 import com.lutris.util.HtmlEncoder;
6 import java.util.Enumeration JavaDoc;
7 import javax.servlet.http.Cookie JavaDoc;
8 //import org.apache.coyote.tomcat5.*;
9
import javax.servlet.*;
10 import javax.servlet.http.*;
11 import java.util.Hashtable JavaDoc;
12
13 import java.util.Vector JavaDoc;
14 public class HttpDebug
15 {
16
17     private static final String JavaDoc SPACE_BG_COLOR = "#000000";
18     private static final String JavaDoc HEADER_BG_COLOR = "#888888";
19     private static final String JavaDoc BODY_BG_COLOR = "#BBBBBB";
20     private static final String JavaDoc HIGHLIGHT_BG_COLOR = "#999999";
21     private static final String JavaDoc HEADER_FG_COLOR = "#FFFFFF";
22     private static final String JavaDoc FRAME_COLOR = "#EEEEEE";
23
24     public HttpDebug()
25     {
26     }
27
28     public static String JavaDoc getRequestDebugInfo(Hashtable JavaDoc request)
29         throws Exception JavaDoc
30     {
31         HtmlTable htmltable = new HtmlTable();
32         htmltable.setCellPadding(1);
33         htmltable.setCellSpacing(2);
34         htmltable.setBackgroundColor("#BBBBBB");
35         htmltable.setBorderWidth(0);
36         htmltable.setPercentWidth(100);
37         
38         addRequestInformation(htmltable, request);
39         addHeaderInformation(htmltable, request);
40         addCookieInformation(htmltable, request);
41         addParameterInformation(htmltable, request);
42         
43         HtmlTable htmltable1 = new HtmlTable();
44         htmltable1.setBackgroundColor("#EEEEEE");
45         htmltable1.setPercentWidth(100);
46         HtmlTableRow htmltablerow = new HtmlTableRow();
47         HtmlTableDataCell htmltabledatacell = new HtmlTableDataCell(htmltable.toString());
48         htmltablerow.addCell(htmltabledatacell);
49         htmltable1.addRow(htmltablerow);
50         return htmltable1.toString();
51     }
52
53     public static String JavaDoc getResponseDebugInfo(Hashtable JavaDoc response)
54         throws Exception JavaDoc
55     {
56         HtmlTable htmltable = new HtmlTable();
57         htmltable.setCellPadding(1);
58         htmltable.setCellSpacing(2);
59         htmltable.setBackgroundColor("#BBBBBB");
60         htmltable.setBorderWidth(0);
61         htmltable.setPercentWidth(100);
62        
63        
64         addResponseInformation(htmltable, response);
65         addHeaderInformationResponse(htmltable, response);
66         addCookieInformationResponse(htmltable, response);
67         addResponseDataInformation(htmltable, response);
68        
69        
70         HtmlTable htmltable1 = new HtmlTable();
71         htmltable1.setBackgroundColor("#EEEEEE");
72         htmltable1.setPercentWidth(100);
73         HtmlTableRow htmltablerow = new HtmlTableRow();
74         HtmlTableDataCell htmltabledatacell = new HtmlTableDataCell(htmltable.toString());
75         htmltablerow.addCell(htmltabledatacell);
76         htmltable1.addRow(htmltablerow);
77         return htmltable1.toString();
78     }
79
80     private static void addRequestInformation(HtmlTable htmltable, Hashtable JavaDoc request)
81         throws Exception JavaDoc
82     {
83         HtmlTableRow htmltablerow = new HtmlTableRow();
84         HtmlTableHeaderCell htmltableheadercell = new HtmlTableHeaderCell("<FONT SIZE=+1 COLOR=#FFFFFF>Request Information</FONT>");
85         htmltableheadercell.setColSpan(2);
86         HtmlTableHeaderCell _tmp = htmltableheadercell;
87         htmltableheadercell.setHorizontalAlignment(2);
88         htmltablerow.addCell(htmltableheadercell);
89         htmltablerow.setBackgroundColor("#888888");
90         htmltable.addRow(htmltablerow);
91         htmltablerow = new HtmlTableRow();
92         HtmlTableDataCell htmltabledatacell = new HtmlTableDataCell("<B>Information</B>");
93         htmltabledatacell.setPercentWidth(10);
94         htmltablerow.addCell(htmltabledatacell);
95         htmltabledatacell = new HtmlTableDataCell("<B>Value</B>");
96         htmltablerow.addCell(htmltabledatacell);
97         htmltable.addRow(htmltablerow);
98         htmltablerow = new HtmlTableRow();
99         htmltabledatacell = new HtmlTableDataCell("Server Name");
100         htmltablerow.addCell(htmltabledatacell);
101         
102     
103         
104         String JavaDoc s =(String JavaDoc) request.get("ServerName");
105         
106      
107         htmltabledatacell = new HtmlTableDataCell(s);
108         htmltablerow.addCell(htmltabledatacell);
109         htmltable.addRow(htmltablerow);
110         htmltablerow = new HtmlTableRow();
111         htmltabledatacell = new HtmlTableDataCell("Server Port");
112         htmltablerow.addCell(htmltabledatacell);
113         Integer JavaDoc port=(Integer JavaDoc)request.get("ServerPort");
114         htmltabledatacell = new HtmlTableDataCell(Integer.toString(port.intValue() ));
115         htmltablerow.addCell(htmltabledatacell);
116         htmltable.addRow(htmltablerow);
117         htmltablerow = new HtmlTableRow();
118         htmltabledatacell = new HtmlTableDataCell("URI");
119         htmltablerow.addCell(htmltabledatacell);
120        s = (String JavaDoc)request.get("RequestURI");
121      
122         htmltabledatacell = new HtmlTableDataCell(s);
123         htmltablerow.addCell(htmltabledatacell);
124         htmltable.addRow(htmltablerow);
125         htmltablerow = new HtmlTableRow();
126         htmltabledatacell = new HtmlTableDataCell("Scheme");
127         htmltablerow.addCell(htmltabledatacell);
128   
129       s = (String JavaDoc)request.get("Scheme");
130       
131         htmltabledatacell = new HtmlTableDataCell(s);
132         htmltablerow.addCell(htmltabledatacell);
133         htmltable.addRow(htmltablerow);
134         htmltablerow = new HtmlTableRow();
135         htmltabledatacell = new HtmlTableDataCell("Total Bytes");
136         htmltablerow.addCell(htmltabledatacell);
137         htmltabledatacell = new HtmlTableDataCell("<I>N/A</I>");
138         htmltablerow.addCell(htmltabledatacell);
139         htmltable.addRow(htmltablerow);
140         htmltablerow = new HtmlTableRow();
141         htmltabledatacell = new HtmlTableDataCell("Query String");
142         htmltablerow.addCell(htmltabledatacell);
143      
144   
145      s =(String JavaDoc) request.get("QueryString");
146      
147          htmltabledatacell = new HtmlTableDataCell(s);
148         htmltablerow.addCell(htmltabledatacell);
149         htmltable.addRow(htmltablerow);
150         htmltablerow = new HtmlTableRow();
151         htmltabledatacell = new HtmlTableDataCell("Remote IP Address");
152         htmltablerow.addCell(htmltabledatacell);
153        
154   
155        s =(String JavaDoc) request.get("RemoteAdr");
156        
157          htmltabledatacell = new HtmlTableDataCell(s);
158         htmltablerow.addCell(htmltabledatacell);
159         htmltable.addRow(htmltablerow);
160         htmltablerow = new HtmlTableRow();
161         htmltabledatacell = new HtmlTableDataCell("Remote Host");
162         htmltablerow.addCell(htmltabledatacell);
163        s = (String JavaDoc)request.get("RemoteHost");
164         htmltabledatacell = new HtmlTableDataCell(s);
165         htmltablerow.addCell(htmltabledatacell);
166         htmltable.addRow(htmltablerow);
167         htmltablerow = new HtmlTableRow();
168         htmltabledatacell = new HtmlTableDataCell("Remote User");
169         htmltablerow.addCell(htmltabledatacell);
170          s = (String JavaDoc)request.get("RemoteUser");
171         htmltabledatacell = new HtmlTableDataCell(s);
172         htmltablerow.addCell(htmltabledatacell);
173         htmltable.addRow(htmltablerow);
174         htmltablerow = new HtmlTableRow();
175         htmltabledatacell = new HtmlTableDataCell("Auth Type");
176         htmltablerow.addCell(htmltabledatacell);
177      s = (String JavaDoc)request.get("AuthType");
178         htmltabledatacell = new HtmlTableDataCell(s);
179         htmltablerow.addCell(htmltabledatacell);
180         htmltable.addRow(htmltablerow);
181         htmltablerow = new HtmlTableRow();
182         htmltabledatacell = new HtmlTableDataCell("Content Length");
183         htmltablerow.addCell(htmltabledatacell);
184       int j =((Integer JavaDoc)request.get("ContentLength")).intValue() ;
185        
186         if(j == -1)
187             htmltabledatacell = new HtmlTableDataCell("<I>N/A</I>");
188         else
189             htmltabledatacell = new HtmlTableDataCell(Integer.toString(j));
190         htmltablerow.addCell(htmltabledatacell);
191         htmltable.addRow(htmltablerow);
192         htmltablerow = new HtmlTableRow();
193         htmltabledatacell = new HtmlTableDataCell("Content Type");
194         htmltablerow.addCell(htmltabledatacell);
195      
196      s = (String JavaDoc)request.get("ContentType");
197          htmltabledatacell = new HtmlTableDataCell(s);
198         htmltablerow.addCell(htmltabledatacell);
199         htmltable.addRow(htmltablerow);
200         htmltablerow = new HtmlTableRow();
201         htmltabledatacell = new HtmlTableDataCell("Method");
202         htmltablerow.addCell(htmltabledatacell);
203       s = (String JavaDoc)request.get("Method");
204        htmltabledatacell = new HtmlTableDataCell(s);
205         htmltablerow.addCell(htmltabledatacell);
206         htmltable.addRow(htmltablerow);
207         htmltablerow = new HtmlTableRow();
208         htmltabledatacell = new HtmlTableDataCell("Path Info");
209         htmltablerow.addCell(htmltabledatacell);
210    
211      s =(String JavaDoc) request.get("PathInfo");
212         htmltabledatacell = new HtmlTableDataCell(s);
213         htmltablerow.addCell(htmltabledatacell);
214         htmltable.addRow(htmltablerow);
215         htmltablerow = new HtmlTableRow();
216         htmltabledatacell = new HtmlTableDataCell("Path Translated");
217         htmltablerow.addCell(htmltabledatacell);
218         s =(String JavaDoc)request.get("PathTranslated");
219         htmltabledatacell = new HtmlTableDataCell(s);
220         htmltablerow.addCell(htmltabledatacell);
221         htmltable.addRow(htmltablerow);
222         htmltablerow = new HtmlTableRow();
223         htmltabledatacell = new HtmlTableDataCell("Protocol");
224         htmltablerow.addCell(htmltabledatacell);
225        s =(String JavaDoc) request.get("Protocol");
226         htmltabledatacell = new HtmlTableDataCell(s);
227         htmltablerow.addCell(htmltabledatacell);
228         htmltable.addRow(htmltablerow);
229     }
230
231     private static void addHeaderInformation(HtmlTable htmltable, Hashtable JavaDoc request)
232         throws Exception JavaDoc
233  
234   
235     {
236         HtmlTableRow htmltablerow = new HtmlTableRow();
237         HtmlTableHeaderCell htmltableheadercell = new HtmlTableHeaderCell("<FONT SIZE=+1 COLOR=#FFFFFF>Request Headers</FONT>");
238         htmltableheadercell.setColSpan(2);
239         HtmlTableHeaderCell _tmp = htmltableheadercell;
240         htmltableheadercell.setHorizontalAlignment(2);
241         htmltablerow.addCell(htmltableheadercell);
242         htmltablerow.setBackgroundColor("#888888");
243         htmltable.addRow(htmltablerow);
244         htmltablerow = new HtmlTableRow();
245         HtmlTableDataCell htmltabledatacell = new HtmlTableDataCell("<B>Header Name</B>");
246         htmltabledatacell.setPercentWidth(10);
247         htmltablerow.addCell(htmltabledatacell);
248         htmltabledatacell = new HtmlTableDataCell("<B>Value(s)</B>");
249         htmltablerow.addCell(htmltabledatacell);
250         htmltable.addRow(htmltablerow);
251      
252         Vector JavaDoc names=(Vector JavaDoc)request.get("HeaderNames");
253      
254         
255         boolean flag = true;
256        
257        if(names.size()==0)
258         {
259             HtmlTableRow htmltablerow1 = new HtmlTableRow();
260             HtmlTableDataCell htmltabledatacell1 = new HtmlTableDataCell("<I>None found</I>");
261             htmltabledatacell1.setColSpan(2);
262             HtmlTableDataCell _tmp1 = htmltabledatacell1;
263             htmltabledatacell1.setHorizontalAlignment(2);
264             htmltablerow1.addCell(htmltabledatacell1);
265             htmltable.addRow(htmltablerow1);
266         }
267         else
268         {
269        
270             for(int i=0;i<names.size();i++)
271             {
272                
273              
274                String JavaDoc s=(String JavaDoc)names.get(i);
275                
276                 String JavaDoc s1 = (String JavaDoc)request.get(s);
277                 HtmlTableRow htmltablerow2 = new HtmlTableRow();
278                 htmltablerow2.addCell(new HtmlTableDataCell(capitalize(s)));
279                 htmltablerow2.addCell(new HtmlTableDataCell(s1));
280            htmltable.addRow(htmltablerow2);
281            }
282
283         }
284     }
285
286     private static void addCookieInformation(HtmlTable htmltable, Hashtable JavaDoc request)
287         throws Exception JavaDoc
288     {
289         Cookie JavaDoc acookie[] = (Cookie JavaDoc[])request.get("Cookies");
290         formatCookiesAsHtml(htmltable, acookie, "Request Cookies", false);
291     }
292
293     private static void formatCookiesAsHtml(HtmlTable htmltable, Cookie JavaDoc acookie[], String JavaDoc s, boolean flag)
294         throws Exception JavaDoc
295     {
296         HtmlTableRow htmltablerow = new HtmlTableRow();
297         HtmlTableHeaderCell htmltableheadercell = new HtmlTableHeaderCell("<FONT SIZE=+1 COLOR=#FFFFFF>" + s + "</FONT>");
298         htmltableheadercell.setColSpan(2);
299         HtmlTableHeaderCell _tmp = htmltableheadercell;
300         htmltableheadercell.setHorizontalAlignment(2);
301         htmltablerow.addCell(htmltableheadercell);
302         htmltablerow.setBackgroundColor("#888888");
303         htmltable.addRow(htmltablerow);
304         htmltablerow = new HtmlTableRow();
305         HtmlTableDataCell htmltabledatacell = new HtmlTableDataCell("<B>Cookie Name</B>");
306         htmltabledatacell.setPercentWidth(10);
307         htmltablerow.addCell(htmltabledatacell);
308         if(flag)
309             htmltabledatacell = new HtmlTableDataCell("<B>Attributes</B>");
310         else
311             htmltabledatacell = new HtmlTableDataCell("<B>Value</B>");
312         htmltablerow.addCell(htmltabledatacell);
313         htmltable.addRow(htmltablerow);
314         if(acookie.length == 0)
315         {
316             HtmlTableRow htmltablerow1 = new HtmlTableRow();
317             HtmlTableDataCell htmltabledatacell1 = new HtmlTableDataCell("<I>None found</I>");
318             htmltabledatacell1.setColSpan(2);
319             HtmlTableDataCell _tmp1 = htmltabledatacell1;
320             htmltabledatacell1.setHorizontalAlignment(2);
321             htmltablerow1.addCell(htmltabledatacell1);
322             htmltable.addRow(htmltablerow1);
323         } else
324         {
325             for(int j = 0; j < acookie.length; j++)
326             {
327                 HtmlTableRow htmltablerow2 = new HtmlTableRow();
328                 HtmlTableDataCell htmltabledatacell2 = new HtmlTableDataCell(acookie[j].getName());
329                 htmltablerow2.addCell(htmltabledatacell2);
330                 if(flag)
331                 {
332                     HtmlTable htmltable1 = new HtmlTable();
333                     htmltable1.setCellPadding(1);
334                     htmltable1.setCellSpacing(1);
335                     htmltable1.setBackgroundColor("#999999");
336                     htmltable1.setBorderWidth(0);
337                     htmltable1.setPercentWidth(100);
338                     HtmlTableRow htmltablerow3 = new HtmlTableRow();
339                     HtmlTableDataCell htmltabledatacell3 = new HtmlTableDataCell("Value:");
340                     htmltabledatacell3.setPercentWidth(10);
341                     HtmlTableDataCell _tmp2 = htmltabledatacell3;
342                     htmltabledatacell3.setHorizontalAlignment(3);
343                     htmltablerow3.addCell(htmltabledatacell3);
344                     htmltabledatacell3 = new HtmlTableDataCell(acookie[j].getValue());
345                     htmltablerow3.addCell(htmltabledatacell3);
346                     htmltable1.addRow(htmltablerow3);
347                     htmltablerow3 = new HtmlTableRow();
348                     htmltabledatacell3 = new HtmlTableDataCell("Domain:");
349                     HtmlTableDataCell _tmp3 = htmltabledatacell3;
350                     htmltabledatacell3.setHorizontalAlignment(3);
351                     htmltablerow3.addCell(htmltabledatacell3);
352                     String JavaDoc s1 = acookie[j].getDomain();
353                     if(s1 == null)
354                         htmltabledatacell3 = new HtmlTableDataCell("Not specified");
355                     else
356                         htmltabledatacell3 = new HtmlTableDataCell(s1);
357                     htmltablerow3.addCell(htmltabledatacell3);
358                     htmltable1.addRow(htmltablerow3);
359                     htmltablerow3 = new HtmlTableRow();
360                     htmltabledatacell3 = new HtmlTableDataCell("Path:");
361                     HtmlTableDataCell _tmp4 = htmltabledatacell3;
362                     htmltabledatacell3.setHorizontalAlignment(3);
363                     htmltablerow3.addCell(htmltabledatacell3);
364                     String JavaDoc s2 = acookie[j].getPath();
365                     if(s2 == null)
366                         htmltabledatacell3 = new HtmlTableDataCell("Not specified");
367                     else
368                         htmltabledatacell3 = new HtmlTableDataCell(s2);
369                     htmltablerow3.addCell(htmltabledatacell3);
370                     htmltable1.addRow(htmltablerow3);
371                     htmltablerow3 = new HtmlTableRow();
372                     htmltabledatacell3 = new HtmlTableDataCell("Max Age:");
373                     HtmlTableDataCell _tmp5 = htmltabledatacell3;
374                     htmltabledatacell3.setHorizontalAlignment(3);
375                     htmltablerow3.addCell(htmltabledatacell3);
376                     int i = acookie[j].getMaxAge();
377                     if(i == -1)
378                         htmltabledatacell3 = new HtmlTableDataCell("Not specified");
379                     else
380                         htmltabledatacell3 = new HtmlTableDataCell(i + " seconds");
381                     htmltablerow3.addCell(htmltabledatacell3);
382                     htmltable1.addRow(htmltablerow3);
383                     htmltablerow3 = new HtmlTableRow();
384                     htmltabledatacell3 = new HtmlTableDataCell("Secure:");
385                     HtmlTableDataCell _tmp6 = htmltabledatacell3;
386                     htmltabledatacell3.setHorizontalAlignment(3);
387                     htmltablerow3.addCell(htmltabledatacell3);
388                     if(acookie[j].getSecure())
389                         htmltabledatacell3 = new HtmlTableDataCell("Yes");
390                     else
391                         htmltabledatacell3 = new HtmlTableDataCell("No");
392                     htmltablerow3.addCell(htmltabledatacell3);
393                     htmltable1.addRow(htmltablerow3);
394                     htmltabledatacell2 = new HtmlTableDataCell(htmltable1.toString());
395                 } else
396                 {
397                     htmltabledatacell2 = new HtmlTableDataCell(acookie[j].getValue());
398                 }
399                 htmltablerow2.addCell(htmltabledatacell2);
400                 htmltable.addRow(htmltablerow2);
401             }
402
403         }
404     }
405
406     private static void addParameterInformation(HtmlTable htmltable, Hashtable JavaDoc request)
407         throws Exception JavaDoc
408     {
409         HtmlTableRow htmltablerow = new HtmlTableRow();
410         HtmlTableHeaderCell htmltableheadercell = new HtmlTableHeaderCell("<FONT SIZE=+1 COLOR=#FFFFFF>Request Parameters</FONT>");
411         htmltableheadercell.setColSpan(2);
412         HtmlTableHeaderCell _tmp = htmltableheadercell;
413         htmltableheadercell.setHorizontalAlignment(2);
414         htmltablerow.addCell(htmltableheadercell);
415         htmltablerow.setBackgroundColor("#888888");
416         htmltable.addRow(htmltablerow);
417         htmltablerow = new HtmlTableRow();
418         HtmlTableDataCell htmltabledatacell = new HtmlTableDataCell("<B>Parameter Name</B>");
419         htmltablerow.addCell(htmltabledatacell);
420         htmltabledatacell = new HtmlTableDataCell("<B>Value(s)</B>");
421         htmltablerow.addCell(htmltabledatacell);
422         htmltable.addRow(htmltablerow);
423        
424     
425       Vector JavaDoc names=(Vector JavaDoc)request.get("ParameterNames");
426      
427       
428   
429        if(names.size()==0)
430         {
431             HtmlTableRow htmltablerow1 = new HtmlTableRow();
432             HtmlTableDataCell htmltabledatacell1 = new HtmlTableDataCell("<I>None found</I>");
433             htmltabledatacell1.setColSpan(2);
434             HtmlTableDataCell _tmp1 = htmltabledatacell1;
435             htmltabledatacell1.setHorizontalAlignment(2);
436             htmltablerow1.addCell(htmltabledatacell1);
437             htmltable.addRow(htmltablerow1);
438         } else
439         {
440        
441             for(int j=0;j<names.size();j++)
442             {
443                 String JavaDoc s = (String JavaDoc)names.get(j);
444             
445                 String JavaDoc as[] =(String JavaDoc[]) request.get(s);
446              
447           
448               
449                 HtmlTableRow htmltablerow2 = new HtmlTableRow();
450                 HtmlTableDataCell htmltabledatacell2 = new HtmlTableDataCell(s);
451                 htmltablerow2.addCell(htmltabledatacell2);
452                 for(int i = 0; i < as.length; i++)
453                 {
454                     if(i == 0)
455                     {
456                         HtmlTableDataCell htmltabledatacell3 = new HtmlTableDataCell(as[0].trim(), "&nbsp");
457                         htmltablerow2.addCell(htmltabledatacell3);
458                         htmltable.addRow(htmltablerow2);
459                     } else
460                     {
461                         htmltablerow2 = new HtmlTableRow();
462                         HtmlTableDataCell htmltabledatacell4 = new HtmlTableDataCell("");
463                         htmltablerow2.addCell(htmltabledatacell4);
464                         htmltabledatacell4 = new HtmlTableDataCell(as[i].trim(), "&nbsp");
465                         htmltablerow2.addCell(htmltabledatacell4);
466                         htmltable.addRow(htmltablerow2);
467                     }
468
469                 }
470             }
471         }
472     }
473
474     private static void addResponseInformation(HtmlTable htmltable, Hashtable JavaDoc response)
475         throws Exception JavaDoc
476     {
477         HtmlTableRow htmltablerow = new HtmlTableRow();
478         HtmlTableHeaderCell htmltableheadercell = new HtmlTableHeaderCell("<FONT SIZE=+1 COLOR=#FFFFFF>Response Information</FONT>");
479         htmltableheadercell.setColSpan(2);
480         HtmlTableHeaderCell _tmp = htmltableheadercell;
481         htmltableheadercell.setHorizontalAlignment(2);
482         htmltablerow.addCell(htmltableheadercell);
483         htmltablerow.setBackgroundColor("#888888");
484         htmltable.addRow(htmltablerow);
485         if(response == null || response.equals(""))
486         {
487             HtmlTableRow htmltablerow1 = new HtmlTableRow();
488             HtmlTableDataCell htmltabledatacell = new HtmlTableDataCell("<I>Response Not Available</I>");
489             htmltabledatacell.setColSpan(2);
490             HtmlTableDataCell _tmp1 = htmltabledatacell;
491             htmltabledatacell.setHorizontalAlignment(2);
492             htmltablerow1.addCell(htmltabledatacell);
493             htmltable.addRow(htmltablerow1);
494         } else
495         {
496             HtmlTableRow htmltablerow2 = new HtmlTableRow();
497             HtmlTableDataCell htmltabledatacell1 = new HtmlTableDataCell("<B>Information</B>");
498             htmltabledatacell1.setPercentWidth(10);
499             htmltablerow2.addCell(htmltabledatacell1);
500             htmltabledatacell1 = new HtmlTableDataCell("<B>Value</B>");
501             htmltablerow2.addCell(htmltabledatacell1);
502             htmltable.addRow(htmltablerow2);
503             htmltablerow2 = new HtmlTableRow();
504             htmltabledatacell1 = new HtmlTableDataCell("Content Length");
505             htmltablerow2.addCell(htmltabledatacell1);
506          int i = ((Integer JavaDoc)response.get("ContentLengthResponse")).intValue() ;
507             
508             if(i == -1)
509                 htmltabledatacell1 = new HtmlTableDataCell("<I>Not set</I>");
510             else
511                 htmltabledatacell1 = new HtmlTableDataCell(Integer.toString(i));
512             htmltablerow2.addCell(htmltabledatacell1);
513             htmltable.addRow(htmltablerow2);
514             htmltablerow2 = new HtmlTableRow();
515             htmltabledatacell1 = new HtmlTableDataCell("Content Type");
516             htmltablerow2.addCell(htmltabledatacell1);
517          
518         String JavaDoc s =(String JavaDoc) response.get("ContentTypeResponse");
519              htmltabledatacell1 = new HtmlTableDataCell(s);
520             htmltablerow2.addCell(htmltabledatacell1);
521             htmltable.addRow(htmltablerow2);
522             htmltablerow2 = new HtmlTableRow();
523             htmltabledatacell1 = new HtmlTableDataCell("Status Code");
524             htmltablerow2.addCell(htmltabledatacell1);
525       int j =((Integer JavaDoc)response.get("StatusResponse")).intValue() ;
526            
527             String JavaDoc s1;
528             if(j == -1)
529                 s1 = "<i>Not set (defaults to 200 OK)</i>";
530             else
531                 s1 = Integer.toString(j);
532             htmltabledatacell1 = new HtmlTableDataCell(s1);
533             htmltablerow2.addCell(htmltabledatacell1);
534             htmltable.addRow(htmltablerow2);
535             htmltablerow2 = new HtmlTableRow();
536             htmltabledatacell1 = new HtmlTableDataCell("Message");
537             htmltablerow2.addCell(htmltabledatacell1);
538         
539    
540           s = (String JavaDoc)response.get("Message");
541   
542             htmltabledatacell1 = new HtmlTableDataCell(s);
543             htmltablerow2.addCell(htmltabledatacell1);
544             htmltablerow2 = new HtmlTableRow();
545             htmltabledatacell1 = new HtmlTableDataCell("Total Bytes");
546             htmltablerow2.addCell(htmltabledatacell1);
547         
548        
549         int k=((Integer JavaDoc)response.get("TotalBytesResponse")).intValue();
550         
551             if(k == -1)
552                 htmltabledatacell1 = new HtmlTableDataCell("<I>N/A</I>");
553             else
554                 htmltabledatacell1 = new HtmlTableDataCell(Integer.toString(k));
555             htmltablerow2.addCell(htmltabledatacell1);
556             htmltable.addRow(htmltablerow2);
557         }
558     }
559
560     private static void addResponseDataInformation(HtmlTable htmltable, Hashtable JavaDoc response)
561         throws Exception JavaDoc
562     {
563    String JavaDoc s ="";
564         if(s == "")
565         {
566             return;
567         } else
568         {
569             HtmlTableRow htmltablerow = new HtmlTableRow();
570             HtmlTableHeaderCell htmltableheadercell = new HtmlTableHeaderCell("<FONT SIZE=+1 COLOR=#FFFFFF>Response Data</FONT>");
571             htmltableheadercell.setColSpan(2);
572             HtmlTableHeaderCell _tmp = htmltableheadercell;
573             htmltableheadercell.setHorizontalAlignment(2);
574             htmltablerow.addCell(htmltableheadercell);
575             htmltablerow.setBackgroundColor("#888888");
576             htmltable.addRow(htmltablerow);
577             htmltablerow = new HtmlTableRow();
578             HtmlTableDataCell htmltabledatacell = new HtmlTableDataCell("<FORM><TEXTAREA ROWS=20 COLS=80>" + HtmlEncoder.encode(s) + "</TEXTAREA></FORM>");
579             htmltabledatacell.setColSpan(2);
580             htmltablerow.addCell(htmltabledatacell);
581             htmltable.addRow(htmltablerow);
582             return;
583         }
584     }
585
586     private static void addHeaderInformationResponse(HtmlTable htmltable, Hashtable JavaDoc response)
587         throws Exception JavaDoc
588     {
589         HtmlTableRow htmltablerow = new HtmlTableRow();
590         HtmlTableHeaderCell htmltableheadercell = new HtmlTableHeaderCell("<FONT SIZE=+1 COLOR=#FFFFFF>Response Headers</FONT>");
591         htmltableheadercell.setColSpan(2);
592         HtmlTableHeaderCell _tmp = htmltableheadercell;
593         htmltableheadercell.setHorizontalAlignment(2);
594         htmltablerow.addCell(htmltableheadercell);
595         htmltablerow.setBackgroundColor("#888888");
596         htmltable.addRow(htmltablerow);
597         htmltablerow = new HtmlTableRow();
598         HtmlTableDataCell htmltabledatacell = new HtmlTableDataCell("<B>Header Name</B>");
599         htmltabledatacell.setPercentWidth(10);
600         htmltablerow.addCell(htmltabledatacell);
601         htmltabledatacell = new HtmlTableDataCell("<B>Value(s)</B>");
602         htmltablerow.addCell(htmltabledatacell);
603         htmltable.addRow(htmltablerow);
604   
605         String JavaDoc names[] = (String JavaDoc[])response.get("HeaderNamesResponse");
606     
607         boolean flag = true;
608       if(names.length==0)
609         {
610             HtmlTableRow htmltablerow1 = new HtmlTableRow();
611             HtmlTableDataCell htmltabledatacell1 = new HtmlTableDataCell("<I>None found</I>");
612             htmltabledatacell1.setColSpan(2);
613             HtmlTableDataCell _tmp1 = htmltabledatacell1;
614             htmltabledatacell1.setHorizontalAlignment(2);
615             htmltablerow1.addCell(htmltabledatacell1);
616             htmltable.addRow(htmltablerow1);
617         } else
618         {
619         
620          for(int e=0; e<names.length;e++)
621             {
622                  String JavaDoc s = names[e];
623                                  
624                 String JavaDoc s1 = (String JavaDoc)response.get("Response"+s);
625             
626                 HtmlTableRow htmltablerow2 = new HtmlTableRow();
627                 htmltablerow2.addCell(new HtmlTableDataCell(capitalize(s)));
628                 htmltablerow2.addCell(new HtmlTableDataCell(s1));
629             htmltable.addRow(htmltablerow2);
630             }
631         }
632         
633     }
634
635     private static void addCookieInformationResponse(HtmlTable htmltable, Hashtable JavaDoc response)
636         throws Exception JavaDoc
637     {
638          Cookie JavaDoc acookie[] = (Cookie JavaDoc[])response.get("CookiesResponse");
639         
640         formatCookiesAsHtml(htmltable, acookie, "Response Cookies", true);
641     }
642
643     private static void addTrace(HtmlTable htmltable, ServletRequest request)
644     {
645         HtmlTableRow htmltablerow = new HtmlTableRow();
646         HtmlTableHeaderCell htmltableheadercell = new HtmlTableHeaderCell("<FONT SIZE=+1 COLOR=#FFFFFF>Request Trace</FONT>");
647         htmltableheadercell.setColSpan(2);
648         HtmlTableHeaderCell _tmp = htmltableheadercell;
649         htmltableheadercell.setHorizontalAlignment(2);
650         htmltablerow.addCell(htmltableheadercell);
651         htmltablerow.setBackgroundColor("#888888");
652         htmltable.addRow(htmltablerow);
653     }
654
655     public static String JavaDoc formatTraceDebugInfo(String JavaDoc s)
656     {
657         HtmlTable htmltable = new HtmlTable();
658         htmltable.setCellPadding(1);
659         htmltable.setCellSpacing(2);
660         htmltable.setBackgroundColor("#BBBBBB");
661         htmltable.setBorderWidth(0);
662         htmltable.setPercentWidth(100);
663         HtmlTableRow htmltablerow = new HtmlTableRow();
664         HtmlTableHeaderCell htmltableheadercell = new HtmlTableHeaderCell("<FONT SIZE=+1 COLOR=#FFFFFF>Trace Information</FONT>");
665         htmltableheadercell.setColSpan(2);
666         HtmlTableHeaderCell _tmp = htmltableheadercell;
667         htmltableheadercell.setHorizontalAlignment(2);
668         htmltablerow.addCell(htmltableheadercell);
669         htmltablerow.setBackgroundColor("#888888");
670         htmltable.addRow(htmltablerow);
671         if(s == null || s.equals(""))
672         {
673             HtmlTableRow htmltablerow1 = new HtmlTableRow();
674             HtmlTableDataCell htmltabledatacell = new HtmlTableDataCell("<I>Trace Not Available</I>");
675             htmltabledatacell.setColSpan(2);
676             HtmlTableDataCell _tmp1 = htmltabledatacell;
677             htmltabledatacell.setHorizontalAlignment(2);
678             htmltablerow1.addCell(htmltabledatacell);
679             htmltable.addRow(htmltablerow1);
680         } else
681         {
682             int i;
683             int j;
684             for(j = 0; (i = s.indexOf("\n", j)) > 0; j = i + 1)
685             {
686                 String JavaDoc s1 = s.substring(j, i);
687                 HtmlTableRow htmltablerow2 = new HtmlTableRow();
688                 HtmlTableDataCell htmltabledatacell1 = new HtmlTableDataCell("<CODE>" + s1 + "</CODE>");
689                 htmltabledatacell1.setColSpan(2);
690                 htmltablerow2.addCell(htmltabledatacell1);
691                 htmltable.addRow(htmltablerow2);
692             }
693
694             String JavaDoc s2 = s.substring(j);
695             HtmlTableRow htmltablerow3 = new HtmlTableRow();
696             HtmlTableDataCell htmltabledatacell2 = new HtmlTableDataCell("<CODE>" + s2 + "</CODE>");
697             htmltabledatacell2.setColSpan(2);
698             htmltablerow3.addCell(htmltabledatacell2);
699             htmltable.addRow(htmltablerow3);
700         }
701         HtmlTable htmltable1 = new HtmlTable();
702         htmltable1.setBackgroundColor("#EEEEEE");
703         htmltable1.setPercentWidth(100);
704         HtmlTableRow htmltablerow4 = new HtmlTableRow();
705         HtmlTableDataCell htmltabledatacell3 = new HtmlTableDataCell(htmltable.toString());
706         htmltablerow4.addCell(htmltabledatacell3);
707         htmltable1.addRow(htmltablerow4);
708         return htmltable1.toString();
709     }
710
711     public static String JavaDoc formatSessionInfo(String JavaDoc s, String JavaDoc s1)
712     {
713         HtmlTable htmltable = new HtmlTable();
714         htmltable.setCellPadding(1);
715         htmltable.setCellSpacing(2);
716         htmltable.setBackgroundColor("#BBBBBB");
717         htmltable.setBorderWidth(0);
718         htmltable.setPercentWidth(100);
719         HtmlTableRow htmltablerow = new HtmlTableRow();
720         HtmlTableHeaderCell htmltableheadercell = new HtmlTableHeaderCell("<FONT SIZE=+1 COLOR=#FFFFFF>" + s1 + "</FONT>");
721         htmltableheadercell.setColSpan(2);
722         HtmlTableHeaderCell _tmp = htmltableheadercell;
723         htmltableheadercell.setHorizontalAlignment(2);
724         htmltablerow.addCell(htmltableheadercell);
725         htmltablerow.setBackgroundColor("#888888");
726         htmltable.addRow(htmltablerow);
727         
728         
729         
730         if(s == null || s.equals("") )
731         {
732             
733             HtmlTableRow htmltablerow1 = new HtmlTableRow();
734             HtmlTableDataCell htmltabledatacell = new HtmlTableDataCell("<I>N/A</I>");
735             htmltabledatacell.setColSpan(2);
736             HtmlTableDataCell _tmp1 = htmltabledatacell;
737             htmltabledatacell.setHorizontalAlignment(2);
738             htmltablerow1.addCell(htmltabledatacell);
739             htmltable.addRow(htmltablerow1);
740         } else
741         {
742           if(s.equals("<UL>\n</UL>\n"))
743            s="<I>No Session</I>";
744             HtmlTableRow htmltablerow2 = new HtmlTableRow();
745             HtmlTableDataCell htmltabledatacell1 = new HtmlTableDataCell("<CODE>" + s + "</CODE>");
746             htmltabledatacell1.setColSpan(2);
747             htmltablerow2.addCell(htmltabledatacell1);
748             htmltable.addRow(htmltablerow2);
749         }
750         HtmlTable htmltable1 = new HtmlTable();
751         htmltable1.setBackgroundColor("#EEEEEE");
752         htmltable1.setPercentWidth(100);
753         HtmlTableRow htmltablerow3 = new HtmlTableRow();
754         HtmlTableDataCell htmltabledatacell2 = new HtmlTableDataCell(htmltable.toString());
755         htmltablerow3.addCell(htmltabledatacell2);
756         htmltable1.addRow(htmltablerow3);
757         return htmltable1.toString();
758     }
759
760     private static String JavaDoc capitalize(String JavaDoc s)
761     {
762         boolean flag = true;
763         StringBuffer JavaDoc stringbuffer = new StringBuffer JavaDoc();
764         for(int i = 0; i < s.length(); i++)
765         {
766             char c = s.charAt(i);
767             if(flag)
768             {
769                 stringbuffer.append(Character.toUpperCase(c));
770                 flag = false;
771             } else
772             {
773                 stringbuffer.append(c);
774             }
775             if(c == '-')
776                 flag = true;
777         }
778
779         return stringbuffer.toString();
780     }
781 }
Popular Tags