本文整理汇总了Java中org.apache.catalina.Session.access方法的典型用法代码示例。如果您正苦于以下问题:Java Session.access方法的具体用法?Java Session.access怎么用?Java Session.access使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.catalina.Session
的用法示例。
在下文中一共展示了Session.access方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findSession
import org.apache.catalina.Session; //导入方法依赖的package包/类
/**
* {@inheritDoc}
* <p>
* This method checks the persistence store if persistence is enabled,
* otherwise just uses the functionality from ManagerBase.
*/
@Override
public Session findSession(String id) throws IOException {
Session session = super.findSession(id);
// OK, at this point, we're not sure if another thread is trying to
// remove the session or not so the only way around this is to lock it
// (or attempt to) and then try to get it by this session id again. If
// the other code ran swapOut, then we should get a null back during
// this run, and if not, we lock it out so we can access the session
// safely.
if(session != null) {
synchronized(session){
session = super.findSession(session.getIdInternal());
if(session != null){
// To keep any external calling code from messing up the
// concurrency.
session.access();
session.endAccess();
}
}
}
if (session != null)
return session;
// See if the Session is in the Store
session = swapIn(id);
return session;
}
示例2: findSession
import org.apache.catalina.Session; //导入方法依赖的package包/类
/**
* Return the active Session, associated with this Manager, with the
* specified session id (if any); otherwise return <code>null</code>.
* This method checks the persistence store if persistence is enabled,
* otherwise just uses the functionality from ManagerBase.
*
* @param id The session id for the session to be returned
*
* @exception IllegalStateException if a new session cannot be
* instantiated for any reason
* @exception IOException if an input/output error occurs while
* processing this request
*/
public Session findSession(String id) throws IOException {
Session session = super.findSession(id);
// OK, at this point, we're not sure if another thread is trying to
// remove the session or not so the only way around this is to lock it
// (or attempt to) and then try to get it by this session id again. If
// the other code ran swapOut, then we should get a null back during
// this run, and if not, we lock it out so we can access the session
// safely.
if(session != null) {
synchronized(session){
session = super.findSession(session.getIdInternal());
if(session != null){
// To keep any external calling code from messing up the
// concurrency.
session.access();
session.endAccess();
}
}
}
if (session != null)
return (session);
// See if the Session is in the Store
session = swapIn(id);
return (session);
}
示例3: findSession
import org.apache.catalina.Session; //导入方法依赖的package包/类
/**
* {@inheritDoc}
* <p>
* This method checks the persistence store if persistence is enabled,
* otherwise just uses the functionality from ManagerBase.
*/
@Override
public Session findSession(String id) throws IOException {
Session session = super.findSession(id);
// OK, at this point, we're not sure if another thread is trying to
// remove the session or not so the only way around this is to lock it
// (or attempt to) and then try to get it by this session id again. If
// the other code ran swapOut, then we should get a null back during
// this run, and if not, we lock it out so we can access the session
// safely.
if (session != null) {
synchronized (session) {
session = super.findSession(session.getIdInternal());
if (session != null) {
// To keep any external calling code from messing up the
// concurrency.
session.access();
session.endAccess();
}
}
}
if (session != null)
return session;
// See if the Session is in the Store
session = swapIn(id);
return session;
}
示例4: getSession
import org.apache.catalina.Session; //导入方法依赖的package包/类
/**
* Return the session associated with this Request, creating one
* if necessary and requested.
*
* @param create Create a new session if one does not exist
*/
@Override
public HttpSession getSession(boolean create) {
if (crossContext) {
// There cannot be a session if no context has been assigned yet
if (context == null)
return (null);
// Return the current session if it exists and is valid
if (session != null && session.isValid()) {
return (session.getSession());
}
HttpSession other = super.getSession(false);
if (create && (other == null)) {
// First create a session in the first context: the problem is
// that the top level request is the only one which can
// create the cookie safely
other = super.getSession(true);
}
if (other != null) {
Session localSession = null;
try {
localSession =
context.getManager().findSession(other.getId());
if (localSession != null && !localSession.isValid()) {
localSession = null;
}
} catch (IOException e) {
// Ignore
}
if (localSession == null && create) {
localSession =
context.getManager().createSession(other.getId());
}
if (localSession != null) {
localSession.access();
session = localSession;
return session.getSession();
}
}
return null;
} else {
return super.getSession(create);
}
}
示例5: backsUpOnce_56698
import org.apache.catalina.Session; //导入方法依赖的package包/类
@Test
public void backsUpOnce_56698() throws IOException, LifecycleException,
InterruptedException {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.setDistributable(true);
Tomcat.addServlet(ctx, "DummyServlet", new DummyServlet());
ctx.addServletMapping("/dummy", "DummyServlet");
PersistentManager manager = new PersistentManager();
TesterStore store = new TesterStore();
manager.setStore(store);
manager.setMaxIdleBackup(0);
ctx.setManager(manager);
tomcat.start();
String sessionId = getUrl("http://localhost:" + getPort() + "/dummy")
.toString();
// Note: PersistenceManager.findSession() silently updates
// session.lastAccessedTime, so call it only once before other work.
Session session = manager.findSession(sessionId);
// Wait until request processing ends, as Request.recycle() updates
// session.lastAccessedTime via session.endAccess().
waitWhileSessionIsActive((StandardSession) session);
long lastAccessedTime = session.getLastAccessedTimeInternal();
// Session should be idle at least for 0 second (maxIdleBackup)
// to be eligible for persistence, thus no need to wait.
// Waiting a bit, to catch changes in last accessed time of a session
waitForClockUpdate();
manager.processPersistenceChecks();
Assert.assertEquals(Arrays.asList(sessionId), store.getSavedIds());
Assert.assertEquals(lastAccessedTime, session.getLastAccessedTimeInternal());
// session was not accessed, so no save will be performed
waitForClockUpdate();
manager.processPersistenceChecks();
Assert.assertEquals(Arrays.asList(sessionId), store.getSavedIds());
Assert.assertEquals(lastAccessedTime, session.getLastAccessedTimeInternal());
// access session
session.access();
session.endAccess();
// session was accessed, so it will be saved once again
manager.processPersistenceChecks();
Assert.assertEquals(Arrays.asList(sessionId, sessionId),
store.getSavedIds());
// session was not accessed, so once again no save will happen
manager.processPersistenceChecks();
Assert.assertEquals(Arrays.asList(sessionId, sessionId),
store.getSavedIds());
}
示例6: getSession
import org.apache.catalina.Session; //导入方法依赖的package包/类
/**
* Return the session associated with this Request, creating one
* if necessary and requested.
*
* @param create Create a new session if one does not exist
*/
public HttpSession getSession(boolean create) {
if (crossContext) {
// There cannot be a session if no context has been assigned yet
if (context == null)
return (null);
// Return the current session if it exists and is valid
if (session != null && session.isValid()) {
return (session.getSession());
}
HttpSession other = super.getSession(false);
if (create && (other == null)) {
// First create a session in the first context: the problem is
// that the top level request is the only one which can
// create the cookie safely
other = super.getSession(true);
}
if (other != null) {
Session localSession = null;
try {
localSession =
context.getManager().findSession(other.getId());
} catch (IOException e) {
// Ignore
}
if (localSession == null && create) {
localSession =
context.getManager().createSession(other.getId());
}
if (localSession != null) {
localSession.access();
session = localSession;
return session.getSession();
}
}
return null;
} else {
return super.getSession(create);
}
}
示例7: invoke
import org.apache.catalina.Session; //导入方法依赖的package包/类
/**
* Select the appropriate child Context to process this request,
* based on the specified request URI. If no matching Context can
* be found, return an appropriate HTTP error.
*
* @param request Request to be processed
* @param response Response to be produced
* @param valveContext Valve context used to forward to the next Valve
*
* @exception IOException if an input/output error occurred
* @exception ServletException if a servlet error occurred
*/
public void invoke(Request request, Response response,
ValveContext valveContext)
throws IOException, ServletException {
// Validate the request and response object types
if (!(request.getRequest() instanceof HttpServletRequest) ||
!(response.getResponse() instanceof HttpServletResponse)) {
return; // NOTE - Not much else we can do generically
}
// Select the Context to be used for this Request
StandardHost host = (StandardHost) getContainer();
Context context = (Context) host.map(request, true);
if (context == null) {
((HttpServletResponse) response.getResponse()).sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
sm.getString("standardHost.noContext"));
return;
}
// Bind the context CL to the current thread
Thread.currentThread().setContextClassLoader
(context.getLoader().getClassLoader());
// Update the session last access time for our session (if any)
HttpServletRequest hreq = (HttpServletRequest) request.getRequest();
String sessionId = hreq.getRequestedSessionId();
if (sessionId != null) {
Manager manager = context.getManager();
if (manager != null) {
Session session = manager.findSession(sessionId);
if ((session != null) && session.isValid())
session.access();
}
}
// Ask this Context to process this request
context.invoke(request, response);
}
示例8: getSession
import org.apache.catalina.Session; //导入方法依赖的package包/类
/**
* Return the session associated with this Request, creating one if
* necessary and requested.
*
* @param create
* Create a new session if one does not exist
*/
@Override
public HttpSession getSession(boolean create) {
if (crossContext) {
// There cannot be a session if no context has been assigned yet
if (context == null)
return (null);
// Return the current session if it exists and is valid
if (session != null && session.isValid()) {
return (session.getSession());
}
HttpSession other = super.getSession(false);
if (create && (other == null)) {
// First create a session in the first context: the problem is
// that the top level request is the only one which can
// create the cookie safely
other = super.getSession(true);
}
if (other != null) {
Session localSession = null;
try {
localSession = context.getManager().findSession(other.getId());
if (localSession != null && !localSession.isValid()) {
localSession = null;
}
} catch (IOException e) {
// Ignore
}
if (localSession == null && create) {
localSession = context.getManager().createSession(other.getId());
}
if (localSession != null) {
localSession.access();
session = localSession;
return session.getSession();
}
}
return null;
} else {
return super.getSession(create);
}
}