Source Code Cross Referenced for Session.java in  » Profiler » MessAdmin » clime » messadmin » model » 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.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * 
003:         */package clime.messadmin.model;
004:
005:        import java.util.Hashtable;
006:        import java.util.Map;
007:
008:        import javax.servlet.ServletContext;
009:        import javax.servlet.http.HttpServletRequest;
010:        import javax.servlet.http.HttpSession;
011:        import javax.servlet.http.HttpSessionActivationListener;
012:        import javax.servlet.http.HttpSessionEvent;
013:
014:        import clime.messadmin.core.Constants;
015:        import clime.messadmin.filter.MessAdminRequestWrapper;
016:        import clime.messadmin.filter.MessAdminResponseWrapper;
017:        import clime.messadmin.utils.SessionUtils;
018:        import clime.messadmin.utils.StringUtils;
019:
020:        /**
021:         * @author Cédrik LIME
022:         */
023:        public class Session implements  HttpSessionActivationListener,
024:                IRequestListener {
025:            protected final SessionInfo sessionInfo;
026:            protected final Request cumulativeRequests = new Request(null);
027:            /**
028:             * Map of user-defined data to store in the Session scope.
029:             * This is mainly used for plugins (key == plugin FQ name, for example)
030:             */
031:            protected Map userData;
032:
033:            /**
034:             * @param session
035:             */
036:            public Session(HttpSession session) {
037:                super ();
038:                sessionInfo = new SessionInfo(session);
039:            }
040:
041:            /**
042:             */
043:            public Session(HttpSession session, ClassLoader cl) {
044:                this (session);
045:                sessionInfo.setClassLoader(cl);
046:            }
047:
048:            /**
049:             * @return Returns the sessionInfo.
050:             */
051:            public ISessionInfo getSessionInfo() {
052:                return sessionInfo;
053:            }
054:
055:            /**
056:             * @return Returns the userData.
057:             */
058:            // implementation note: this should be synchronized, but
059:            // we don't really care if multiple copies are created.
060:            public Map getUserData() {
061:                if (userData == null) {
062:                    userData = new Hashtable();
063:                }
064:                return userData;
065:            }
066:
067:            /**
068:             * {@inheritDoc}
069:             */
070:            public void sessionDidActivate(final HttpSessionEvent se) {
071:                sessionInfo.setHttpSession(se.getSession());
072:                //FIXME can the id change? Need to read the Servlet spec.
073:            }
074:
075:            /**
076:             * {@inheritDoc}
077:             */
078:            public void sessionWillPassivate(final HttpSessionEvent se) {
079:                sessionInfo.setHttpSession(null);
080:            }
081:
082:            /**
083:             * If message if blank or null, remove HttpSession attribute, otherwise inject message into HttpSessions
084:             * @param message
085:             */
086:            public boolean injectMessage(String message) {
087:                boolean inject = StringUtils.isNotBlank(message);
088:                boolean actionDone = false;
089:                if (inject) {
090:                    if (!message.equals(getSessionInfo().getAttribute(
091:                            Constants.SESSION_MESSAGE_KEY))) {
092:                        // Setting message
093:                        getSessionInfo().setAttribute(
094:                                Constants.SESSION_MESSAGE_KEY, message);
095:                        actionDone = true;
096:                    }
097:                } else {
098:                    if (getSessionInfo().getAttribute(
099:                            Constants.SESSION_MESSAGE_KEY) != null) {
100:                        // Removing message
101:                        getSessionInfo().removeAttribute(
102:                                Constants.SESSION_MESSAGE_KEY);
103:                        actionDone = true;
104:                    }
105:                }
106:                return actionDone;
107:            }
108:
109:            /*****************************************/
110:            /**	Request/Response Listener methods	**/
111:            /*****************************************/
112:
113:            /** {@inheritDoc} */
114:            public void requestInitialized(final HttpServletRequest request,
115:                    final ServletContext servletContext) {
116:                if (request == null || servletContext == null) {
117:                    return;
118:                }
119:                final HttpSession httpSession = request.getSession(false);
120:                if (httpSession == null) {
121:                    // should never happen!
122:                    return;
123:                } // else
124:                try {
125:                    sessionInfo.authType = request.getAuthType();
126:                    sessionInfo.remoteHost = request.getRemoteHost();//FIXME getRemoteAddr() if config says not to resolve IPs
127:                    sessionInfo.lastRequestURL = SessionUtils
128:                            .getRequestURLWithMethodAndQueryString(request);
129:                    sessionInfo.userPrincipal = request.getUserPrincipal();
130:                    sessionInfo.remoteUser = request.getRemoteUser();
131:                    sessionInfo.isSecure = request.isSecure();
132:                    sessionInfo.userAgent = request.getHeader("user-agent");//$NON-NLS-1$
133:                    sessionInfo.referer = request.getHeader("referer");//$NON-NLS-1$
134:                    sessionInfo.sslCipherSuite = (String) request
135:                            .getAttribute("javax.servlet.request.cipher_suite");//$NON-NLS-1$
136:                    sessionInfo.sslAlgorithmSize = (Integer) request
137:                            .getAttribute("javax.servlet.request.key_size");//$NON-NLS-1$
138:                    //			sessionInfo.sslCertificates	= (X509Certificate[])request.getAttribute("javax.servlet.request.X509Certificate");//$NON-NLS-1$
139:                    cumulativeRequests.requestInitialized(
140:                            sessionInfo.cumulativeRequestStats, request,
141:                            servletContext);
142:                } catch (IllegalStateException ise) {
143:                    // session is invalidated
144:                }
145:            }
146:
147:            /** {@inheritDoc} */
148:            public void requestDestroyed(final MessAdminRequestWrapper request,
149:                    final MessAdminResponseWrapper response,
150:                    final ServletContext servletContext) {
151:                if (request == null || response == null
152:                        || servletContext == null) {
153:                    return;
154:                }
155:                final HttpSession httpSession = request.getSession(false);
156:                if (httpSession == null) {
157:                    // should never happen!
158:                    return;
159:                } // else
160:                try {
161:                    // request not already counted
162:                    cumulativeRequests.requestDestroyed(
163:                            sessionInfo.cumulativeRequestStats, request,
164:                            response, servletContext);
165:                } catch (IllegalStateException ise) {
166:                    // session is invalidated
167:                }
168:            }
169:
170:            /** {@inheritDoc} */
171:            public void requestException(Exception e,
172:                    MessAdminRequestWrapper request,
173:                    MessAdminResponseWrapper response,
174:                    ServletContext servletContext) {
175:                if (request == null || response == null
176:                        || servletContext == null) {
177:                    return;
178:                }
179:                cumulativeRequests.requestException(
180:                        sessionInfo.cumulativeRequestStats, e, request,
181:                        response, servletContext);
182:            }
183:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.