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 org.apache.catalina.connector;
006:
007: import org.apache.catalina.Realm;
008: import org.apache.catalina.Session;
009:
010: import com.tc.object.util.OverrideCheck;
011: import com.tc.tomcat.session.SessionInternal;
012: import com.terracotta.session.TerracottaRequest;
013:
014: import javax.servlet.http.HttpServletRequest;
015: import javax.servlet.http.HttpSession;
016:
017: // NOTE: A class adapter adds methods that delegate all override'able methods of tomcat's
018: // Request class to the "valveReq" instance
019: public class SessionRequest55 extends Request {
020:
021: static {
022: OverrideCheck.check(Request.class, SessionRequest55.class);
023: }
024:
025: private final Request valveReq;
026: private final TerracottaRequest sessionReq;
027: private final Realm realm;
028: private SessionResponse55 sessionRes;
029: private Session sessionInternal = null;
030:
031: /**
032: * @param sessionReq SessionRequest must be a HttpServletRequest slice of Request
033: * @param valveReq
034: */
035: public SessionRequest55(TerracottaRequest sessionReq,
036: Request valveReq, Realm realm) {
037: this .valveReq = valveReq;
038: this .sessionReq = sessionReq;
039: this .realm = realm;
040:
041: // silence compiler warning
042: if (false && this .valveReq != this .valveReq) {
043: throw new AssertionError();
044: }
045: }
046:
047: public void setSessionResponse(SessionResponse55 sessionRes) {
048: this .sessionRes = sessionRes;
049: }
050:
051: public HttpSession getSession() {
052: return sessionReq.getSession();
053: }
054:
055: public HttpSession getSession(boolean arg0) {
056: return sessionReq.getSession(arg0);
057: }
058:
059: public String getRequestedSessionId() {
060: return sessionReq.getRequestedSessionId();
061: }
062:
063: public boolean isRequestedSessionIdFromCookie() {
064: return sessionReq.isRequestedSessionIdFromCookie();
065: }
066:
067: public boolean isRequestedSessionIdFromUrl() {
068: return sessionReq.isRequestedSessionIdFromUrl();
069: }
070:
071: public boolean isRequestedSessionIdFromURL() {
072: return sessionReq.isRequestedSessionIdFromURL();
073: }
074:
075: public boolean isRequestedSessionIdValid() {
076: return sessionReq.isRequestedSessionIdValid();
077: }
078:
079: public HttpServletRequest getRequest() {
080: return sessionReq;
081: }
082:
083: public Response getResponse() {
084: return sessionRes;
085: }
086:
087: public Session getSessionInternal() {
088: return getSessionInternal(true);
089: }
090:
091: public Session getSessionInternal(boolean create) {
092: synchronized (this ) {
093: if (sessionInternal != null) {
094: return sessionInternal;
095: }
096:
097: com.terracotta.session.Session tcSession = (com.terracotta.session.Session) getSession(create);
098: if (tcSession == null) {
099: return null;
100: }
101:
102: return sessionInternal = new SessionInternal(tcSession,
103: realm);
104: }
105:
106: // unreachable
107: }
108:
109: }
|