|
What this is
Other links
The source code
/*
* Copyright 1999-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.tomcat.facade;
import java.util.Enumeration;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import javax.servlet.http.HttpSessionContext;
import org.apache.tomcat.core.ServerSession;
import org.apache.tomcat.util.res.StringManager;
/**
* Facade for http session. Used to prevent servlets to access
* internal tomcat objects.
*
* This is a "special" facade - since session management is
* (more or less) orthogonal to request processing, it is
* indpendent of tomcat architecture. It will provide a
* HttpSession implementation ( but it's not guaranteed
* in any way it is "safe" ), and HttpSessionFacade will
* act as a "guard" to make sure only servlet API public
* methods are exposed.
*
* Another thing to note is that this object will be recycled
* and will allways be set in a request. The "real" session
* object will determine if the request is part of a session.
*
* @author James Duncan Davidson [duncan@eng.sun.com]
* @author Jason Hunter [jch@eng.sun.com]
* @author James Todd [gonzo@eng.sun.com]
* @author costin@eng.sun.com
*/
public final class HttpSessionFacade implements HttpSession {
private static StringManager sm =
StringManager.getManager("org.apache.tomcat.resources");
ServerSession realSession;
// We need to keep the Id, since it may change in realSession.
private String sessionId;
private boolean isValid = false;
HttpSessionFacade() {
}
/** Package-level method - accessible only by core
*/
void setRealSession(ServerSession s) {
realSession=s;
realSession.setFacade( this );
sessionId = realSession.getId().toString();
isValid = true;
}
/** Package-level method - accessible only by core
*/
void recycle() {
isValid = false;
// realSession=null;
}
// -------------------- public facade --------------------
public String getId() {
return sessionId;
}
/**
* Return the time when this session was created, in milliseconds since
* midnight, January 1, 1970 GMT.
*
* @exception IllegalStateException if this method is called on an
* invalidated session
*/
public long getCreationTime() {
checkValid();
return realSession.getTimeStamp().getCreationTime();
}
/**
* We return our own "disabled" SessionContext -
* regardless of what the real session returns.
*
* @deprecated
*/
public HttpSessionContext getSessionContext() {
return new SessionContextImpl();
}
public long getLastAccessedTime() {
return realSession.getTimeStamp().getLastAccessedTime();
}
/**
* Invalidates this session and unbinds any objects bound to it.
*
* @exception IllegalStateException if this method is called on
* an invalidated session
*/
public void invalidate() {
checkValid();
realSession.getTimeStamp().setValid( false );
// remove all attributes
if( dL > 0 ) d("Invalidate " + realSession.getId());
realSession.setState(ServerSession.STATE_EXPIRED);
realSession.recycle();
realSession.setState(ServerSession.STATE_INVALID);
}
/**
* Return
|
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.