Source Code Cross Referenced for SessionRequest.java in  » Net » Terracotta » com » terracotta » session » 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 » Net » Terracotta » com.terracotta.session 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003:         * notice. All rights reserved.
004:         */
005:        package com.terracotta.session;
006:
007:        import com.terracotta.session.util.Assert;
008:
009:        import javax.servlet.RequestDispatcher;
010:        import javax.servlet.http.HttpServletRequest;
011:        import javax.servlet.http.HttpServletRequestWrapper;
012:        import javax.servlet.http.HttpServletResponse;
013:        import javax.servlet.http.HttpSession;
014:
015:        public class SessionRequest extends HttpServletRequestWrapper implements 
016:                TerracottaRequest {
017:
018:            // Attribute name for storing the Session in the request
019:            private static final String SESSION_ATTRIBUTE_NAME = SessionRequest.class
020:                    .getName()
021:                    + ".session";
022:
023:            // Attribute name for storing a Boolean.TRUE indicating the request has been forwarded
024:            public static final String SESSION_FORWARD_ATTRIBUTE_NAME = SessionRequest.class
025:                    .getName()
026:                    + ".forward";
027:
028:            private final HttpServletRequest req;
029:            private final HttpServletResponse res;
030:            private SessionId requestedSessionId;
031:            private final long requestStartMillis;
032:            private final boolean isForwarded;
033:            private final boolean isSessionOwner;
034:            private final SessionManager mgr;
035:
036:            public SessionRequest(SessionId requestedSessionId,
037:                    HttpServletRequest req, HttpServletResponse res,
038:                    SessionManager sessionManager) {
039:                super (req);
040:
041:                Assert.pre(req != null);
042:                Assert.pre(res != null);
043:                Assert.pre(sessionManager != null);
044:
045:                this .req = req;
046:                this .res = res;
047:                this .mgr = sessionManager;
048:                this .requestedSessionId = requestedSessionId;
049:                this .requestStartMillis = System.currentTimeMillis();
050:                // in some cases, we could be multi-wrapping native requests.
051:                // in this case, we need to check if TC session has already been created
052:                HttpSession nativeSess = req.getSession(false);
053:                if (nativeSess instanceof  Session) {
054:                    this .isForwarded = true;
055:                    this .isSessionOwner = false;
056:                    setAttribute(SESSION_ATTRIBUTE_NAME, nativeSess);
057:                } else {
058:                    this .isSessionOwner = true;
059:
060:                    // Added by TerracottaDispatcher when requests get forwarded through
061:                    Object fwdFlag = req
062:                            .getAttribute(SESSION_FORWARD_ATTRIBUTE_NAME);
063:                    this .isForwarded = (fwdFlag != null && fwdFlag
064:                            .equals(Boolean.TRUE));
065:                }
066:            }
067:
068:            public HttpSession getSession() {
069:                HttpSession rv = getTerracottaSession(true);
070:                Assert.post(rv != null);
071:                return rv;
072:            }
073:
074:            public HttpSession getSession(boolean createNew) {
075:                return getTerracottaSession(createNew);
076:            }
077:
078:            public boolean isRequestedSessionIdValid() {
079:                if (requestedSessionId == null)
080:                    return false;
081:                Session sess = getTerracottaSession(false);
082:                return (sess != null && requestedSessionId.getKey().equals(
083:                        sess.getSessionId().getKey()));
084:            }
085:
086:            public String encodeRedirectURL(String url) {
087:                return mgr.getCookieWriter().encodeRedirectURL(url, this );
088:            }
089:
090:            public String encodeURL(String url) {
091:                return mgr.getCookieWriter().encodeURL(url, this );
092:            }
093:
094:            public final Session getTerracottaSession(boolean createNew) {
095:                Session session = (Session) getAttribute(SESSION_ATTRIBUTE_NAME);
096:                if (session != null)
097:                    return session;
098:                session = (createNew) ? mgr.getSession(requestedSessionId, req,
099:                        res) : mgr.getSessionIfExists(requestedSessionId, req,
100:                        res);
101:                setAttribute(SESSION_ATTRIBUTE_NAME, session);
102:
103:                if (session != null) {
104:                    session.associateRequest(this );
105:                }
106:                Assert.post(!createNew || session != null);
107:                return session;
108:            }
109:
110:            public boolean isSessionOwner() {
111:                return isSessionOwner
112:                        && getAttribute(SESSION_ATTRIBUTE_NAME) != null;
113:            }
114:
115:            public boolean isForwarded() {
116:                return isForwarded;
117:            }
118:
119:            public long getRequestStartMillis() {
120:                return requestStartMillis;
121:            }
122:
123:            public RequestDispatcher getRequestDispatcher(String path) {
124:                return new TerracottaDispatcher(super 
125:                        .getRequestDispatcher(path));
126:            }
127:
128:            void clearSession() {
129:                Assert.pre(getAttribute(SESSION_ATTRIBUTE_NAME) != null);
130:                removeAttribute(SESSION_ATTRIBUTE_NAME);
131:
132:                requestedSessionId = null;
133:            }
134:
135:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.