KickJava   Java API By Example, From Geeks To Geeks.

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


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: DebugServer.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 import java.io.ObjectOutputStream JavaDoc;
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
52 public class DebugServer implements HttpPresentation {
53
54
55     public void run(HttpPresentationComms comms) throws Exception JavaDoc {
56
57
58
59       
60       
61         String JavaDoc action = comms.request.getParameter("action");
62         if ((action == null) || (action.length() == 0))
63             return;
64         if(action.equals("getSnapshot"))
65         {
66             sendSnapshot(comms);
67             return;
68         }
69         if(action.equals("start"))
70         {
71             startDebugging(comms);
72             return;
73         }
74         if(action.equals("stop"))
75         {
76             stopDebugging(comms);
77             return;
78         } else
79         {
80             return;
81         }
82     }
83
84
85     private void sendSnapshot(HttpPresentationComms comms) throws Exception JavaDoc {
86         long id = -1;
87        
88       
89         try {
90             String JavaDoc ids = comms.request.getParameter("id");
91             id = Long.parseLong(ids);
92         } catch (Exception JavaDoc e) {
93         }
94        
95         int wait = 0;
96         try {
97             String JavaDoc waitStr = comms.request.getParameter("wait");
98             wait = Integer.parseInt(waitStr);
99         } catch (Exception JavaDoc e) {
100         }
101     ServletMonitor sm=ServletMonitorFactory.getServletMonitor("com.lutris.appserver.debugger.business.ServletMonitorImpl");
102    
103       sm.takeSnapshotAndWrite(comms,id, wait);
104  
105     
106   
107     
108     }
109
110     private void startDebugging(HttpPresentationComms comms) throws Exception JavaDoc {
111         
112       
113         
114         
115         String JavaDoc response = "ERR";
116         String JavaDoc name = comms.request.getParameter("name");
117         if (name != null) {
118              ServletMonitor sm=ServletMonitorFactory.getServletMonitor("com.lutris.appserver.debugger.business.ServletMonitorImpl");
119     
120             boolean ok = sm.start(name);
121             if (ok)
122                 response = "OK";
123          }
124         
125           
126         comms.response.setContentType("text/ascii");
127         comms.response.setContentLength(response.length());
128         comms.response.getOutputStream().println(response);
129
130       
131     }
132     
133     private void stopDebugging(HttpPresentationComms comms) throws Exception JavaDoc {
134         String JavaDoc response = "ERR";
135         String JavaDoc name = comms.request.getParameter("name");
136         if (name != null) {
137     ServletMonitor sm=ServletMonitorFactory.getServletMonitor("com.lutris.appserver.debugger.business.ServletMonitorImpl");
138     
139             boolean ok = sm.stop(name);
140             if (ok)
141                 response = "OK";
142         }
143         comms.response.setContentType("text/ascii");
144         comms.response.setContentLength(response.length());
145         comms.response.getOutputStream().println(response);
146     }
147     
148
149 }
150
Popular Tags