当前位置: 首页>>代码示例>>Java>>正文


Java StandardSession类代码示例

本文整理汇总了Java中org.apache.catalina.session.StandardSession的典型用法代码示例。如果您正苦于以下问题:Java StandardSession类的具体用法?Java StandardSession怎么用?Java StandardSession使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StandardSession类属于org.apache.catalina.session包,在下文中一共展示了StandardSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: serializeFrom

import org.apache.catalina.session.StandardSession; //导入依赖的package包/类
public static byte[] serializeFrom(HttpSession session) throws IOException, NoSuchFieldException, SecurityException,
    IllegalArgumentException, IllegalAccessException {
    if (session != null) {
        Field facadeSessionField = StandardSessionFacade.class.getDeclaredField("session");
        facadeSessionField.setAccessible(true);
        StandardSession standardSession = (StandardSession) facadeSessionField.get(session);

        if (standardSession != null) {
            // StandardSessionFacade standardSession =
            // (StandardSessionFacade) session;
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(bos));
            oos.writeLong(standardSession.getCreationTime());
            standardSession.writeObjectData(oos);

            oos.close();

            return bos.toByteArray();
        }
    }

    return null;
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:24,代码来源:JavaSerializer.java

示例2: deserializeInto

import org.apache.catalina.session.StandardSession; //导入依赖的package包/类
public static HttpSession deserializeInto(byte[] data, HttpSession session, ClassLoader loader)
    throws IOException, ClassNotFoundException, NoSuchFieldException, SecurityException,
    IllegalArgumentException, IllegalAccessException {
    if (data != null && data.length > 0 && session != null) {
        Field facadeSessionField = StandardSessionFacade.class.getDeclaredField("session");
        facadeSessionField.setAccessible(true);
        StandardSession standardSession = (StandardSession) facadeSessionField.get(session);

        // StandardSessionFacade standardSession = (StandardSessionFacade)
        // session;

        BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(data));

        ObjectInputStream ois = new CustomObjectInputStream(bis, loader);
        standardSession.setCreationTime(ois.readLong());
        standardSession.readObjectData(ois);
    }

    return session;
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:21,代码来源:JavaSerializer.java

示例3: serialize

import org.apache.catalina.session.StandardSession; //导入依赖的package包/类
/**
 * Serialize a {@link Session}
 *
 * @param session the {@link Session} to serialize
 * @return a {@code byte[]} representing the serialized {@link Session}
 * @throws IOException
 */
public byte[] serialize(Session session) throws IOException {
    ByteArrayOutputStream bytes = null;
    ObjectOutputStream out = null;

    try {
        bytes = new ByteArrayOutputStream();
        out = new ObjectOutputStream(bytes);

        StandardSession standardSession = (StandardSession) session;
        standardSession.writeObjectData(out);

        out.flush();
        bytes.flush();

        return bytes.toByteArray();
    } finally {
        closeQuietly(out, bytes);
    }

}
 
开发者ID:pivotalsoftware,项目名称:session-managers,代码行数:28,代码来源:SessionSerializationUtils.java

示例4: toSessionItem

import org.apache.catalina.session.StandardSession; //导入依赖的package包/类
@Override
public DynamoSessionItem toSessionItem(Session session) {
    ObjectOutputStream oos = null;
    try {
        ByteArrayOutputStream fos = new ByteArrayOutputStream();
        oos = new ObjectOutputStream(fos);
        ((StandardSession) session).writeObjectData(oos);
        oos.close();
        DynamoSessionItem sessionItem = new DynamoSessionItem(session.getIdInternal());
        sessionItem.setSessionData(ByteBuffer.wrap(fos.toByteArray()));
        return sessionItem;
    } catch (Exception e) {
        IOUtils.closeQuietly(oos, null);
        throw new SessionConversionException("Unable to convert Tomcat Session into Dynamo storage representation",
                e);
    }
}
 
开发者ID:amazon-archives,项目名称:aws-dynamodb-session-tomcat,代码行数:18,代码来源:DefaultDynamoSessionItemConverter.java

示例5: createStandardSession

import org.apache.catalina.session.StandardSession; //导入依赖的package包/类
public final StandardSession createStandardSession() {
    TestStandardSession session = new TestStandardSession(null);
    session.setValid(true);
    session.setId(getSessionId(), false);
    session.setCreationTime(getCreationTime());
    session.setMaxInactiveInterval(maxInactiveInterval);
    session.setLastAccessedTime(lastAccessedTime);

    Map<String, Object> sessionData = getSessionAttributes();
    if (sessionData != null) {
        for (Entry<String, Object> attr : sessionData.entrySet()) {
            session.setAttribute(attr.getKey(), attr.getValue(), false);
        }
    }
    session.setManager(getManager());
    return session;
}
 
开发者ID:amazon-archives,项目名称:aws-dynamodb-session-tomcat,代码行数:18,代码来源:TestSessionFactory.java

示例6: TesterRequest

import org.apache.catalina.session.StandardSession; //导入依赖的package包/类
public TesterRequest(boolean withSession) {
    context = new TesterContext();
    servletContext = new TesterServletContext();
    context.setServletContext(servletContext);
    if (withSession) {
        Set<SessionTrackingMode> modes = new HashSet<SessionTrackingMode>();
        modes.add(SessionTrackingMode.URL);
        modes.add(SessionTrackingMode.COOKIE);
        servletContext.setSessionTrackingModes(modes);
        session = new StandardSession(null);
        session.setId("1234", false);
        session.setValid(true);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:15,代码来源:TesterRequest.java

示例7: test

import org.apache.catalina.session.StandardSession; //导入依赖的package包/类
@Test
public void test() throws Exception {
	StandardContext context = new StandardContext();
	context.setName("foo");
	WebappLoader loader = new WebappLoader() {
		@Override
		public ClassLoader getClassLoader() {
			return WebappLoader.class.getClassLoader();
		}
	};
	context.setLoader(loader);
	StandardHost host = new StandardHost();
	StandardEngine engine = new StandardEngine();
	engine.setService(new StandardService());
	host.setParent(engine);
	context.setParent(host);
	loader.setContext(context);

	RedisSessionManager manager = new RedisSessionManager();
	manager.setSessionIdGenerator(new StandardSessionIdGenerator());
	manager.setContext(context);
	manager.initializeSerializer();
	manager.initializeDatabaseConnection();
	manager.clear();
	
	StandardSession session = manager.createSession(null);
	session.setAttribute("foo", "test");
	
	manager.afterRequest();
	
	StandardSession loaded = manager.findSession(session.getId());
	Assert.assertEquals(session.getAttribute("foo"), loaded.getAttribute("foo"));
	
	Assert.assertEquals(1, manager.getSize());
	Assert.assertArrayEquals(new String[] { session.getId() }, manager.keys());
	
	manager.processExpires();

}
 
开发者ID:appNG,项目名称:appng-tomcat-session,代码行数:40,代码来源:RedisSessionMangagerIT.java

示例8: test

import org.apache.catalina.session.StandardSession; //导入依赖的package包/类
@Test
public void test() throws Exception {
	MockServletContext ctx = new MockServletContext();
	StandardManager manager = new StandardManager();
	manager.setContext(new StandardContext());
	StandardSession session = new StandardSession(manager);
	session.setId("4711");
	session.setValid(true);
	session.setAttribute("foo", "bar");
	session.setAttribute("property", new SimpleProperty("foo", "bar"));
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	ObjectOutputStream oos = new ObjectOutputStream(baos);
	session.writeObjectData(oos);
	oos.flush();
	oos.close();
	ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
	ObjectInputStream ois = Utils.getObjectInputStream(contextClassLoader, ctx, baos.toByteArray());

	StandardSession newSession = new StandardSession(manager);
	newSession.readObjectData(ois);
	Assert.assertEquals(session.getId(), newSession.getId());
	Assert.assertEquals("4711", newSession.getId());
	Assert.assertEquals(session.getAttribute("foo"), newSession.getAttribute("foo"));
	Assert.assertEquals("bar", newSession.getAttribute("foo"));
	Assert.assertEquals(SimpleProperty.class, newSession.getAttribute("property").getClass());
	Assert.assertEquals("bar", ((Property) newSession.getAttribute("property")).getString());

}
 
开发者ID:appNG,项目名称:appng-tomcat-session,代码行数:29,代码来源:UtilsTest.java

示例9: getAttributesField

import org.apache.catalina.session.StandardSession; //导入依赖的package包/类
/**
 * "attributes" field type is changed to ConcurrentMap with Tomcat 8.0.35+ and this causes NoSuchFieldException
 * if accessed directly. "attributes" is accessed through reflection to support Tomcat 8.0.35+
 */
private static Field getAttributesField() {
    try {
        Field attributesField = StandardSession.class.getDeclaredField("attributes");
        attributesField.setAccessible(true);
        return attributesField;
    } catch (NoSuchFieldException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:hazelcast,项目名称:hazelcast-tomcat-sessionmanager,代码行数:14,代码来源:HazelcastSession.java

示例10: save

import org.apache.catalina.session.StandardSession; //导入依赖的package包/类
@Override
public void save(Session session) throws IOException {
	try{
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(bos));

		((StandardSession) session).writeObjectData(oos);
		oos.close();
		oos = null;
		byte[] obs = bos.toByteArray();
		redisCache.storeCacheObject(KEY_PREFIX_SESSION + session.getIdInternal(), obs);
	}catch(Exception e){

	}
}
 
开发者ID:baholladay,项目名称:WicketRedisSession,代码行数:16,代码来源:CatalinaRedisSessionStore.java

示例11: save

import org.apache.catalina.session.StandardSession; //导入依赖的package包/类
public void save(Session session) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(bos));

    ((StandardSession) session).writeObjectData(oos);
    oos.close();
    oos = null;

    byte[] obs = bos.toByteArray();
    int size = obs.length;

    GenericValue sessionValue = delegator.makeValue(entityName);
    sessionValue.setBytes("sessionInfo", obs);
    sessionValue.set("sessionId", session.getId());
    sessionValue.set("sessionSize", size);
    sessionValue.set("isValid", session.isValid() ? "Y" : "N");
    sessionValue.set("maxIdle", session.getMaxInactiveInterval());
    sessionValue.set("lastAccessed", session.getLastAccessedTime());

    try {
        delegator.createOrStore(sessionValue);
    } catch (GenericEntityException e) {
        throw new IOException(e.getMessage());
    }

    Debug.logInfo("Persisted session [" + session.getId() + "]", module);
}
 
开发者ID:gildaslemoal,项目名称:elpi,代码行数:28,代码来源:OfbizStore.java

示例12: load

import org.apache.catalina.session.StandardSession; //导入依赖的package包/类
@Test
public void load() throws IOException {
    Session session = new StandardSession(this.manager);
    session.setId("test-id");
    byte[] response = this.sessionSerializationUtils.serialize(session);

    when(this.jedisClient.get("test-id")).thenReturn(response);

    Session result = this.store.load("test-id");

    assertEquals(session.getId(), result.getId());
}
 
开发者ID:pivotalsoftware,项目名称:session-managers,代码行数:13,代码来源:RedisStoreTest.java

示例13: save

import org.apache.catalina.session.StandardSession; //导入依赖的package包/类
@Test
public void save() throws IOException {
    Session session = new StandardSession(this.manager);
    session.setId("test-id");

    this.store.save(session);

    verify(this.jedisClient).set(getRedisSessionId(session), SESSIONS_KEY, this.sessionSerializationUtils.serialize(session), session.getMaxInactiveInterval());
}
 
开发者ID:pivotalsoftware,项目名称:session-managers,代码行数:10,代码来源:RedisStoreTest.java

示例14: saveJedisConnectionException

import org.apache.catalina.session.StandardSession; //导入依赖的package包/类
@Test
public void saveJedisConnectionException() throws UnsupportedEncodingException {
    Session session = new StandardSession(this.manager);
    session.setId("test-id");

    doThrow(new JedisConnectionException("test-message"))
            .when(this.jedisClient)
            .set(anyString(), anyString(), any((byte[].class)), eq(session.getMaxInactiveInterval()));

    this.store.save(session);
}
 
开发者ID:pivotalsoftware,项目名称:session-managers,代码行数:12,代码来源:RedisStoreTest.java

示例15: deserialize

import org.apache.catalina.session.StandardSession; //导入依赖的package包/类
/**
 * Deserialize a {@link Session}
 *
 * @param session a {@code byte[]} representing the serialized {@link Session}
 * @return the deserialized {@link Session} or {@code null} if the session data is {@code null}
 * @throws ClassNotFoundException
 * @throws IOException
 */
public Session deserialize(byte[] session) throws ClassNotFoundException, IOException {
    if (session == null) {
        return null;
    }

    ByteArrayInputStream bytes = null;
    ObjectInputStream in = null;
    Context context = this.manager.getContext();
    ClassLoader oldThreadContextCL = context.bind(Globals.IS_SECURITY_ENABLED, null);

    try {
        bytes = new ByteArrayInputStream(session);
        in = new ObjectInputStream(bytes) {
            @Override
            protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
                try {
                    return Class.forName(desc.getName(), false, Thread.currentThread().getContextClassLoader());
                } catch (ClassNotFoundException cnfe) {
                    return super.resolveClass(desc);
                }
            }
        };

        StandardSession standardSession = (StandardSession) this.manager.createEmptySession();
        standardSession.readObjectData(in);

        return standardSession;
    } finally {
        closeQuietly(in, bytes);
        context.unbind(Globals.IS_SECURITY_ENABLED, oldThreadContextCL);
    }
}
 
开发者ID:pivotalsoftware,项目名称:session-managers,代码行数:41,代码来源:SessionSerializationUtils.java


注:本文中的org.apache.catalina.session.StandardSession类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。