Source Code Cross Referenced for MessAdminServlet.java in  » Profiler » MessAdmin » clime » messadmin » admin » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Profiler » MessAdmin » clime.messadmin.admin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package clime.messadmin.admin;
002:
003:        import java.io.IOException;
004:        import java.util.ArrayList;
005:        import java.util.Collection;
006:        import java.util.Collections;
007:        import java.util.Comparator;
008:        import java.util.Date;
009:        import java.util.List;
010:        import java.util.Locale;
011:        import java.util.Set;
012:
013:        import javax.servlet.Servlet;
014:        import javax.servlet.ServletException;
015:        import javax.servlet.http.HttpServlet;
016:        import javax.servlet.http.HttpServletRequest;
017:        import javax.servlet.http.HttpServletResponse;
018:        import javax.servlet.http.HttpSession;
019:
020:        import clime.messadmin.core.Constants;
021:        import clime.messadmin.core.MessAdmin;
022:        import clime.messadmin.i18n.I18NSupport;
023:        import clime.messadmin.model.Application;
024:        import clime.messadmin.model.IApplicationInfo;
025:        import clime.messadmin.model.IServerInfo;
026:        import clime.messadmin.model.ISessionInfo;
027:        import clime.messadmin.model.Server;
028:        import clime.messadmin.model.Session;
029:        import clime.messadmin.providers.spi.DisplayFormatProvider;
030:        import clime.messadmin.providers.spi.LocaleProvider;
031:        import clime.messadmin.providers.spi.UserNameProvider;
032:        import clime.messadmin.taglib.core.Util;
033:        import clime.messadmin.taglib.fmt.BundleTag;
034:        import clime.messadmin.taglib.jstl.fmt.LocalizationContext;
035:        import clime.messadmin.utils.ComparableBoolean;
036:        import clime.messadmin.utils.ReverseComparator;
037:        import clime.messadmin.utils.SessionUtils;
038:
039:        /**
040:         * Servlet implementation class for Servlet: MessAdminServlet
041:         * IMPLEMENTATION NOTE: always use include() instead of forward(), to get the real name of this servlet in jsp's
042:         * @author Cédrik LIME
043:         */
044:        public class MessAdminServlet extends HttpServlet implements  Servlet {
045:            private static final boolean DEBUG = false;
046:
047:            private static final String I18N_BUNDLE_NAME = "clime.messadmin.admin.i18n.core";//$NON-NLS-1$
048:
049:            private static final String METHOD_POST = "POST";//$NON-NLS-1$
050:
051:            protected String authorizationPassword = null;
052:
053:            /** {@inheritDoc} */
054:            public void log(String message) {
055:                if (DEBUG) {
056:                    getServletContext().log(getServletName() + ": " + message);//$NON-NLS-1$
057:                }
058:            }
059:
060:            /** {@inheritDoc} */
061:            public void log(String message, Throwable t) {
062:                if (DEBUG) {
063:                    getServletContext().log(
064:                            getServletName() + ": " + message, t);//$NON-NLS-1$
065:                }
066:            }
067:
068:            /* (non-Java-doc)
069:             * @see javax.servlet.http.HttpServlet#HttpServlet()
070:             */
071:            public MessAdminServlet() {
072:                super ();
073:            }
074:
075:            /**
076:             * {@inheritDoc}
077:             */
078:            protected void doGet(HttpServletRequest req,
079:                    HttpServletResponse resp) throws ServletException,
080:                    IOException {
081:                try {
082:                    process(req, resp);
083:                } finally {
084:                    I18NSupport.setAdminLocale(null);
085:                }
086:            }
087:
088:            /**
089:             * {@inheritDoc}
090:             */
091:            protected void doPost(HttpServletRequest req,
092:                    HttpServletResponse resp) throws ServletException,
093:                    IOException {
094:                try {
095:                    process(req, resp);
096:                } finally {
097:                    I18NSupport.setAdminLocale(null);
098:                }
099:            }
100:
101:            /**
102:             * Dispatcher method which processes the request
103:             * @param req
104:             * @param resp
105:             * @throws ServletException
106:             * @throws IOException 
107:             */
108:            protected void process(HttpServletRequest req,
109:                    HttpServletResponse resp) throws ServletException,
110:                    IOException {
111:                if (!HTTPAuthorizationProvider.checkAccess(
112:                        authorizationPassword, req, resp)) {
113:                    return;
114:                }
115:
116:                if (req.getParameter(Constants.APPLICATION_MESSAGE) != null) {
117:                    req.setAttribute(Constants.APPLICATION_MESSAGE, req
118:                            .getParameter(Constants.APPLICATION_MESSAGE));
119:                }
120:                if (req.getParameter(Constants.APPLICATION_ERROR) != null) {
121:                    req.setAttribute(Constants.APPLICATION_ERROR, req
122:                            .getParameter(Constants.APPLICATION_ERROR));
123:                }
124:
125:                DisplayFormatProvider displayFormatProvider = DisplayFormatProvider.Util
126:                        .getInstance(req);
127:                resp.setContentType(displayFormatProvider.getContentType());
128:                //resp.setCharacterEncoding("UTF-8");//$NON-NLS-1$
129:                // set response locale from client's browser settings.
130:                LocalizationContext l10nContext = BundleTag.findMatch(req,
131:                        I18N_BUNDLE_NAME);
132:                if (l10nContext != null && l10nContext.getLocale() != null) {
133:                    resp.setLocale(l10nContext.getLocale());
134:                } else {
135:                    resp.setLocale(I18NSupport.DEFAULT_ADMIN_LOCALE);
136:                }
137:                I18NSupport.setAdminLocale(resp.getLocale()); // necessary for plugins
138:
139:                displayFormatProvider.preProcess(req, resp);
140:
141:                final ClassLoader cl = Thread.currentThread()
142:                        .getContextClassLoader();
143:
144:                String action = req.getParameter("action");//$NON-NLS-1$
145:                // The Big Dispatch(TM), part 1
146:                if ("serverInfos".equals(action)) {//$NON-NLS-1$
147:                    displayServerInfosPage(displayFormatProvider, req, resp);
148:                    return;
149:                } else if ("webAppsList".equals(action)) {//$NON-NLS-1$
150:                    displayWebAppsList(displayFormatProvider, req, resp);
151:                    return;
152:                } else if ("injectApplications".equals(action)) {//$NON-NLS-1$
153:                    String permanent = req.getParameter("permanent");//$NON-NLS-1$
154:                    String[] applicationIds = req
155:                            .getParameterValues("applicationIds");//$NON-NLS-1$
156:                    String message = req.getParameter("message");//$NON-NLS-1$
157:                    int i;
158:                    if (permanent != null) {
159:                        i = MessAdmin.injectApplicationsPermanent(
160:                                applicationIds, message);
161:                    } else {
162:                        i = MessAdmin.injectApplicationsOnce(applicationIds,
163:                                message);
164:                    }
165:                    req
166:                            .setAttribute(
167:                                    Constants.APPLICATION_MESSAGE,
168:                                    I18NSupport
169:                                            .getLocalizedMessage(
170:                                                    I18N_BUNDLE_NAME,
171:                                                    cl,
172:                                                    "injectApplications.ok", new Integer[] { new Integer(i) }));//$NON-NLS-1$
173:                    displayWebAppsList(displayFormatProvider, req, resp);
174:                    return;
175:                }
176:
177:                // Get the WebApp context we want to work with
178:                String context = req.getParameter("context");//$NON-NLS-1$
179:                if (context == null
180:                        && Server.getInstance().getAllKnownInternalContexts()
181:                                .size() == 1) {
182:                    context = (String) Server.getInstance()
183:                            .getAllKnownInternalContexts().toArray()[0];//req.getContextPath();
184:                }
185:                // If no or invalid context, display a list of available WebApps
186:                if (context == null
187:                        || Server.getInstance().getApplication(context) == null) {
188:                    displayWebAppsList(displayFormatProvider, req, resp);
189:                    return;
190:                }
191:                req.setAttribute("context", context);//$NON-NLS-1$
192:
193:                // The Big Dispatch(TM), part 2
194:                if ("webAppStats".equals(action)) {//$NON-NLS-1$
195:                    displayWebAppStatsPage(displayFormatProvider, req, resp,
196:                            context);
197:                    return;
198:                } else if ("sessionsList".equals(action)) {//$NON-NLS-1$
199:                    displaySessionsListPage(displayFormatProvider, req, resp,
200:                            context);
201:                    return;
202:                } else if ("sessionDetail".equals(action)) {//$NON-NLS-1$
203:                    String sessionId = req.getParameter("sessionId");//$NON-NLS-1$
204:                    displaySessionDetailPage(displayFormatProvider, req, resp,
205:                            context, sessionId);
206:                    return;
207:                } else if ("removeServletContextAttribute".equals(action)) {//$NON-NLS-1$
208:                    String name = req.getParameter("attributeName");//$NON-NLS-1$
209:                    IApplicationInfo applicationInfo = Server.getInstance()
210:                            .getApplication(context).getApplicationInfo();
211:                    boolean removed = (null != applicationInfo
212:                            .getAttribute(name));
213:                    applicationInfo.removeAttribute(name);
214:                    if (removed) {
215:                        req
216:                                .setAttribute(
217:                                        Constants.APPLICATION_MESSAGE,
218:                                        I18NSupport
219:                                                .getLocalizedMessage(
220:                                                        I18N_BUNDLE_NAME,
221:                                                        cl,
222:                                                        "removeServletContextAttribute.ok", new String[] { name }));//$NON-NLS-1$
223:                    } else {
224:                        req
225:                                .setAttribute(
226:                                        Constants.APPLICATION_ERROR,
227:                                        I18NSupport
228:                                                .getLocalizedMessage(
229:                                                        I18N_BUNDLE_NAME,
230:                                                        cl,
231:                                                        "removeServletContextAttribute.ko", new String[] { context, name }));//$NON-NLS-1$
232:                    }
233:                    resp.sendRedirect(resp.encodeRedirectURL(req
234:                            .getRequestURL().append(
235:                                    "?action=webAppStats&context=").append(
236:                                    context).toString()));
237:                    return;
238:                } else if ("injectApplication".equals(action)) {//$NON-NLS-1$
239:                    String message = req.getParameter("message");//$NON-NLS-1$
240:                    Application application = Server.getInstance()
241:                            .getApplication(context);
242:                    application.injectPermanentMessage(message);
243:                    req.setAttribute(Constants.APPLICATION_MESSAGE, I18NSupport
244:                            .getLocalizedMessage(I18N_BUNDLE_NAME, cl,
245:                                    "injectApplication.ok"));//$NON-NLS-1$
246:                    displaySessionsListPage(displayFormatProvider, req, resp,
247:                            context);
248:                    return;
249:                } else if ("injectSessions".equals(action)) {//$NON-NLS-1$
250:                    String[] sessionIds = req.getParameterValues("sessionIds");//$NON-NLS-1$
251:                    String message = req.getParameter("message");//$NON-NLS-1$
252:                    int i = MessAdmin.injectSessions(context, sessionIds,
253:                            message);
254:                    req.setAttribute(Constants.APPLICATION_MESSAGE, "" + i
255:                            + " sessions modified.");
256:                    displaySessionsListPage(displayFormatProvider, req, resp,
257:                            context);
258:                    return;
259:                } else if ("invalidateSessions".equals(action)) {//$NON-NLS-1$
260:                    String[] sessionIds = req.getParameterValues("sessionIds");//$NON-NLS-1$
261:                    int i = MessAdmin.invalidateSessions(context, sessionIds);
262:                    req
263:                            .setAttribute(
264:                                    Constants.APPLICATION_MESSAGE,
265:                                    I18NSupport
266:                                            .getLocalizedMessage(
267:                                                    I18N_BUNDLE_NAME,
268:                                                    cl,
269:                                                    "invalidateSessions.ok", new Integer[] { new Integer(i) }));//$NON-NLS-1$
270:                    displaySessionsListPage(displayFormatProvider, req, resp,
271:                            context);
272:                    return;
273:                } else if ("setSessionMaxInactiveInterval".equals(action)) {//$NON-NLS-1$
274:                    String sessionId = req.getParameter("sessionId");//$NON-NLS-1$
275:                    String timeoutStr = req.getParameter("timeout");//$NON-NLS-1$
276:                    try {
277:                        int timeout = Integer.parseInt(timeoutStr.trim()) * 60;
278:                        int oldTimeout = MessAdmin
279:                                .setSessionMaxInactiveInterval(context,
280:                                        sessionId, timeout);
281:                        if (oldTimeout != 0) {
282:                            req
283:                                    .setAttribute(
284:                                            Constants.APPLICATION_MESSAGE,
285:                                            I18NSupport
286:                                                    .getLocalizedMessage(
287:                                                            I18N_BUNDLE_NAME,
288:                                                            cl,
289:                                                            "setSessionMaxInactiveInterval.ok", new Object[] { new Integer(oldTimeout / 60), timeoutStr }));//$NON-NLS-1$
290:                        } else {
291:                            req
292:                                    .setAttribute(
293:                                            Constants.APPLICATION_ERROR,
294:                                            I18NSupport
295:                                                    .getLocalizedMessage(
296:                                                            I18N_BUNDLE_NAME,
297:                                                            cl,
298:                                                            "setSessionMaxInactiveInterval.ko", new String[] { sessionId }));//$NON-NLS-1$
299:                        }
300:                    } catch (NumberFormatException nfe) {
301:                        req.setAttribute(Constants.APPLICATION_ERROR,
302:                                I18NSupport.getLocalizedMessage(
303:                                        I18N_BUNDLE_NAME, cl,
304:                                        "setSessionMaxInactiveInterval.error"));//$NON-NLS-1$
305:                    } catch (NullPointerException npe) {
306:                        req.setAttribute(Constants.APPLICATION_ERROR,
307:                                I18NSupport.getLocalizedMessage(
308:                                        I18N_BUNDLE_NAME, cl,
309:                                        "setSessionMaxInactiveInterval.error"));//$NON-NLS-1$
310:                    }
311:                    resp.sendRedirect(resp.encodeRedirectURL(req
312:                            .getRequestURL().append(
313:                                    "?action=sessionDetail&context=").append(
314:                                    context).append("&sessionId=").append(
315:                                    Util.URLEncode(sessionId, resp
316:                                            .getCharacterEncoding()))
317:                            .toString()));
318:                    return;
319:                } else if ("removeSessionAttribute".equals(action)) {//$NON-NLS-1$
320:                    String sessionId = req.getParameter("sessionId");//$NON-NLS-1$
321:                    String name = req.getParameter("attributeName");//$NON-NLS-1$
322:                    boolean removed = MessAdmin.removeSessionAttribute(context,
323:                            sessionId, name);
324:                    if (removed) {
325:                        req
326:                                .setAttribute(
327:                                        Constants.APPLICATION_MESSAGE,
328:                                        I18NSupport
329:                                                .getLocalizedMessage(
330:                                                        I18N_BUNDLE_NAME,
331:                                                        cl,
332:                                                        "removeSessionAttribute.ok", new String[] { name }));//$NON-NLS-1$
333:                    } else {
334:                        req
335:                                .setAttribute(
336:                                        Constants.APPLICATION_ERROR,
337:                                        I18NSupport
338:                                                .getLocalizedMessage(
339:                                                        I18N_BUNDLE_NAME,
340:                                                        cl,
341:                                                        "removeSessionAttribute.ko", new String[] { name }));//$NON-NLS-1$
342:                    }
343:                    resp.sendRedirect(resp.encodeRedirectURL(req
344:                            .getRequestURL().append(
345:                                    "?action=sessionDetail&context=").append(
346:                                    context).append("&sessionId=").append(
347:                                    Util.URLEncode(sessionId, resp
348:                                            .getCharacterEncoding()))
349:                            .toString()));
350:                    return;
351:                } // else
352:                // default fall-back action
353:                displaySessionsListPage(displayFormatProvider, req, resp,
354:                        context);
355:            }
356:
357:            private StringBuffer getMessages(HttpServletRequest req,
358:                    HttpServletResponse resp) {
359:                StringBuffer buffer = new StringBuffer();
360:                if (req.getAttribute(Constants.APPLICATION_MESSAGE) != null) {
361:                    buffer
362:                            .append('&')
363:                            .append(Constants.APPLICATION_MESSAGE)
364:                            .append('=')
365:                            .append(
366:                                    Util
367:                                            .URLEncode(
368:                                                    String
369:                                                            .valueOf(req
370:                                                                    .getAttribute(Constants.APPLICATION_MESSAGE)),
371:                                                    resp.getCharacterEncoding()));
372:                }
373:                if (req.getAttribute(Constants.APPLICATION_ERROR) != null) {
374:                    buffer
375:                            .append('&')
376:                            .append(Constants.APPLICATION_ERROR)
377:                            .append('=')
378:                            .append(
379:                                    Util
380:                                            .URLEncode(
381:                                                    String
382:                                                            .valueOf(req
383:                                                                    .getAttribute(Constants.APPLICATION_ERROR)),
384:                                                    resp.getCharacterEncoding()));
385:                }
386:                return buffer;
387:            }
388:
389:            protected void setNoCache(HttpServletResponse resp) {
390:                // <strong>NOTE</strong> - This header will be overridden
391:                // automatically if a <code>RequestDispatcher.forward()</code> call is
392:                // ultimately invoked.
393:                //resp.setHeader("Pragma", "No-cache"); // HTTP 1.0 //$NON-NLS-1$ //$NON-NLS-2$
394:                resp.setHeader("Cache-Control", "no-cache,no-store,max-age=0"); // HTTP 1.1 //$NON-NLS-1$ //$NON-NLS-2$
395:                resp.setDateHeader("Expires", 0); // 0 means now //$NON-NLS-1$
396:                // should we decide to enable caching, here are the current vary:
397:                resp.addHeader("Vary", "Accept-Language,Accept-Encoding");
398:            }
399:
400:            /**
401:             * Displays the Web Applications list
402:             * @param req
403:             * @param resp
404:             * @throws ServletException
405:             * @throws IOException
406:             */
407:            protected void displayWebAppsList(
408:                    DisplayFormatProvider displayFormatProvider,
409:                    HttpServletRequest req, HttpServletResponse resp)
410:                    throws ServletException, IOException {
411:                if (METHOD_POST.equals(req.getMethod())) {
412:                    resp
413:                            .sendRedirect(resp
414:                                    .encodeRedirectURL(req
415:                                            .getRequestURL()
416:                                            .append("?action=webAppsList").append(getMessages(req, resp)).toString()));//$NON-NLS-1$
417:                    return;
418:                }
419:                Set/*<ApplicationInfo>*/applicationInfos = Server
420:                        .getInstance().getApplicationInfos();
421:                setNoCache(resp);
422:                displayFormatProvider.displayWebAppsList(req, resp,
423:                        applicationInfos);
424:            }
425:
426:            /**
427:             * Displays the HttpSessions list for a given WebApp (context)
428:             * @param req
429:             * @param resp
430:             * @param context internal context name for required WebApp
431:             * @throws ServletException
432:             * @throws IOException
433:             */
434:            protected void displaySessionsListPage(
435:                    DisplayFormatProvider displayFormatProvider,
436:                    HttpServletRequest req, HttpServletResponse resp,
437:                    String context) throws ServletException, IOException {
438:                if (METHOD_POST.equals(req.getMethod())) {
439:                    StringBuffer buffer = req.getRequestURL().append(
440:                            "?action=sessionsList&context=").append(context);//$NON-NLS-1$
441:                    if (req.getAttribute("sort") != null) {//$NON-NLS-1$
442:                        buffer
443:                                .append('&')
444:                                .append("sort=").append(req.getAttribute("sort"));//$NON-NLS-1$//$NON-NLS-2$
445:                    }
446:                    if (req.getAttribute("order") != null) {//$NON-NLS-1$
447:                        buffer
448:                                .append('&')
449:                                .append("order=").append(req.getAttribute("order"));//$NON-NLS-1$//$NON-NLS-2$
450:                    }
451:                    resp.sendRedirect(resp.encodeRedirectURL(buffer.append(
452:                            getMessages(req, resp)).toString()));
453:                    return;
454:                }
455:                Collection/*<SessionInfo>*/activeSessions = Server
456:                        .getInstance().getApplication(context)
457:                        .getActiveSessionInfos();
458:                String sortBy = req.getParameter("sort");//$NON-NLS-1$
459:                String orderBy = null;
460:                if (null != sortBy && !"".equals(sortBy.trim())) {
461:                    activeSessions = new ArrayList(activeSessions);
462:                    Comparator comparator = getComparator(sortBy);
463:                    if (comparator != null) {
464:                        orderBy = req.getParameter("order");//$NON-NLS-1$
465:                        if ("DESC".equalsIgnoreCase(orderBy)) {//$NON-NLS-1$
466:                            comparator = new ReverseComparator(comparator);
467:                            //orderBy = "ASC";
468:                        } else {
469:                            //orderBy = "DESC";
470:                        }
471:                        try {
472:                            Collections.sort((List) activeSessions, comparator);
473:                        } catch (IllegalStateException ise) {
474:                            // at least 1 session is invalidated
475:                            req.setAttribute(Constants.APPLICATION_ERROR,
476:                                    I18NSupport.getLocalizedMessage(
477:                                            I18N_BUNDLE_NAME, null,
478:                                            "sessionsList.sort.error"));//$NON-NLS-1$
479:                        }
480:                    } else {
481:                        log("WARNING: unknown sort order: " + sortBy);
482:                    }
483:                }
484:                setNoCache(resp);
485:                displayFormatProvider.displaySessionsListPage(req, resp,
486:                        sortBy, orderBy, Server.getInstance().getApplication(
487:                                context).getApplicationInfo(), activeSessions,
488:                        Server.getInstance().getApplication(context)
489:                                .getPassiveSessionsIds());
490:            }
491:
492:            /**
493:             * Displays the details page for a given HttpSession
494:             * @param req
495:             * @param resp
496:             * @param context internal context name for required WebApp
497:             * @throws ServletException
498:             * @throws IOException
499:             */
500:            protected void displaySessionDetailPage(
501:                    DisplayFormatProvider displayFormatProvider,
502:                    HttpServletRequest req, HttpServletResponse resp,
503:                    String context, String sessionId) throws ServletException,
504:                    IOException {
505:                if (METHOD_POST.equals(req.getMethod())) {
506:                    resp.sendRedirect(resp.encodeRedirectURL(req
507:                            .getRequestURL().append(
508:                                    "?action=sessionDetail&context=").append(
509:                                    context).append("&sessionId=").append(
510:                                    Util.URLEncode(sessionId, resp
511:                                            .getCharacterEncoding())).append(
512:                                    getMessages(req, resp)).toString()));//$NON-NLS-1$//$NON-NLS-2$
513:                    return;
514:                }
515:                Application application = Server.getInstance().getApplication(
516:                        context);
517:                Session session = application.getSession(sessionId);
518:                if (null == session) {
519:                    String error = I18NSupport
520:                            .getLocalizedMessage(
521:                                    I18N_BUNDLE_NAME,
522:                                    null,
523:                                    "sessionDetail.null.error", new String[] { sessionId });//$NON-NLS-1$
524:                    log(error);
525:                    req.setAttribute(Constants.APPLICATION_ERROR, error);
526:                    displaySessionsListPage(displayFormatProvider, req, resp,
527:                            context);
528:                    return;
529:                }
530:                setNoCache(resp);
531:                IApplicationInfo applicationInfo = application
532:                        .getApplicationInfo();
533:                ISessionInfo currentSession = session.getSessionInfo();
534:                displayFormatProvider.displaySessionDetailPage(req, resp,
535:                        applicationInfo, currentSession);
536:            }
537:
538:            /**
539:             * Displays the details page for a Web Application
540:             * @param req
541:             * @param resp
542:             * @param context internal context name for required WebApp
543:             * @throws ServletException
544:             * @throws IOException
545:             */
546:            protected void displayWebAppStatsPage(
547:                    DisplayFormatProvider displayFormatProvider,
548:                    HttpServletRequest req, HttpServletResponse resp,
549:                    String context) throws ServletException, IOException {
550:                if (METHOD_POST.equals(req.getMethod())) {
551:                    resp
552:                            .sendRedirect(resp
553:                                    .encodeRedirectURL(req
554:                                            .getRequestURL()
555:                                            .append(
556:                                                    "?action=webAppStats&context=").append(context).append(getMessages(req, resp)).toString()));//$NON-NLS-1$
557:                    return;
558:                }
559:                setNoCache(resp);
560:                IApplicationInfo webAppStats = Server.getInstance()
561:                        .getApplication(context).getApplicationInfo();
562:                displayFormatProvider.displayWebAppStatsPage(req, resp,
563:                        webAppStats);
564:            }
565:
566:            /**
567:             * Displays the page for the Server Informations
568:             * @param req
569:             * @param resp
570:             * @throws ServletException
571:             * @throws IOException
572:             */
573:            protected void displayServerInfosPage(
574:                    DisplayFormatProvider displayFormatProvider,
575:                    HttpServletRequest req, HttpServletResponse resp)
576:                    throws ServletException, IOException {
577:                if (METHOD_POST.equals(req.getMethod())) {
578:                    resp
579:                            .sendRedirect(resp
580:                                    .encodeRedirectURL(req
581:                                            .getRequestURL()
582:                                            .append("?action=serverInfos").append(getMessages(req, resp)).toString()));//$NON-NLS-1$
583:                    return;
584:                }
585:                setNoCache(resp);
586:                IServerInfo serverInfo = Server.getInstance().getServerInfo();
587:                displayFormatProvider.displayServerInfosPage(req, resp,
588:                        serverInfo);
589:            }
590:
591:            /**
592:             * Comparator used on the HttpSessions list, when sorting is required
593:             * @param sortBy
594:             * @return Comparator
595:             */
596:            protected Comparator getComparator(String sortBy) {
597:                Comparator comparator = null;
598:                if ("CreationTime".equalsIgnoreCase(sortBy)) {//$NON-NLS-1$
599:                    comparator = new BaseSessionComparator() {
600:                        public Comparable getComparableObject(
601:                                HttpSession session) {
602:                            return new Date(session.getCreationTime());
603:                        }
604:                    };
605:                } else if ("id".equalsIgnoreCase(sortBy)) {//$NON-NLS-1$
606:                    comparator = new BaseSessionComparator() {
607:                        public Comparable getComparableObject(
608:                                HttpSession session) {
609:                            return session.getId();
610:                        }
611:                    };
612:                } else if ("LastAccessedTime".equalsIgnoreCase(sortBy)) {//$NON-NLS-1$
613:                    comparator = new BaseSessionComparator() {
614:                        public Comparable getComparableObject(
615:                                HttpSession session) {
616:                            return new Date(session.getLastAccessedTime());
617:                        }
618:                    };
619:                } else if ("MaxInactiveInterval".equalsIgnoreCase(sortBy)) {//$NON-NLS-1$
620:                    comparator = new BaseSessionComparator() {
621:                        public Comparable getComparableObject(
622:                                HttpSession session) {
623:                            return new Date(session.getMaxInactiveInterval());
624:                        }
625:                    };
626:                } else if ("new".equalsIgnoreCase(sortBy)) {//$NON-NLS-1$
627:                    comparator = new BaseSessionComparator() {
628:                        public Comparable getComparableObject(
629:                                HttpSession session) {
630:                            return ComparableBoolean.valueOf(session.isNew());
631:                        }
632:                    };
633:                } else if ("locale".equalsIgnoreCase(sortBy)) {//$NON-NLS-1$
634:                    comparator = new BaseSessionComparator() {
635:                        public Comparable getComparableObject(
636:                                HttpSession session) {
637:                            ClassLoader cl = Server
638:                                    .getInstance()
639:                                    .getApplication(session.getServletContext())
640:                                    .getApplicationInfo().getClassLoader();
641:                            Locale locale = LocaleProvider.Util
642:                                    .guessLocaleFromSession(session, cl);
643:                            return (null == locale) ? "" : locale.toString();
644:                        }
645:                    };
646:                } else if ("user".equalsIgnoreCase(sortBy)) {//$NON-NLS-1$
647:                    comparator = new BaseSessionComparator() {
648:                        public Comparable getComparableObject(
649:                                HttpSession session) {
650:                            ClassLoader cl = Server
651:                                    .getInstance()
652:                                    .getApplication(session.getServletContext())
653:                                    .getApplicationInfo().getClassLoader();
654:                            Object user = UserNameProvider.Util
655:                                    .guessUserFromSession(session, cl);
656:                            return (null == user) ? "" : user.toString();
657:                        }
658:                    };
659:                } else if ("UsedTime".equalsIgnoreCase(sortBy)) {//$NON-NLS-1$
660:                    comparator = new BaseSessionComparator() {
661:                        public Comparable getComparableObject(
662:                                HttpSession session) {
663:                            return new Date(SessionUtils
664:                                    .getUsedTimeForSession(session));
665:                        }
666:                    };
667:                } else if ("IdleTime".equalsIgnoreCase(sortBy)) {//$NON-NLS-1$
668:                    comparator = new BaseSessionComparator() {
669:                        public Comparable getComparableObject(
670:                                HttpSession session) {
671:                            return new Date(SessionUtils
672:                                    .getIdleTimeForSession(session));
673:                        }
674:                    };
675:                } else if ("TTL".equalsIgnoreCase(sortBy)) {//$NON-NLS-1$
676:                    comparator = new BaseSessionComparator() {
677:                        public Comparable getComparableObject(
678:                                HttpSession session) {
679:                            return new Date(SessionUtils
680:                                    .getTTLForSession(session));
681:                        }
682:                    };
683:                }
684:                //TODO: complete this to TTL, etc.
685:                return comparator;
686:            }
687:
688:            /**
689:             * {@inheritDoc}
690:             */
691:            public String getServletInfo() {
692:                return "MessAdminServlet, copyright (c) 2005-2007 Cédrik LIME";
693:            }
694:
695:            /**
696:             * {@inheritDoc}
697:             */
698:            public void init() throws ServletException {
699:                super .init();
700:                String initAuthorizationPassword = getServletConfig()
701:                        .getInitParameter("AuthorizationPassword");//$NON-NLS-1$
702:                if (null != initAuthorizationPassword) {
703:                    authorizationPassword = initAuthorizationPassword;
704:                }
705:                DisplayFormatProvider.Util.initAll(getServletConfig());
706:            }
707:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.