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


001:        package clime.messadmin.utils;
002:
003:        import java.net.MalformedURLException;
004:
005:        import javax.servlet.ServletContext;
006:        import javax.servlet.http.HttpServletRequest;
007:        import javax.servlet.http.HttpSession;
008:
009:        import clime.messadmin.model.ISessionInfo;
010:        import clime.messadmin.model.Server;
011:
012:        /**
013:         * Utility methods on HttpSessions...
014:         * @author Cédrik LIME
015:         */
016:        public class SessionUtils {
017:
018:            /**
019:             * 
020:             */
021:            private SessionUtils() {
022:                super ();
023:            }
024:
025:            public static int getUsedTimeForSession(HttpSession in_session) {
026:                try {
027:                    ISessionInfo extraSessionInfo = Server.getInstance()
028:                            .getSession(in_session).getSessionInfo();
029:                    if (null != extraSessionInfo) {
030:                        return extraSessionInfo.getTotalUsedTime();
031:                    } else {
032:                        return -1;
033:                    }
034:                    //long diffMilliSeconds = in_session.getLastAccessedTime() - in_session.getCreationTime();
035:                    //return diffMilliSeconds;
036:                } catch (IllegalStateException ise) {
037:                    //ignore: invalidated session
038:                    return -1;
039:                }
040:            }
041:
042:            public static int getTTLForSession(HttpSession in_session) {
043:                try {
044:                    long diffMilliSeconds = (1000 * in_session
045:                            .getMaxInactiveInterval())
046:                            - (System.currentTimeMillis() - in_session
047:                                    .getLastAccessedTime());
048:                    return (int) diffMilliSeconds;
049:                } catch (IllegalStateException ise) {
050:                    //ignore: invalidated session
051:                    return -1;
052:                }
053:            }
054:
055:            public static int getIdleTimeForSession(HttpSession in_session) {
056:                try {
057:                    long diffMilliSeconds = System.currentTimeMillis()
058:                            - in_session.getLastAccessedTime();
059:                    return (int) diffMilliSeconds;
060:                } catch (IllegalStateException ise) {
061:                    //ignore: invalidated session
062:                    return -1;
063:                }
064:            }
065:
066:            //TODO: move this method in a utility package
067:
068:            /**
069:             * Returns the context path of the web application. The context path is
070:             * the portion of the request URI that is used to select the context of
071:             * the request. The context path always comes first in a request URI. The
072:             * path starts with a "/" character but does not end with a "/" character.
073:             * For servlets in the default (root) context, this method returns "".
074:             * 
075:             * It is possible that a servlet container may match a context by more than
076:             * one context path. In such cases getContextPath() will return the actual
077:             * context path used by the request and it may differ from the path returned
078:             * by this method. The context path returned by this method should be considered
079:             * as the prime or preferred context path of the application.
080:             * 
081:             * @return The context path of the web application.
082:             */
083:            /**
084:             * FIXME debug this method so that it really works! Should return the same as HttpServletRequest.getContextPath(). Now, where the hell is ServletContext.getContextPath()? :-( UPDATE: it's in 2.5 now!
085:             * Returns the portion of the request URI that indicates the context
086:             * of the request.  The context path always comes first in a request
087:             * URI.  The path starts with a "/" character but does not end with a "/"
088:             * character.  For servlets in the default (root) context, this method
089:             * returns "". The container does not decode this string.
090:             * 
091:             * It is possible that a servlet container may match a context by more
092:             * than one context path. In such cases this method will return the actual
093:             * context path used by the request and it may differ from the path returned
094:             * by the ServletContext.getContextPath() method. The context path returned
095:             * by ServletContext.getContextPath() should be considered as the prime or
096:             * preferred context path of the application.
097:             * 
098:             * @param session
099:             * @return	a <code>String</code> specifying the portion of
100:             *			the request URI that indicates the context of the request
101:             */
102:            public static String getContext(HttpSession session) {
103:                return getContext(session.getServletContext());
104:            }
105:
106:            public static String getContext(ServletContext context) {
107:                //FIXME try new 2.5 ServletContext.getContextPath() first; use new plugin architecture
108:                try {
109:                    return context.getResource("/").getPath();//$NON-NLS-1$
110:                } catch (MalformedURLException mue) {
111:                    throw new RuntimeException(mue.getMessage());
112:                }
113:            }
114:
115:            /**
116:             * Reconstructs the URL the client used to make the request,
117:             * using information in the <code>HttpServletRequest</code> object.
118:             * The returned URL contains a protocol, server name, port
119:             * number, and server path, and include query
120:             * string parameters.
121:             * 
122:             * <p>This method is useful for creating redirect messages
123:             * and for reporting errors.
124:             *
125:             * @param req	a <code>HttpServletRequest</code> object
126:             *			containing the client's request
127:             * 
128:             * @return		a <code>String</code> object containing
129:             *			the reconstructed URL
130:             */
131:            public static String getRequestURLWithMethodAndQueryString(
132:                    HttpServletRequest req) {
133:                /*
134:                StringBuffer url = new StringBuffer(32);
135:                String scheme = req.getScheme();
136:                int port = req.getServerPort();
137:                if (port < 0) {
138:                	port = 80; // Work around java.net.URL bug
139:                }
140:                //String	servletPath = req.getServletPath();
141:                //String 	pathInfo = req.getPathInfo();
142:                String queryString = req.getQueryString();
143:
144:                url.append(scheme);	// http, https
145:                url.append("://"); //$NON-NLS-1$
146:                url.append(req.getServerName());
147:                if ((scheme.equals ("http") && port != 80) //$NON-NLS-1$
148:                	|| (scheme.equals ("https") && port != 443)) { //$NON-NLS-1$
149:                	url.append (':'); //$NON-NLS-1$
150:                	url.append (port);
151:                }
152:                //if (servletPath != null)
153:                //	url.append (servletPath);
154:                //if (pathInfo != null)
155:                //	url.append (pathInfo);
156:                url.append(req.getRequestURI());
157:                if (queryString != null) {
158:                	url.append('?').append(queryString); //$NON-NLS-1$
159:                }
160:                return url.toString();
161:                 */
162:                String method = req.getMethod();
163:                StringBuffer requestURL = req.getRequestURL();
164:                String queryString = req.getQueryString();
165:                int totalLength = method.length() + 1 + requestURL.length()
166:                        + (queryString == null ? 0 : 1 + queryString.length());
167:                StringBuffer buffer = new StringBuffer(totalLength);
168:                buffer.append(method).append(' ').append(requestURL);
169:                if (queryString != null && !"".equals(queryString)) {//$NON-NLS-1$
170:                    buffer.append('?').append(queryString);
171:                }
172:                return buffer.toString();
173:            }
174:
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.