本文整理汇总了Java中org.springframework.session.events.SessionCreatedEvent类的典型用法代码示例。如果您正苦于以下问题:Java SessionCreatedEvent类的具体用法?Java SessionCreatedEvent怎么用?Java SessionCreatedEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SessionCreatedEvent类属于org.springframework.session.events包,在下文中一共展示了SessionCreatedEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onApplicationEvent
import org.springframework.session.events.SessionCreatedEvent; //导入依赖的package包/类
public void onApplicationEvent(AbstractSessionEvent event) {
if (this.listeners.isEmpty()) {
return;
}
HttpSessionEvent httpSessionEvent = createHttpSessionEvent(event);
for (HttpSessionListener listener : this.listeners) {
if (event instanceof SessionDestroyedEvent) {
listener.sessionDestroyed(httpSessionEvent);
}
else if (event instanceof SessionCreatedEvent) {
listener.sessionCreated(httpSessionEvent);
}
}
}
示例2: expiredSessionTest
import org.springframework.session.events.SessionCreatedEvent; //导入依赖的package包/类
@Test
public void expiredSessionTest() throws InterruptedException {
S sessionToSave = repository.createSession();
repository.save(sessionToSave);
assertThat(registry.receivedEvent(sessionToSave.getId())).isTrue();
assertThat((EventObject) registry.getEvent(sessionToSave.getId()))
.isInstanceOf(SessionCreatedEvent.class);
registry.clear();
assertThat(sessionToSave.getMaxInactiveIntervalInSeconds())
.isEqualTo(MAX_INACTIVE_INTERVAL_IN_SECONDS);
assertThat(registry.receivedEvent(sessionToSave.getId())).isTrue();
assertThat((EventObject) registry.getEvent(sessionToSave.getId()))
.isInstanceOf(SessionExpiredEvent.class);
assertThat(repository.getSession(sessionToSave.getId())).isNull();
}
开发者ID:kazuhira-r,项目名称:spring-session-infinispan,代码行数:22,代码来源:AbstractEnableInfinispanHttpSessionEventsITests.java
示例3: deletedSessionTest
import org.springframework.session.events.SessionCreatedEvent; //导入依赖的package包/类
@Test
public void deletedSessionTest() throws InterruptedException {
S sessionToSave = repository.createSession();
repository.save(sessionToSave);
assertThat(registry.receivedEvent(sessionToSave.getId())).isTrue();
assertThat((EventObject) registry.getEvent(sessionToSave.getId()))
.isInstanceOf(SessionCreatedEvent.class);
registry.clear();
repository.delete(sessionToSave.getId());
assertThat(registry.receivedEvent(sessionToSave.getId())).isTrue();
assertThat((EventObject) registry.getEvent(sessionToSave.getId()))
.isInstanceOf(SessionDeletedEvent.class);
assertThat(repository.getSession(sessionToSave.getId())).isNull();
}
开发者ID:kazuhira-r,项目名称:spring-session-infinispan,代码行数:21,代码来源:AbstractEnableInfinispanHttpSessionEventsITests.java
示例4: onApplicationEvent
import org.springframework.session.events.SessionCreatedEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(AbstractSessionEvent event) {
if (this.listeners.isEmpty()) {
return;
}
HttpSessionEvent httpSessionEvent = createHttpSessionEvent(event);
for (HttpSessionListener listener : this.listeners) {
if (event instanceof SessionDestroyedEvent) {
listener.sessionDestroyed(httpSessionEvent);
}
else if (event instanceof SessionCreatedEvent) {
listener.sessionCreated(httpSessionEvent);
}
}
}
示例5: expiredSessionTest
import org.springframework.session.events.SessionCreatedEvent; //导入依赖的package包/类
@Test
public void expiredSessionTest() throws InterruptedException {
S sessionToSave = this.repository.createSession();
this.repository.save(sessionToSave);
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
assertThat(this.registry.<SessionCreatedEvent>getEvent(sessionToSave.getId()))
.isInstanceOf(SessionCreatedEvent.class);
this.registry.clear();
assertThat(sessionToSave.getMaxInactiveInterval())
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
assertThat(this.registry.<SessionExpiredEvent>getEvent(sessionToSave.getId()))
.isInstanceOf(SessionExpiredEvent.class);
assertThat(this.repository.<Session>findById(sessionToSave.getId())).isNull();
}
示例6: deletedSessionTest
import org.springframework.session.events.SessionCreatedEvent; //导入依赖的package包/类
@Test
public void deletedSessionTest() throws InterruptedException {
S sessionToSave = this.repository.createSession();
this.repository.save(sessionToSave);
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
assertThat(this.registry.<SessionCreatedEvent>getEvent(sessionToSave.getId()))
.isInstanceOf(SessionCreatedEvent.class);
this.registry.clear();
this.repository.deleteById(sessionToSave.getId());
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
assertThat(this.registry.<SessionDeletedEvent>getEvent(sessionToSave.getId()))
.isInstanceOf(SessionDeletedEvent.class);
assertThat(this.repository.findById(sessionToSave.getId())).isNull();
}
示例7: onApplicationEvent
import org.springframework.session.events.SessionCreatedEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(AbstractSessionEvent event) {
if (event instanceof SessionCreatedEvent) {
sessionCreatedEvents++;
}
if (event instanceof SessionDeletedEvent) {
sessionDeletedEvents++;
}
if (event instanceof SessionExpiredEvent) {
sessionExpiredEvents++;
}
}
示例8: entryCreated
import org.springframework.session.events.SessionCreatedEvent; //导入依赖的package包/类
@ClientCacheEntryCreated
public void entryCreated(ClientCacheEntryCreatedEvent<String> event) {
if (logger.isDebugEnabled()) {
logger.debug("Session created with id: " + event.getKey());
}
eventPublisher.publishEvent(new SessionCreatedEvent(this, event.getKey()));
}
示例9: saveSessionTest
import org.springframework.session.events.SessionCreatedEvent; //导入依赖的package包/类
@Test
public void saveSessionTest() throws InterruptedException {
String username = "saves-" + System.currentTimeMillis();
S sessionToSave = repository.createSession();
String expectedAttributeName = "a";
String expectedAttributeValue = "b";
sessionToSave.setAttribute(expectedAttributeName, expectedAttributeValue);
Authentication toSaveToken = new UsernamePasswordAuthenticationToken(username,
"password", AuthorityUtils.createAuthorityList("ROLE_USER"));
SecurityContext toSaveContext = SecurityContextHolder.createEmptyContext();
toSaveContext.setAuthentication(toSaveToken);
sessionToSave.setAttribute("SPRING_SECURITY_CONTEXT", toSaveContext);
sessionToSave.setAttribute(
FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, username);
repository.save(sessionToSave);
assertThat(registry.receivedEvent(sessionToSave.getId())).isTrue();
assertThat((EventObject) registry.getEvent(sessionToSave.getId()))
.isInstanceOf(SessionCreatedEvent.class);
Session session = repository.getSession(sessionToSave.getId());
assertThat(session.getId()).isEqualTo(sessionToSave.getId());
assertThat(session.getAttributeNames())
.isEqualTo(sessionToSave.getAttributeNames());
assertThat((String) session.getAttribute(expectedAttributeName))
.isEqualTo(sessionToSave.getAttribute(expectedAttributeName));
}
开发者ID:kazuhira-r,项目名称:spring-session-infinispan,代码行数:32,代码来源:AbstractEnableInfinispanHttpSessionEventsITests.java
示例10: createSession
import org.springframework.session.events.SessionCreatedEvent; //导入依赖的package包/类
@Override
public ExpiringSession createSession()
{
final ExpiringSession result = new MapSession();
if (defaultMaxInactiveInterval != null)
{
result.setMaxInactiveIntervalInSeconds(defaultMaxInactiveInterval);
}
// Fire event
applicationEventPublisher.publishEvent(new SessionCreatedEvent(this, result.getId()));
return result;
}
示例11: createSession
import org.springframework.session.events.SessionCreatedEvent; //导入依赖的package包/类
@Override
public CouchbaseSession createSession() {
CouchbaseSession session = new CouchbaseSession(sessionTimeout);
Map<String, Map<String, Object>> sessionData = new HashMap<>(2);
sessionData.put(GLOBAL_NAMESPACE, session.getGlobalAttributes());
sessionData.put(namespace, session.getNamespaceAttributes());
SessionDocument sessionDocument = new SessionDocument(session.getId(), sessionData);
dao.save(sessionDocument);
dao.updateExpirationTime(session.getId(), getSessionDocumentExpiration());
eventPublisher.publishEvent(new SessionCreatedEvent(this, session));
log.debug("HTTP session with ID {} has been created", session.getId());
return session;
}
开发者ID:mkopylec,项目名称:session-couchbase-spring-boot-starter,代码行数:16,代码来源:CouchbaseSessionRepository.java
示例12: setup
import org.springframework.session.events.SessionCreatedEvent; //导入依赖的package包/类
@Before
public void setup() {
this.listener = new SessionEventHttpSessionListenerAdapter(
Arrays.asList(this.listener1, this.listener2));
this.listener.setServletContext(new MockServletContext());
Session session = new MapSession();
this.destroyed = new SessionDestroyedEvent(this, session);
this.created = new SessionCreatedEvent(this, session);
}
开发者ID:spring-projects,项目名称:spring-session,代码行数:11,代码来源:SessionEventHttpSessionListenerAdapterTests.java
示例13: entryAdded
import org.springframework.session.events.SessionCreatedEvent; //导入依赖的package包/类
@Override
public void entryAdded(EntryEvent<String, MapSession> event) {
if (logger.isDebugEnabled()) {
logger.debug("Session created with id: " + event.getValue().getId());
}
this.eventPublisher.publishEvent(new SessionCreatedEvent(this, event.getValue()));
}
示例14: saveSessionTest
import org.springframework.session.events.SessionCreatedEvent; //导入依赖的package包/类
@Test
public void saveSessionTest() throws InterruptedException {
String username = "saves-" + System.currentTimeMillis();
S sessionToSave = this.repository.createSession();
String expectedAttributeName = "a";
String expectedAttributeValue = "b";
sessionToSave.setAttribute(expectedAttributeName, expectedAttributeValue);
Authentication toSaveToken = new UsernamePasswordAuthenticationToken(username,
"password", AuthorityUtils.createAuthorityList("ROLE_USER"));
SecurityContext toSaveContext = SecurityContextHolder.createEmptyContext();
toSaveContext.setAuthentication(toSaveToken);
sessionToSave.setAttribute("SPRING_SECURITY_CONTEXT", toSaveContext);
sessionToSave.setAttribute(
FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, username);
this.repository.save(sessionToSave);
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
assertThat(this.registry.<SessionCreatedEvent>getEvent(sessionToSave.getId()))
.isInstanceOf(SessionCreatedEvent.class);
Session session = this.repository.findById(sessionToSave.getId());
assertThat(session.getId()).isEqualTo(sessionToSave.getId());
assertThat(session.getAttributeNames())
.isEqualTo(sessionToSave.getAttributeNames());
assertThat(session.<String>getAttribute(expectedAttributeName))
.isEqualTo(sessionToSave.getAttribute(expectedAttributeName));
}
示例15: entryCreated
import org.springframework.session.events.SessionCreatedEvent; //导入依赖的package包/类
@CacheEntryCreated
public void entryCreated(CacheEntryCreatedEvent<String, ExpiringSession> event) {
if (logger.isDebugEnabled()) {
logger.debug("Session created with id: " + event.getValue().getId());
}
eventPublisher.publishEvent(new SessionCreatedEvent(this, event.getValue()));
}