KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Jmx_dynamic


1 /**
2  * The XMOJO Project 5
3  * Copyright © 2003 XMOJO.org. All rights reserved.
4
5  * NO WARRANTY
6
7  * BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
8  * THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
9  * OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
10  * PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
11  * OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
13  * TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE
14  * LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
15  * REPAIR OR CORRECTION.
16
17  * IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
18  * ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE
19  * THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
20  * GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
21  * USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF
22  * DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
23  * PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE),
24  * EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGES.
26 **/

27
28 import java.io.*;
29 import java.util.*;
30 import javax.servlet.*;
31 import javax.servlet.http.*;
32 import javax.management.*;
33
34 import com.adventnet.html.dynamic.*;
35 import com.adventnet.adaptors.html.*;
36
37 import com.adventnet.agent.logging.*;
38
39 /**
40  * Sevlet class for the HTML adaptor of JMX agent. All the communication
41  * of the JMX server to the browser through this servlet if the request
42  * is for dynamic page request.
43  */

44
45 public class Jmx_dynamic extends HttpServlet
46 {
47     /* Mail class object for html */
48     private DynamicMain main;
49
50     private com.adventnet.agent.logging.Log log;
51
52     /**
53      * Method to initialize. This method is called once
54      * by the web-server.
55      */

56
57     public void init(ServletConfig config) throws ServletException
58     {
59         super.init(config);
60
61          try {
62                         log = LogFactory.getInstance("HTML");
63                 }
64                 catch (InstantiationException JavaDoc ie)
65                 {
66                         ie.printStackTrace();
67                 }
68     }
69
70
71     /**
72      * This method is invoked by the web-server when a get is
73      * called from the browser.
74      *
75      * @param sreq - the collection of data rcvd from the browser.
76      * @param sres - the collection of data send to the browser.
77      */

78     public void doGet(HttpServletRequest sreq, HttpServletResponse sres)
79         throws ServletException, IOException {
80             sres.setContentType("text/html");
81             String JavaDoc result = null;
82             sreq.getSession(true);
83             main = new DynamicMain();
84
85             String JavaDoc name = sreq.getParameter("fname");
86             if (name != null && name.equals("aboutus.html")) {
87                 RequestDispatcher reqDispatch = sreq.getRequestDispatcher("/"+name);
88                 reqDispatch.forward(sreq, sres);
89                 return;
90             }
91
92             HtmlCreation htmlCr = new HtmlCreation();
93                         try {
94                             htmlCr.setContextPath(sreq.getContextPath());
95                         } catch(NoSuchMethodError JavaDoc nsme) {
96                             htmlCr.setContextPath("");
97                         }
98
99             main.registerHtmlInterface(htmlCr);
100             main.registerErrorInterface(new DynamicError());
101
102             Hashtable table = new Hashtable();
103
104             HttpSession session = sreq.getSession(true);
105
106             String JavaDoc id = session.getId();
107             //HtmlAdaptor.setClientInfo(id);
108

109             table.put((String JavaDoc)"Session", session);
110             Enumeration e = sreq.getParameterNames();
111
112             for (; e.hasMoreElements(); ) {
113                 Object JavaDoc paramName = e.nextElement();
114                 String JavaDoc paramValue = sreq.getParameter(paramName.toString());
115                 log.trace("ParamName is "+paramName+" "+"ParamValue is "+paramValue);
116
117                 if (paramValue.trim().length() != 0)
118                 {
119                     table.put(paramName, paramValue);
120                 }
121             }
122
123
124             PrintWriter p = sres.getWriter();
125
126             //System.out.println("Inside Get");
127
result = main.processGetRequest(table);
128
129             //System.out.println("The result is " + result);
130

131             p.println(result);
132             p.flush();
133             p.close();
134             return;
135         }
136
137     public void doPost(HttpServletRequest sreq, HttpServletResponse sres)
138         throws ServletException, IOException {
139             sres.setContentType("text/html");
140             String JavaDoc result = null;
141             //sreq.getSession(true);
142

143 // String s1 = sreq.getParameter("arrayType");
144

145             //System.out.println("POST");
146
main = new DynamicMain();
147
148             HtmlCreation htmlCr = new HtmlCreation();
149                         try {
150                             htmlCr.setContextPath(sreq.getContextPath());
151                         } catch(NoSuchMethodError JavaDoc nsme) {
152                             htmlCr.setContextPath("");
153                         }
154
155             main.registerHtmlInterface(htmlCr);
156             main.registerErrorInterface(new DynamicError());
157
158             HttpSession session = sreq.getSession(true);
159
160             String JavaDoc objName = sreq.getParameter("attrbName");
161             Hashtable table = new Hashtable();
162             table.put((String JavaDoc)"Session", session);
163
164 // table = null;
165
//System.out.println("inside do post");
166
//System.out.println("Object name is " + objName);
167

168
169 // if((Object)s1 == null){
170

171
172                 Enumeration e = sreq.getParameterNames();
173
174                 for (; e.hasMoreElements(); ) {
175                     Object JavaDoc paramName = e.nextElement();
176                     String JavaDoc paramValue = sreq.getParameter(paramName.toString());
177                     log.trace("ParamName is "+paramName+" "+"ParamValue is "+paramValue);
178                 if (paramValue.trim().length() != 0)
179                 {
180                     table.put(paramName, paramValue);
181                 }
182                 }
183 // }
184
if( (Object JavaDoc) table != null)
185             {
186                 PrintWriter p = sres.getWriter();
187
188                 result = main.processPostRequest(table);
189
190                 p.println(result);
191                 p.flush();
192                 p.close();
193             };
194 /* p.println("hai");
195             p.flush();
196             p.close(); */

197             return ;
198
199
200
201             // doGet(sreq,sres);
202
}
203 }
204
Popular Tags