Search in sources :

Example 6 with MapSessionRepository

use of org.springframework.session.MapSessionRepository in project spring-session by spring-projects.

the class SessionRepositoryFilterTests method doFilterLazySessionCreation.

@Test
public void doFilterLazySessionCreation() throws Exception {
    SessionRepository<MapSession> sessionRepository = spy(new MapSessionRepository(new ConcurrentHashMap<>()));
    this.filter = new SessionRepositoryFilter<>(sessionRepository);
    doFilter(new DoInFilter() {

        @Override
        public void doFilter(HttpServletRequest wrappedRequest, HttpServletResponse wrappedResponse) throws IOException {
        }
    });
    verifyZeroInteractions(sessionRepository);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MapSessionRepository(org.springframework.session.MapSessionRepository) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) MapSession(org.springframework.session.MapSession) IOException(java.io.IOException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 7 with MapSessionRepository

use of org.springframework.session.MapSessionRepository in project spring-boot by spring-projects.

the class SessionAutoConfigurationTests method hashMapSessionStoreCustomTimeout.

@Test
public void hashMapSessionStoreCustomTimeout() {
    load("spring.session.store-type=hash-map", "server.session.timeout=3000");
    MapSessionRepository repository = validateSessionRepository(MapSessionRepository.class);
    assertThat(getSessionTimeout(repository)).isEqualTo(3000);
}
Also used : MapSessionRepository(org.springframework.session.MapSessionRepository) Test(org.junit.Test)

Example 8 with MapSessionRepository

use of org.springframework.session.MapSessionRepository in project spring-session by spring-projects.

the class IndexDocTests method repositoryDemo.

@Test
public void repositoryDemo() {
    RepositoryDemo<MapSession> demo = new RepositoryDemo<>();
    demo.repository = new MapSessionRepository(new ConcurrentHashMap<>());
    demo.demo();
}
Also used : MapSessionRepository(org.springframework.session.MapSessionRepository) MapSession(org.springframework.session.MapSession) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 9 with MapSessionRepository

use of org.springframework.session.MapSessionRepository in project spring-session by spring-projects.

the class IndexDocTests method expireRepositoryDemo.

// end::repository-demo[]
@Test
public void expireRepositoryDemo() {
    ExpiringRepositoryDemo<MapSession> demo = new ExpiringRepositoryDemo<>();
    demo.repository = new MapSessionRepository(new ConcurrentHashMap<>());
    demo.demo();
}
Also used : MapSessionRepository(org.springframework.session.MapSessionRepository) MapSession(org.springframework.session.MapSession) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 10 with MapSessionRepository

use of org.springframework.session.MapSessionRepository in project spring-session by spring-projects.

the class Initializer method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent sce) {
    this.instance = createHazelcastInstance();
    Map<String, Session> sessions = this.instance.getMap(SESSION_MAP_NAME);
    MapSessionRepository sessionRepository = new MapSessionRepository(sessions);
    SessionRepositoryFilter<? extends Session> filter = new SessionRepositoryFilter<>(sessionRepository);
    Dynamic fr = sce.getServletContext().addFilter("springSessionFilter", filter);
    fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
}
Also used : Dynamic(javax.servlet.FilterRegistration.Dynamic) MapSessionRepository(org.springframework.session.MapSessionRepository) Session(org.springframework.session.Session) MapSession(org.springframework.session.MapSession) SessionRepositoryFilter(org.springframework.session.web.http.SessionRepositoryFilter)

Aggregations

MapSessionRepository (org.springframework.session.MapSessionRepository)13 Test (org.junit.Test)10 MapSession (org.springframework.session.MapSession)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 IOException (java.io.IOException)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Dynamic (javax.servlet.FilterRegistration.Dynamic)1 Before (org.junit.Before)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1 Session (org.springframework.session.Session)1 SessionRepositoryFilter (org.springframework.session.web.http.SessionRepositoryFilter)1