From 7f3302253bf828a7e7d75913eca97c8e32dda13f Mon Sep 17 00:00:00 2001
From: Vedran Pavic
Date: Sat, 5 Mar 2016 20:27:06 +0100
Subject: [PATCH] Prepare codebase to adhere to Checkstyle rules
Issue gh-393
---
.../docs/AbstractGemFireIntegrationTests.java | 42 +-
.../HttpSessionGemFireIndexingITests.java | 13 +-
.../GemFireHttpSessionConfig.java | 7 +-
...ttpSessionGemFireIndexingCustomITests.java | 13 +-
...FindByIndexNameSessionRepositoryTests.java | 10 +-
...ationNoOpConfigureRedisActionXmlTests.java | 12 +-
docs/src/test/java/docs/IndexDocTests.java | 44 +-
...gurationNoOpConfigureRedisActionTests.java | 11 +-
.../java/docs/SpringHttpSessionConfig.java | 5 +-
.../AbstractHttpSessionListenerTests.java | 20 +-
.../docs/http/HazelcastHttpSessionConfig.java | 13 +-
.../HttpSessionListenerJavaConfigTests.java | 3 +-
.../http/HttpSessionListenerXmlTests.java | 3 +-
.../docs/http/RedisHttpSessionConfig.java | 5 +-
.../java/docs/websocket/WebSocketConfig.java | 21 +-
.../groovy/sample/BootTests.groovy | 5 +-
.../groovy/sample/pages/HomePage.groovy | 3 +-
.../groovy/sample/pages/LoginPage.groovy | 3 +-
.../src/main/java/sample/Application.java | 19 +-
.../java/sample/config/HttpSessionConfig.java | 5 +-
.../java/sample/config/SecurityConfig.java | 19 +-
.../main/java/sample/mvc/IndexController.java | 19 +-
.../groovy/sample/AttributeTests.groovy | 5 +-
.../groovy/sample/pages/HomePage.groovy | 3 +-
.../src/main/java/sample/Config.java | 5 +-
.../src/main/java/sample/Initializer.java | 5 +-
.../src/main/java/sample/SessionServlet.java | 14 +-
.../groovy/sample/FindByUsernameTests.groovy | 5 +-
.../groovy/sample/MultiBrowserGebSpec.groovy | 7 +-
.../groovy/sample/pages/HomePage.groovy | 3 +-
.../groovy/sample/pages/LoginPage.groovy | 3 +-
.../sample/FindByUsernameApplication.java | 19 +-
.../main/java/sample/config/GeoConfig.java | 7 +-
.../java/sample/config/HttpSessionConfig.java | 5 +-
.../java/sample/config/SecurityConfig.java | 19 +-
.../main/java/sample/mvc/IndexController.java | 29 +-
.../main/java/sample/mvc/LoginController.java | 3 +-
.../java/sample/session/SessionDetails.java | 7 +-
.../sample/session/SessionDetailsFilter.java | 25 +-
.../session/SessionDetailsFilterTests.java | 23 +-
.../groovy/sample/HazelcastSpringTests.groovy | 5 +-
.../groovy/sample/pages/HomePage.groovy | 3 +-
.../groovy/sample/pages/LoginPage.groovy | 3 +-
.../src/main/java/sample/Config.java | 15 +-
.../src/main/java/sample/Initializer.java | 5 +-
.../java/sample/ObjectStreamSerializer.java | 16 +-
.../src/main/java/sample/SecurityConfig.java | 19 +-
.../main/java/sample/SecurityInitializer.java | 5 +-
.../src/main/java/sample/SessionServlet.java | 6 +-
.../groovy/sample/AttributeTests.groovy | 5 +-
.../groovy/sample/pages/HomePage.groovy | 3 +-
.../src/main/java/sample/Initializer.java | 53 +-
.../java/sample/ObjectStreamSerializer.java | 16 +-
.../src/main/java/sample/SessionServlet.java | 6 +-
.../groovy/sample/AttributeTests.groovy | 5 +-
.../groovy/sample/pages/HomePage.groovy | 3 +-
.../src/main/java/sample/Application.java | 5 +-
...FireCacheServerReadyBeanPostProcessor.java | 24 +-
.../src/main/java/sample/SessionServlet.java | 6 +-
.../groovy/sample/AttributeTests.groovy | 5 +-
.../groovy/sample/pages/HomePage.groovy | 3 +-
.../src/main/java/sample/ClientConfig.java | 25 +-
.../src/main/java/sample/Initializer.java | 5 +-
.../src/main/java/sample/ServerConfig.java | 11 +-
.../src/main/java/sample/SessionServlet.java | 4 +-
.../groovy/sample/AttributeTests.groovy | 5 +-
.../groovy/sample/pages/HomePage.groovy | 3 +-
.../src/main/java/sample/SessionServlet.java | 6 +-
.../groovy/sample/AttributeTests.groovy | 5 +-
.../groovy/sample/pages/HomePage.groovy | 3 +-
.../src/main/java/sample/Config.java | 3 +-
.../src/main/java/sample/Initializer.java | 5 +-
.../src/main/java/sample/SessionServlet.java | 4 +-
.../groovy/sample/AttributeTests.groovy | 5 +-
.../groovy/sample/pages/HomePage.groovy | 3 +-
.../src/main/java/sample/SessionServlet.java | 12 +-
.../groovy/sample/AttributeTests.groovy | 5 +-
.../groovy/sample/pages/HomePage.groovy | 3 +-
.../src/main/java/sample/Config.java | 5 +-
.../src/main/java/sample/Initializer.java | 5 +-
.../src/main/java/sample/SessionServlet.java | 14 +-
.../groovy/sample/RestTests.groovy | 7 +-
.../java/rest/RestMockMvcTests.java | 36 +-
.../main/java/sample/HttpSessionConfig.java | 5 +-
.../src/main/java/sample/Initializer.java | 5 +-
.../src/main/java/sample/SecurityConfig.java | 19 +-
.../main/java/sample/SecurityInitializer.java | 21 +-
.../src/main/java/sample/mvc/MvcConfig.java | 19 +-
.../main/java/sample/mvc/MvcInitializer.java | 22 +-
.../java/sample/mvc/RestDemoController.java | 25 +-
.../groovy/sample/SecurityTests.groovy | 5 +-
.../groovy/sample/pages/HomePage.groovy | 3 +-
.../groovy/sample/pages/LoginPage.groovy | 3 +-
.../security/src/main/java/sample/Config.java | 5 +-
.../src/main/java/sample/Initializer.java | 5 +-
.../src/main/java/sample/SecurityConfig.java | 19 +-
.../main/java/sample/SecurityInitializer.java | 5 +-
.../src/main/java/sample/SessionServlet.java | 6 +-
.../groovy/sample/UserTests.groovy | 5 +-
.../groovy/sample/pages/HomePage.groovy | 3 +-
.../groovy/sample/pages/LinkPage.groovy | 3 +-
.../users/src/main/java/sample/Account.java | 9 +-
.../users/src/main/java/sample/Config.java | 21 +-
.../src/main/java/sample/Initializer.java | 21 +-
.../src/main/java/sample/LoginServlet.java | 10 +-
.../src/main/java/sample/LogoutServlet.java | 7 +-
.../main/java/sample/UserAccountsFilter.java | 14 +-
.../src/main/java/sample/Application.java | 19 +-
.../java/sample/config/DataSourceConfig.java | 3 +-
.../java/sample/config/H2Initializer.java | 4 +-
.../java/sample/config/WebSecurityConfig.java | 5 +-
.../java/sample/config/WebSocketConfig.java | 23 +-
.../config/WebSocketHandlersConfig.java | 27 +-
.../config/WebSocketSecurityConfig.java | 25 +-
.../java/sample/data/ActiveWebSocketUser.java | 10 +-
.../data/ActiveWebSocketUserRepository.java | 5 +-
.../main/java/sample/data/InstantMessage.java | 11 +-
.../src/main/java/sample/data/User.java | 21 +-
.../main/java/sample/data/UserRepository.java | 19 +-
.../main/java/sample/mvc/CsrfController.java | 16 +
.../java/sample/mvc/MessageController.java | 37 +-
.../java/sample/security/CurrentUser.java | 3 +-
.../UserRepositoryUserDetailsService.java | 12 +-
.../websocket/WebSocketConnectHandler.java | 17 +-
.../websocket/WebSocketDisconnectHandler.java | 21 +-
.../session/data/SessionEventRegistry.java | 21 +-
.../AbstractGemFireIntegrationTests.java | 40 +-
...ionsSessionRepositoryIntegrationTests.java | 55 +-
...ionsSessionRepositoryIntegrationTests.java | 82 +--
...FireHttpSessionEventsIntegrationTests.java | 66 +-
...FireHttpSessionJavaConfigurationTests.java | 30 +-
...mFireHttpSessionXmlConfigurationTests.java | 28 +-
...ttpSessionExpireSessionDestroyedTests.java | 57 +-
.../RedisHttpSessionConfig.java | 5 +-
...ssionRepositoryFlushImmediatelyITests.java | 16 +-
...isListenerContainerTaskExecutorITests.java | 48 +-
.../AbstractHazelcastRepositoryITests.java | 17 +-
.../HazelcastClientRepositoryITests.java | 11 +-
.../hazelcast/HazelcastITestUtils.java | 7 +-
.../HazelcastServerRepositoryITests.java | 2 +-
...EnableHazelcastHttpSessionEventsTests.java | 69 +-
...lcastHttpSessionConfigurationXmlTests.java | 31 +-
.../session/ExpiringSession.java | 9 +-
.../FindByIndexNameSessionRepository.java | 8 +-
.../springframework/session/MapSession.java | 60 +-
.../session/MapSessionRepository.java | 47 +-
.../org/springframework/session/Session.java | 25 +-
.../session/SessionRepository.java | 22 +-
.../web/http/EnableSpringHttpSession.java | 7 +-
.../http/SpringHttpSessionConfiguration.java | 20 +-
...actGemFireOperationsSessionRepository.java | 136 ++--
.../GemFireOperationsSessionRepository.java | 10 +-
.../web/http/EnableGemFireHttpSession.java | 10 +-
.../http/GemFireHttpSessionConfiguration.java | 60 +-
...emFireCacheTypeAwareRegionFactoryBean.java | 40 +-
.../data/gemfire/support/GemFireUtils.java | 4 +-
.../session/data/redis/RedisFlushMode.java | 3 +-
.../RedisOperationsSessionRepository.java | 202 ++---
.../redis/RedisSessionExpirationPolicy.java | 47 +-
.../data/redis/SessionMessageListener.java | 19 +-
.../ConfigureNotifyKeyspaceEventsAction.java | 16 +-
.../redis/config/ConfigureRedisAction.java | 3 +-
.../web/http/EnableRedisHttpSession.java | 9 +-
.../http/RedisHttpSessionConfiguration.java | 78 +-
.../session/events/AbstractSessionEvent.java | 9 +-
.../session/events/SessionCreatedEvent.java | 6 +-
.../session/events/SessionDeletedEvent.java | 5 +-
.../session/events/SessionDestroyedEvent.java | 6 +-
.../session/events/SessionExpiredEvent.java | 5 +-
.../hazelcast/SessionEntryListener.java | 19 +-
.../web/http/EnableHazelcastHttpSession.java | 7 +-
.../HazelcastHttpSessionConfiguration.java | 52 +-
...ractHttpSessionApplicationInitializer.java | 36 +-
.../web/http/CookieHttpSessionStrategy.java | 145 ++--
.../session/web/http/CookieSerializer.java | 15 +-
.../web/http/DefaultCookieSerializer.java | 49 +-
.../web/http/ExpiringSessionHttpSession.java | 34 +-
.../web/http/HeaderHttpSessionStrategy.java | 35 +-
.../session/web/http/HttpSessionManager.java | 5 +-
.../session/web/http/HttpSessionStrategy.java | 25 +-
.../web/http/MultiHttpSessionStrategy.java | 8 +-
.../web/http/OnCommittedResponseWrapper.java | 197 ++---
.../web/http/OncePerRequestFilter.java | 48 +-
.../http/RequestResponsePostProcessor.java | 3 +-
...essionEventHttpSessionListenerAdapter.java | 14 +-
.../web/http/SessionRepositoryFilter.java | 147 ++--
...ssionWebSocketMessageBrokerConfigurer.java | 25 +-
.../socket/events/SessionConnectEvent.java | 7 +-
...bSocketConnectHandlerDecoratorFactory.java | 12 +-
.../handler/WebSocketRegistryListener.java | 55 +-
.../SessionRepositoryMessageInterceptor.java | 18 +-
.../session/MapSessionRepositoryTests.java | 27 +-
.../session/MapSessionTests.java | 35 +-
...ttpSessionCustomCookieSerializerTests.java | 28 +-
...onCustomMultiHttpSessionStrategyTests.java | 26 +-
...emFireOperationsSessionRepositoryTest.java | 695 ++++++++++--------
...emFireOperationsSessionRepositoryTest.java | 223 +++---
.../GemFireHttpSessionConfigurationTest.java | 186 ++---
...reCacheTypeAwareRegionFactoryBeanTest.java | 158 ++--
.../gemfire/support/GemFireUtilsTest.java | 23 +-
...RedisOperationsSessionRepositoryTests.java | 421 ++++++-----
.../RedisSessionExpirationPolicyTests.java | 71 +-
.../redis/SessionMessageListenerTests.java | 79 +-
...KeyspaceNotificationsInitializerTests.java | 63 +-
...onClassPathXmlApplicationContextTests.java | 17 +-
...gurationNoOpConfigureRedisActionTests.java | 11 +-
...urationOverrideDefaultSerializerTests.java | 17 +-
...figurationOverrideSessionTaskExecutor.java | 20 +-
...igurationOverrideSessionTaskExecutors.java | 16 +-
...sionConfigurationXmlCustomExpireTests.java | 17 +-
...RedisHttpSessionConfigurationXmlTests.java | 17 +-
.../annotation/web/http/gh109/Gh109Tests.java | 13 +-
.../http/CookieHttpSessionStrategyTests.java | 213 +++---
.../http/DefaultCookieSerializerTests.java | 194 ++---
.../web/http/HeaderSessionStrategyTests.java | 63 +-
.../http/OnCommittedResponseWrapperTests.java | 575 +++++++--------
.../web/http/OncePerRequestFilterTests.java | 54 +-
...nEventHttpSessionListenerAdapterTests.java | 42 +-
.../http/SessionRepositoryFilterTests.java | 250 ++++---
...etConnectHandlerDecoratorFactoryTests.java | 30 +-
.../WebSocketRegistryListenerTests.java | 110 +--
...sionRepositoryMessageInterceptorTests.java | 121 +--
222 files changed, 4071 insertions(+), 3556 deletions(-)
diff --git a/docs/src/integration-test/java/docs/AbstractGemFireIntegrationTests.java b/docs/src/integration-test/java/docs/AbstractGemFireIntegrationTests.java
index 8bcf2425..a35d3cc2 100644
--- a/docs/src/integration-test/java/docs/AbstractGemFireIntegrationTests.java
+++ b/docs/src/integration-test/java/docs/AbstractGemFireIntegrationTests.java
@@ -1,11 +1,11 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* 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
+ * 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,
@@ -16,8 +16,6 @@
package docs;
-import static org.assertj.core.api.Assertions.assertThat;
-
import java.io.File;
import java.io.IOException;
import java.net.Socket;
@@ -27,14 +25,6 @@ import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
-import org.junit.Before;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.ApplicationListener;
-import org.springframework.session.ExpiringSession;
-import org.springframework.session.data.gemfire.GemFireOperationsSessionRepository;
-import org.springframework.session.data.gemfire.support.GemFireUtils;
-import org.springframework.session.events.AbstractSessionEvent;
-
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheClosedException;
import com.gemstone.gemfire.cache.DataPolicy;
@@ -46,12 +36,23 @@ import com.gemstone.gemfire.cache.client.ClientCache;
import com.gemstone.gemfire.cache.client.ClientCacheFactory;
import com.gemstone.gemfire.cache.query.Index;
import com.gemstone.gemfire.cache.server.CacheServer;
+import org.junit.Before;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationListener;
+import org.springframework.session.ExpiringSession;
+import org.springframework.session.data.gemfire.GemFireOperationsSessionRepository;
+import org.springframework.session.data.gemfire.support.GemFireUtils;
+import org.springframework.session.events.AbstractSessionEvent;
+
+import static org.assertj.core.api.Assertions.assertThat;
/**
* AbstractGemFireIntegrationTests is an abstract base class encapsulating common operations for writing
* Spring Session GemFire integration tests.
*
* @author John Blum
+ * @since 1.1.0
* @see org.springframework.session.ExpiringSession
* @see org.springframework.session.events.AbstractSessionEvent
* @see com.gemstone.gemfire.cache.Cache
@@ -61,7 +62,6 @@ import com.gemstone.gemfire.cache.server.CacheServer;
* @see com.gemstone.gemfire.cache.Region
* @see com.gemstone.gemfire.cache.client.ClientCache
* @see com.gemstone.gemfire.cache.server.CacheServer
- * @since 1.1.0
*/
public class AbstractGemFireIntegrationTests {
public static final String GEMFIRE_LOG_LEVEL = System.getProperty(
@@ -73,7 +73,7 @@ public class AbstractGemFireIntegrationTests {
protected static final int DEFAULT_GEMFIRE_SERVER_PORT = CacheServer.DEFAULT_PORT;
protected static final long DEFAULT_WAIT_DURATION = TimeUnit.SECONDS.toMillis(20);
- protected static final long DEFAULT_WAIT_INTERVAL = 500l;
+ protected static final long DEFAULT_WAIT_INTERVAL = 500L;
protected static final File WORKING_DIRECTORY = new File(System.getProperty("user.dir"));
@@ -356,7 +356,7 @@ public class AbstractGemFireIntegrationTests {
List regionList = new ArrayList(regions.size());
- for (Region,?> region : regions) {
+ for (Region, ?> region : regions) {
regionList.add(region.getFullPath());
}
@@ -366,7 +366,7 @@ public class AbstractGemFireIntegrationTests {
/* (non-Javadoc) */
@SuppressWarnings("unchecked")
protected T createSession() {
- T expiringSession = (T) sessionRepository.createSession();
+ T expiringSession = (T) this.sessionRepository.createSession();
assertThat(expiringSession).isNotNull();
return expiringSession;
}
@@ -381,19 +381,19 @@ public class AbstractGemFireIntegrationTests {
/* (non-Javadoc) */
protected T expire(T session) {
- session.setLastAccessedTime(0l);
+ session.setLastAccessedTime(0L);
return session;
}
/* (non-Javadoc) */
@SuppressWarnings("unchecked")
protected T get(String sessionId) {
- return (T) sessionRepository.getSession(sessionId);
+ return (T) this.sessionRepository.getSession(sessionId);
}
/* (non-Javadoc) */
protected T save(T session) {
- sessionRepository.save(session);
+ this.sessionRepository.save(session);
return session;
}
@@ -424,14 +424,14 @@ public class AbstractGemFireIntegrationTests {
/* (non-Javadoc) */
public void onApplicationEvent(AbstractSessionEvent event) {
- sessionEvent = event;
+ this.sessionEvent = event;
}
/* (non-Javadoc) */
public T waitForSessionEvent(long duration) {
waitOnCondition(new Condition() {
public boolean evaluate() {
- return (sessionEvent != null);
+ return (SessionEventListener.this.sessionEvent != null);
}
}, duration);
diff --git a/docs/src/integration-test/java/docs/http/HttpSessionGemFireIndexingITests.java b/docs/src/integration-test/java/docs/http/HttpSessionGemFireIndexingITests.java
index e893774d..5aab06fa 100644
--- a/docs/src/integration-test/java/docs/http/HttpSessionGemFireIndexingITests.java
+++ b/docs/src/integration-test/java/docs/http/HttpSessionGemFireIndexingITests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,15 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package docs.http;
-import static org.assertj.core.api.Assertions.assertThat;
+package docs.http;
import java.util.Map;
import java.util.Properties;
+import docs.AbstractGemFireIntegrationTests;
import org.junit.Test;
import org.junit.runner.RunWith;
+
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.gemfire.CacheFactoryBean;
@@ -36,7 +37,7 @@ import org.springframework.session.data.gemfire.config.annotation.web.http.Enabl
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import docs.AbstractGemFireIntegrationTests;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rob Winch
@@ -59,7 +60,7 @@ public class HttpSessionGemFireIndexingITests extends AbstractGemFireIntegration
sessionRepository.save(session);
// tag::findbyindexname-get[]
- Map idToSessions = sessionRepository.findByIndexNameAndIndexValue(indexName, username);
+ Map idToSessions = sessionRepository.findByIndexNameAndIndexValue(indexName, username);
// end::findbyindexname-get[]
assertThat(idToSessions.keySet()).containsOnly(session.getId());
@@ -82,7 +83,7 @@ public class HttpSessionGemFireIndexingITests extends AbstractGemFireIntegration
// tag::findbyspringsecurityindexname-get[]
String indexName = FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME;
- Map idToSessions = sessionRepository.findByIndexNameAndIndexValue(indexName, authentication.getName());
+ Map idToSessions = sessionRepository.findByIndexNameAndIndexValue(indexName, authentication.getName());
// end::findbyspringsecurityindexname-get[]
assertThat(idToSessions.keySet()).containsOnly(session.getId());
diff --git a/docs/src/integration-test/java/docs/http/gemfire/indexablesessionattributes/GemFireHttpSessionConfig.java b/docs/src/integration-test/java/docs/http/gemfire/indexablesessionattributes/GemFireHttpSessionConfig.java
index 13ad608c..096890a6 100644
--- a/docs/src/integration-test/java/docs/http/gemfire/indexablesessionattributes/GemFireHttpSessionConfig.java
+++ b/docs/src/integration-test/java/docs/http/gemfire/indexablesessionattributes/GemFireHttpSessionConfig.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,16 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package docs.http.gemfire.indexablesessionattributes;
import java.util.Properties;
+import docs.AbstractGemFireIntegrationTests;
+
import org.springframework.context.annotation.Bean;
import org.springframework.data.gemfire.CacheFactoryBean;
import org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession;
-import docs.AbstractGemFireIntegrationTests;
-
/**
* @author Rob Winch
*
diff --git a/docs/src/integration-test/java/docs/http/gemfire/indexablesessionattributes/HttpSessionGemFireIndexingCustomITests.java b/docs/src/integration-test/java/docs/http/gemfire/indexablesessionattributes/HttpSessionGemFireIndexingCustomITests.java
index 780c2889..cfbae29d 100644
--- a/docs/src/integration-test/java/docs/http/gemfire/indexablesessionattributes/HttpSessionGemFireIndexingCustomITests.java
+++ b/docs/src/integration-test/java/docs/http/gemfire/indexablesessionattributes/HttpSessionGemFireIndexingCustomITests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,26 +13,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package docs.http.gemfire.indexablesessionattributes;
-import static org.assertj.core.api.Assertions.assertThat;
+package docs.http.gemfire.indexablesessionattributes;
import java.util.Map;
+import docs.AbstractGemFireIntegrationTests;
import org.junit.Test;
import org.junit.runner.RunWith;
+
import org.springframework.session.ExpiringSession;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import docs.AbstractGemFireIntegrationTests;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rob Winch
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(classes=GemFireHttpSessionConfig.class)
+@ContextConfiguration(classes = GemFireHttpSessionConfig.class)
public class HttpSessionGemFireIndexingCustomITests extends AbstractGemFireIntegrationTests {
@Test
@@ -48,7 +49,7 @@ public class HttpSessionGemFireIndexingCustomITests extends AbstractGemFireInteg
sessionRepository.save(session);
// tag::findbyindexname-get[]
- Map idToSessions = sessionRepository.findByIndexNameAndIndexValue(indexName, attrValue);
+ Map idToSessions = sessionRepository.findByIndexNameAndIndexValue(indexName, attrValue);
// end::findbyindexname-get[]
assertThat(idToSessions.keySet()).containsOnly(session.getId());
diff --git a/docs/src/test/java/docs/FindByIndexNameSessionRepositoryTests.java b/docs/src/test/java/docs/FindByIndexNameSessionRepositoryTests.java
index c876142f..986a3d72 100644
--- a/docs/src/test/java/docs/FindByIndexNameSessionRepositoryTests.java
+++ b/docs/src/test/java/docs/FindByIndexNameSessionRepositoryTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package docs;
import java.util.Map;
@@ -21,6 +22,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
+
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.Session;
@@ -39,7 +41,7 @@ public class FindByIndexNameSessionRepositoryTests {
public void setUsername() {
// tag::set-username[]
String username = "username";
- session.setAttribute(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, username);
+ this.session.setAttribute(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, username);
// end::set-username[]
}
@@ -48,8 +50,8 @@ public class FindByIndexNameSessionRepositoryTests {
public void findByUsername() {
// tag::findby-username[]
String username = "username";
- Map sessionIdToSession =
- sessionRepository.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, username);
+ Map sessionIdToSession =
+ this.sessionRepository.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, username);
// end::findby-username[]
}
}
diff --git a/docs/src/test/java/docs/HttpSessionConfigurationNoOpConfigureRedisActionXmlTests.java b/docs/src/test/java/docs/HttpSessionConfigurationNoOpConfigureRedisActionXmlTests.java
index 994c14bf..da23a011 100644
--- a/docs/src/test/java/docs/HttpSessionConfigurationNoOpConfigureRedisActionXmlTests.java
+++ b/docs/src/test/java/docs/HttpSessionConfigurationNoOpConfigureRedisActionXmlTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,13 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package docs;
-import static org.assertj.core.api.Assertions.*;
-import static org.mockito.Mockito.mock;
+package docs;
import org.junit.Test;
import org.junit.runner.RunWith;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.session.ExpiringSession;
@@ -28,6 +27,9 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
/**
* @author Rob Winch
*/
@@ -40,7 +42,7 @@ public class HttpSessionConfigurationNoOpConfigureRedisActionXmlTests {
@Test
public void redisConnectionFactoryNotUsedSinceNoValidation() {
- assertThat(filter).isNotNull();
+ assertThat(this.filter).isNotNull();
}
diff --git a/docs/src/test/java/docs/IndexDocTests.java b/docs/src/test/java/docs/IndexDocTests.java
index 8e19bfd4..3e683131 100644
--- a/docs/src/test/java/docs/IndexDocTests.java
+++ b/docs/src/test/java/docs/IndexDocTests.java
@@ -1,23 +1,23 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
- * 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
+ * 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
+ * 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.
+ * 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 docs;
-import static org.assertj.core.api.Assertions.*;
-
import org.junit.Test;
+
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.mock.web.MockServletContext;
import org.springframework.session.ExpiringSession;
@@ -28,6 +28,8 @@ import org.springframework.session.data.redis.RedisOperationsSessionRepository;
import org.springframework.session.web.http.SessionRepositoryFilter;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
+import static org.assertj.core.api.Assertions.assertThat;
+
/**
* @author Rob Winch
*/
@@ -47,15 +49,15 @@ public class IndexDocTests {
private SessionRepository repository; // <1>
public void demo() {
- S toSave = repository.createSession(); // <2>
+ S toSave = this.repository.createSession(); // <2>
// <3>
User rwinch = new User("rwinch");
toSave.setAttribute(ATTR_USER, rwinch);
- repository.save(toSave); // <4>
+ this.repository.save(toSave); // <4>
- S session = repository.getSession(toSave.getId()); // <5>
+ S session = this.repository.getSession(toSave.getId()); // <5>
// <6>
User user = session.getAttribute(ATTR_USER);
@@ -81,13 +83,13 @@ public class IndexDocTests {
private SessionRepository repository; // <1>
public void demo() {
- S toSave = repository.createSession(); // <2>
+ S toSave = this.repository.createSession(); // <2>
// ...
toSave.setMaxInactiveIntervalInSeconds(30); // <3>
- repository.save(toSave); // <4>
+ this.repository.save(toSave); // <4>
- S session = repository.getSession(toSave.getId()); // <5>
+ S session = this.repository.getSession(toSave.getId()); // <5>
// ...
}
@@ -122,12 +124,14 @@ public class IndexDocTests {
try {
context.getBean(SessionRepositoryFilter.class);
- } finally {
+ }
+ finally {
context.close();
}
}
- private static class User {
- private User(String username) {}
+ private static final class User {
+ private User(String username) {
+ }
}
}
diff --git a/docs/src/test/java/docs/RedisHttpSessionConfigurationNoOpConfigureRedisActionTests.java b/docs/src/test/java/docs/RedisHttpSessionConfigurationNoOpConfigureRedisActionTests.java
index 2c17f2ca..21fa5600 100644
--- a/docs/src/test/java/docs/RedisHttpSessionConfigurationNoOpConfigureRedisActionTests.java
+++ b/docs/src/test/java/docs/RedisHttpSessionConfigurationNoOpConfigureRedisActionTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package docs;
-import static org.mockito.Mockito.mock;
+package docs;
import org.junit.Test;
import org.junit.runner.RunWith;
+
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
@@ -28,6 +28,8 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
+import static org.mockito.Mockito.mock;
+
/**
* @author Rob Winch
*/
@@ -37,7 +39,8 @@ import org.springframework.test.context.web.WebAppConfiguration;
public class RedisHttpSessionConfigurationNoOpConfigureRedisActionTests {
@Test
- public void redisConnectionFactoryNotUsedSinceNoValidation() {}
+ public void redisConnectionFactoryNotUsedSinceNoValidation() {
+ }
@EnableRedisHttpSession
@Configuration
diff --git a/docs/src/test/java/docs/SpringHttpSessionConfig.java b/docs/src/test/java/docs/SpringHttpSessionConfig.java
index b7456e90..30694cdf 100644
--- a/docs/src/test/java/docs/SpringHttpSessionConfig.java
+++ b/docs/src/test/java/docs/SpringHttpSessionConfig.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package docs;
import org.springframework.context.annotation.Bean;
@@ -29,4 +30,4 @@ public class SpringHttpSessionConfig {
return new MapSessionRepository();
}
}
-// end::class[]
\ No newline at end of file
+// end::class[]
diff --git a/docs/src/test/java/docs/http/AbstractHttpSessionListenerTests.java b/docs/src/test/java/docs/http/AbstractHttpSessionListenerTests.java
index 4a7fb67a..567f1f07 100644
--- a/docs/src/test/java/docs/http/AbstractHttpSessionListenerTests.java
+++ b/docs/src/test/java/docs/http/AbstractHttpSessionListenerTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,14 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package docs.http;
-import static org.assertj.core.api.Assertions.*;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+package docs.http;
import org.junit.Test;
import org.junit.runner.RunWith;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationListener;
@@ -32,6 +30,10 @@ import org.springframework.session.Session;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.mock;
+
/**
* @author Rob Winch
* @since 1.2
@@ -49,16 +51,16 @@ public abstract class AbstractHttpSessionListenerTests {
public void springSessionDestroyedTranslatedToSpringSecurityDestroyed() {
Session session = new MapSession();
- publisher.publishEvent(new org.springframework.session.events.SessionDestroyedEvent(this, session));
+ this.publisher.publishEvent(new org.springframework.session.events.SessionDestroyedEvent(this, session));
- assertThat(listener.getEvent().getId()).isEqualTo(session.getId());
+ assertThat(this.listener.getEvent().getId()).isEqualTo(session.getId());
}
static RedisConnectionFactory createMockRedisConnection() {
RedisConnectionFactory factory = mock(RedisConnectionFactory.class);
RedisConnection connection = mock(RedisConnection.class);
- when(factory.getConnection()).thenReturn(connection);
+ given(factory.getConnection()).willReturn(connection);
return factory;
}
@@ -74,7 +76,7 @@ public abstract class AbstractHttpSessionListenerTests {
}
public SessionDestroyedEvent getEvent() {
- return event;
+ return this.event;
}
}
}
diff --git a/docs/src/test/java/docs/http/HazelcastHttpSessionConfig.java b/docs/src/test/java/docs/http/HazelcastHttpSessionConfig.java
index 14f707f2..6a472095 100644
--- a/docs/src/test/java/docs/http/HazelcastHttpSessionConfig.java
+++ b/docs/src/test/java/docs/http/HazelcastHttpSessionConfig.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,16 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package docs.http;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.session.hazelcast.config.annotation.web.http.EnableHazelcastHttpSession;
+package docs.http;
import com.hazelcast.config.Config;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.session.hazelcast.config.annotation.web.http.EnableHazelcastHttpSession;
+
//tag::config[]
@EnableHazelcastHttpSession // <1>
@Configuration
@@ -33,4 +34,4 @@ public class HazelcastHttpSessionConfig {
return Hazelcast.newHazelcastInstance(hazelcastConfig); // <2>
}
}
-// end::config[]
\ No newline at end of file
+// end::config[]
diff --git a/docs/src/test/java/docs/http/HttpSessionListenerJavaConfigTests.java b/docs/src/test/java/docs/http/HttpSessionListenerJavaConfigTests.java
index 3aeecd8d..f051976e 100644
--- a/docs/src/test/java/docs/http/HttpSessionListenerJavaConfigTests.java
+++ b/docs/src/test/java/docs/http/HttpSessionListenerJavaConfigTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package docs.http;
import org.springframework.context.annotation.Bean;
diff --git a/docs/src/test/java/docs/http/HttpSessionListenerXmlTests.java b/docs/src/test/java/docs/http/HttpSessionListenerXmlTests.java
index 43c900aa..aa359e23 100644
--- a/docs/src/test/java/docs/http/HttpSessionListenerXmlTests.java
+++ b/docs/src/test/java/docs/http/HttpSessionListenerXmlTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package docs.http;
import org.springframework.test.context.ContextConfiguration;
diff --git a/docs/src/test/java/docs/http/RedisHttpSessionConfig.java b/docs/src/test/java/docs/http/RedisHttpSessionConfig.java
index 13b97072..948de07e 100644
--- a/docs/src/test/java/docs/http/RedisHttpSessionConfig.java
+++ b/docs/src/test/java/docs/http/RedisHttpSessionConfig.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package docs.http;
import org.springframework.context.annotation.Bean;
@@ -32,4 +33,4 @@ public class RedisHttpSessionConfig {
// ...
}
-// end::config[]
\ No newline at end of file
+// end::config[]
diff --git a/docs/src/test/java/docs/websocket/WebSocketConfig.java b/docs/src/test/java/docs/websocket/WebSocketConfig.java
index 46123ad2..81b435ff 100644
--- a/docs/src/test/java/docs/websocket/WebSocketConfig.java
+++ b/docs/src/test/java/docs/websocket/WebSocketConfig.java
@@ -1,18 +1,19 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
- * 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
+ * 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
+ * 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.
+ * 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 docs.websocket;
import org.springframework.context.annotation.Configuration;
@@ -43,4 +44,4 @@ public class WebSocketConfig
registry.setApplicationDestinationPrefixes("/app");
}
}
-// end::class[]
\ No newline at end of file
+// end::class[]
diff --git a/samples/boot/src/integration-test/groovy/sample/BootTests.groovy b/samples/boot/src/integration-test/groovy/sample/BootTests.groovy
index b1c8d7f4..f158edbd 100644
--- a/samples/boot/src/integration-test/groovy/sample/BootTests.groovy
+++ b/samples/boot/src/integration-test/groovy/sample/BootTests.groovy
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample
import geb.spock.*
@@ -71,4 +72,4 @@ class BootTests extends GebReportingSpec {
then: 'sent to the log in page'
at LoginPage
}
-}
\ No newline at end of file
+}
diff --git a/samples/boot/src/integration-test/groovy/sample/pages/HomePage.groovy b/samples/boot/src/integration-test/groovy/sample/pages/HomePage.groovy
index 867b81a7..ae2c3e94 100644
--- a/samples/boot/src/integration-test/groovy/sample/pages/HomePage.groovy
+++ b/samples/boot/src/integration-test/groovy/sample/pages/HomePage.groovy
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample.pages
import geb.*
diff --git a/samples/boot/src/integration-test/groovy/sample/pages/LoginPage.groovy b/samples/boot/src/integration-test/groovy/sample/pages/LoginPage.groovy
index ceeb790a..68f98597 100644
--- a/samples/boot/src/integration-test/groovy/sample/pages/LoginPage.groovy
+++ b/samples/boot/src/integration-test/groovy/sample/pages/LoginPage.groovy
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample.pages
import geb.*
diff --git a/samples/boot/src/main/java/sample/Application.java b/samples/boot/src/main/java/sample/Application.java
index 8d570129..02627e78 100644
--- a/samples/boot/src/main/java/sample/Application.java
+++ b/samples/boot/src/main/java/sample/Application.java
@@ -1,18 +1,19 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
- * 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
+ * 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
+ * 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.
+ * 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 sample;
import org.springframework.boot.SpringApplication;
diff --git a/samples/boot/src/main/java/sample/config/HttpSessionConfig.java b/samples/boot/src/main/java/sample/config/HttpSessionConfig.java
index 29ba85c0..40b37329 100644
--- a/samples/boot/src/main/java/sample/config/HttpSessionConfig.java
+++ b/samples/boot/src/main/java/sample/config/HttpSessionConfig.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample.config;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
@@ -21,4 +22,4 @@ import org.springframework.session.data.redis.config.annotation.web.http.EnableR
// tag::class[]
@EnableRedisHttpSession // <1>
public class HttpSessionConfig { }
-// end::class[]
\ No newline at end of file
+// end::class[]
diff --git a/samples/boot/src/main/java/sample/config/SecurityConfig.java b/samples/boot/src/main/java/sample/config/SecurityConfig.java
index ab040300..082b2fd5 100644
--- a/samples/boot/src/main/java/sample/config/SecurityConfig.java
+++ b/samples/boot/src/main/java/sample/config/SecurityConfig.java
@@ -1,18 +1,19 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
- * 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
+ * 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
+ * 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.
+ * 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 sample.config;
import org.springframework.beans.factory.annotation.Autowired;
diff --git a/samples/boot/src/main/java/sample/mvc/IndexController.java b/samples/boot/src/main/java/sample/mvc/IndexController.java
index 8a76934d..8c94fb38 100644
--- a/samples/boot/src/main/java/sample/mvc/IndexController.java
+++ b/samples/boot/src/main/java/sample/mvc/IndexController.java
@@ -1,18 +1,19 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
- * 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
+ * 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
+ * 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.
+ * 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 sample.mvc;
import org.springframework.stereotype.Controller;
diff --git a/samples/custom-cookie/src/integration-test/groovy/sample/AttributeTests.groovy b/samples/custom-cookie/src/integration-test/groovy/sample/AttributeTests.groovy
index a5f85c86..c865fc43 100644
--- a/samples/custom-cookie/src/integration-test/groovy/sample/AttributeTests.groovy
+++ b/samples/custom-cookie/src/integration-test/groovy/sample/AttributeTests.groovy
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample
import geb.spock.*
@@ -42,4 +43,4 @@ class AttributeTests extends GebReportingSpec {
attributes[0].name == 'a'
attributes[0].value == 'b'
}
-}
\ No newline at end of file
+}
diff --git a/samples/custom-cookie/src/integration-test/groovy/sample/pages/HomePage.groovy b/samples/custom-cookie/src/integration-test/groovy/sample/pages/HomePage.groovy
index e087b5c4..25215292 100644
--- a/samples/custom-cookie/src/integration-test/groovy/sample/pages/HomePage.groovy
+++ b/samples/custom-cookie/src/integration-test/groovy/sample/pages/HomePage.groovy
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample.pages
import geb.*
diff --git a/samples/custom-cookie/src/main/java/sample/Config.java b/samples/custom-cookie/src/main/java/sample/Config.java
index a1db9fef..1555763d 100644
--- a/samples/custom-cookie/src/main/java/sample/Config.java
+++ b/samples/custom-cookie/src/main/java/sample/Config.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample;
import org.springframework.context.annotation.Bean;
@@ -40,4 +41,4 @@ public class Config {
return serializer;
}
// end::cookie-serializer[]
-}
\ No newline at end of file
+}
diff --git a/samples/custom-cookie/src/main/java/sample/Initializer.java b/samples/custom-cookie/src/main/java/sample/Initializer.java
index 7512f33c..508db307 100644
--- a/samples/custom-cookie/src/main/java/sample/Initializer.java
+++ b/samples/custom-cookie/src/main/java/sample/Initializer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample;
import org.springframework.session.web.context.AbstractHttpSessionApplicationInitializer;
@@ -25,4 +26,4 @@ public class Initializer
super(Config.class); // <2>
}
}
-// end::class[]
\ No newline at end of file
+// end::class[]
diff --git a/samples/custom-cookie/src/main/java/sample/SessionServlet.java b/samples/custom-cookie/src/main/java/sample/SessionServlet.java
index f0a8d6dc..95fc103a 100644
--- a/samples/custom-cookie/src/main/java/sample/SessionServlet.java
+++ b/samples/custom-cookie/src/main/java/sample/SessionServlet.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,13 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample;
-import javax.servlet.*;
-import javax.servlet.annotation.*;
-import javax.servlet.http.*;
import java.io.IOException;
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
// tag::class[]
@WebServlet("/session")
public class SessionServlet extends HttpServlet {
@@ -34,4 +38,4 @@ public class SessionServlet extends HttpServlet {
private static final long serialVersionUID = 2878267318695777395L;
}
-// tag::end[]
\ No newline at end of file
+// tag::end[]
diff --git a/samples/findbyusername/src/integration-test/groovy/sample/FindByUsernameTests.groovy b/samples/findbyusername/src/integration-test/groovy/sample/FindByUsernameTests.groovy
index 511c3781..21228034 100644
--- a/samples/findbyusername/src/integration-test/groovy/sample/FindByUsernameTests.groovy
+++ b/samples/findbyusername/src/integration-test/groovy/sample/FindByUsernameTests.groovy
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample
import geb.Browser
@@ -101,4 +102,4 @@ class FindByUsernameTests extends MultiBrowserGebSpec {
then: 'browser a sent to log in'
a.at LoginPage
}
-}
\ No newline at end of file
+}
diff --git a/samples/findbyusername/src/integration-test/groovy/sample/MultiBrowserGebSpec.groovy b/samples/findbyusername/src/integration-test/groovy/sample/MultiBrowserGebSpec.groovy
index 5c2f73a0..6f38c197 100644
--- a/samples/findbyusername/src/integration-test/groovy/sample/MultiBrowserGebSpec.groovy
+++ b/samples/findbyusername/src/integration-test/groovy/sample/MultiBrowserGebSpec.groovy
@@ -1,11 +1,11 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* 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
+ * 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,
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample;
import geb.*
import spock.lang.*
@@ -97,4 +98,4 @@ abstract class MultiBrowserGebSpec extends Specification {
def cleanupSpec() {
if (isSpecStepwise()) resetBrowsers()
}
-}
\ No newline at end of file
+}
diff --git a/samples/findbyusername/src/integration-test/groovy/sample/pages/HomePage.groovy b/samples/findbyusername/src/integration-test/groovy/sample/pages/HomePage.groovy
index 3d877631..a9d002df 100644
--- a/samples/findbyusername/src/integration-test/groovy/sample/pages/HomePage.groovy
+++ b/samples/findbyusername/src/integration-test/groovy/sample/pages/HomePage.groovy
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample.pages
import geb.*
diff --git a/samples/findbyusername/src/integration-test/groovy/sample/pages/LoginPage.groovy b/samples/findbyusername/src/integration-test/groovy/sample/pages/LoginPage.groovy
index 612be1e6..b93ad5f9 100644
--- a/samples/findbyusername/src/integration-test/groovy/sample/pages/LoginPage.groovy
+++ b/samples/findbyusername/src/integration-test/groovy/sample/pages/LoginPage.groovy
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample.pages
import geb.*
diff --git a/samples/findbyusername/src/main/java/sample/FindByUsernameApplication.java b/samples/findbyusername/src/main/java/sample/FindByUsernameApplication.java
index 433e782b..0bca487f 100644
--- a/samples/findbyusername/src/main/java/sample/FindByUsernameApplication.java
+++ b/samples/findbyusername/src/main/java/sample/FindByUsernameApplication.java
@@ -1,18 +1,19 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
- * 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
+ * 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
+ * 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.
+ * 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 sample;
import org.springframework.boot.SpringApplication;
diff --git a/samples/findbyusername/src/main/java/sample/config/GeoConfig.java b/samples/findbyusername/src/main/java/sample/config/GeoConfig.java
index d34404d2..c74a29fb 100644
--- a/samples/findbyusername/src/main/java/sample/config/GeoConfig.java
+++ b/samples/findbyusername/src/main/java/sample/config/GeoConfig.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,16 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample.config;
import java.io.InputStream;
+import com.maxmind.geoip2.DatabaseReader;
+
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import com.maxmind.geoip2.DatabaseReader;
-
/**
*
* @author Rob Winch
diff --git a/samples/findbyusername/src/main/java/sample/config/HttpSessionConfig.java b/samples/findbyusername/src/main/java/sample/config/HttpSessionConfig.java
index f516173f..fd61436a 100644
--- a/samples/findbyusername/src/main/java/sample/config/HttpSessionConfig.java
+++ b/samples/findbyusername/src/main/java/sample/config/HttpSessionConfig.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample.config;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
@@ -25,4 +26,4 @@ import org.springframework.session.data.redis.config.annotation.web.http.EnableR
// tag::class[]
@EnableRedisHttpSession // <1>
public class HttpSessionConfig { }
-// end::class[]
\ No newline at end of file
+// end::class[]
diff --git a/samples/findbyusername/src/main/java/sample/config/SecurityConfig.java b/samples/findbyusername/src/main/java/sample/config/SecurityConfig.java
index ade70f5f..9747d785 100644
--- a/samples/findbyusername/src/main/java/sample/config/SecurityConfig.java
+++ b/samples/findbyusername/src/main/java/sample/config/SecurityConfig.java
@@ -1,18 +1,19 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
- * 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
+ * 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
+ * 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.
+ * 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 sample.config;
import org.springframework.beans.factory.annotation.Autowired;
diff --git a/samples/findbyusername/src/main/java/sample/mvc/IndexController.java b/samples/findbyusername/src/main/java/sample/mvc/IndexController.java
index 0200fc5d..51ee4fd0 100644
--- a/samples/findbyusername/src/main/java/sample/mvc/IndexController.java
+++ b/samples/findbyusername/src/main/java/sample/mvc/IndexController.java
@@ -1,18 +1,19 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
- * 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
+ * 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
+ * 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.
+ * 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 sample.mvc;
import java.security.Principal;
@@ -43,7 +44,7 @@ public class IndexController {
@RequestMapping("/")
public String index(Principal principal, Model model) {
Collection extends ExpiringSession> usersSessions =
- sessions.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME,
+ this.sessions.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME,
principal.getName()).values();
model.addAttribute("sessions", usersSessions);
return "index";
@@ -52,12 +53,12 @@ public class IndexController {
@RequestMapping(value = "/sessions/{sessionIdToDelete}", method = RequestMethod.DELETE)
public String removeSession(Principal principal, @PathVariable String sessionIdToDelete) {
- Set usersSessionIds = sessions.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME,
+ Set usersSessionIds = this.sessions.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME,
principal.getName()).keySet();
- if(usersSessionIds.contains(sessionIdToDelete)) {
- sessions.delete(sessionIdToDelete);
+ if (usersSessionIds.contains(sessionIdToDelete)) {
+ this.sessions.delete(sessionIdToDelete);
}
return "redirect:/";
}
-}
\ No newline at end of file
+}
diff --git a/samples/findbyusername/src/main/java/sample/mvc/LoginController.java b/samples/findbyusername/src/main/java/sample/mvc/LoginController.java
index 81bb64a1..7403b021 100644
--- a/samples/findbyusername/src/main/java/sample/mvc/LoginController.java
+++ b/samples/findbyusername/src/main/java/sample/mvc/LoginController.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample.mvc;
import org.springframework.stereotype.Controller;
diff --git a/samples/findbyusername/src/main/java/sample/session/SessionDetails.java b/samples/findbyusername/src/main/java/sample/session/SessionDetails.java
index 3d6b52f5..03be008f 100644
--- a/samples/findbyusername/src/main/java/sample/session/SessionDetails.java
+++ b/samples/findbyusername/src/main/java/sample/session/SessionDetails.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample.session;
import java.io.Serializable;
@@ -30,7 +31,7 @@ public class SessionDetails implements Serializable {
private String accessType;
public String getLocation() {
- return location;
+ return this.location;
}
public void setLocation(String location) {
@@ -38,7 +39,7 @@ public class SessionDetails implements Serializable {
}
public String getAccessType() {
- return accessType;
+ return this.accessType;
}
public void setAccessType(String accessType) {
diff --git a/samples/findbyusername/src/main/java/sample/session/SessionDetailsFilter.java b/samples/findbyusername/src/main/java/sample/session/SessionDetailsFilter.java
index 70b6e4ec..4731734f 100644
--- a/samples/findbyusername/src/main/java/sample/session/SessionDetailsFilter.java
+++ b/samples/findbyusername/src/main/java/sample/session/SessionDetailsFilter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample.session;
import java.io.IOException;
@@ -24,15 +25,15 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
+import com.maxmind.geoip2.DatabaseReader;
+import com.maxmind.geoip2.model.CityResponse;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
-import com.maxmind.geoip2.DatabaseReader;
-import com.maxmind.geoip2.model.CityResponse;
-
/**
* Inserts the session details into the session for every request. Some users
* may prefer to insert session details only after authentication. This is fine,
@@ -76,18 +77,21 @@ public class SessionDetailsFilter extends OncePerRequestFilter {
String getGeoLocation(String remoteAddr) {
try {
- CityResponse city = reader.city(InetAddress.getByName(remoteAddr));
+ CityResponse city = this.reader.city(InetAddress.getByName(remoteAddr));
String cityName = city.getCity().getName();
String countryName = city.getCountry().getName();
- if(cityName == null && countryName == null) {
+ if (cityName == null && countryName == null) {
return null;
- } else if(cityName == null) {
+ }
+ else if (cityName == null) {
return countryName;
- } else if(countryName == null) {
+ }
+ else if (countryName == null) {
return cityName;
}
return cityName + ", " + countryName;
- } catch (Exception e) {
+ }
+ catch (Exception e) {
return UNKNOWN;
}
@@ -97,7 +101,8 @@ public class SessionDetailsFilter extends OncePerRequestFilter {
String remoteAddr = request.getHeader("X-FORWARDED-FOR");
if (remoteAddr == null) {
remoteAddr = request.getRemoteAddr();
- } else if (remoteAddr.contains(",")) {
+ }
+ else if (remoteAddr.contains(",")) {
remoteAddr = remoteAddr.split(",")[0];
}
return remoteAddr;
diff --git a/samples/findbyusername/src/test/java/sample/session/SessionDetailsFilterTests.java b/samples/findbyusername/src/test/java/sample/session/SessionDetailsFilterTests.java
index da098b59..66eb75ea 100644
--- a/samples/findbyusername/src/test/java/sample/session/SessionDetailsFilterTests.java
+++ b/samples/findbyusername/src/test/java/sample/session/SessionDetailsFilterTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,20 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample.session;
-import static org.assertj.core.api.Assertions.*;
-
+import com.maxmind.geoip2.DatabaseReader;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+
+import sample.config.GeoConfig;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import com.maxmind.geoip2.DatabaseReader;
-
-import sample.config.GeoConfig;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rob Winch
@@ -42,21 +43,21 @@ public class SessionDetailsFilterTests {
@Before
public void setup() {
- filter = new SessionDetailsFilter(reader);
+ this.filter = new SessionDetailsFilter(this.reader);
}
@Test
public void getGeoLocationHanldesInvalidIp() {
- assertThat(filter.getGeoLocation("a")).isEqualTo(SessionDetailsFilter.UNKNOWN);
+ assertThat(this.filter.getGeoLocation("a")).isEqualTo(SessionDetailsFilter.UNKNOWN);
}
@Test
public void getGeoLocationNullCity() {
- assertThat(filter.getGeoLocation("22.231.113.64")).isEqualTo("United States");
+ assertThat(this.filter.getGeoLocation("22.231.113.64")).isEqualTo("United States");
}
@Test
public void getGeoLocationBoth() {
- assertThat(filter.getGeoLocation("184.154.83.119")).isEqualTo("Chicago, United States");
+ assertThat(this.filter.getGeoLocation("184.154.83.119")).isEqualTo("Chicago, United States");
}
-}
\ No newline at end of file
+}
diff --git a/samples/hazelcast-spring/src/integration-test/groovy/sample/HazelcastSpringTests.groovy b/samples/hazelcast-spring/src/integration-test/groovy/sample/HazelcastSpringTests.groovy
index 12a1fa96..df2c1cab 100644
--- a/samples/hazelcast-spring/src/integration-test/groovy/sample/HazelcastSpringTests.groovy
+++ b/samples/hazelcast-spring/src/integration-test/groovy/sample/HazelcastSpringTests.groovy
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample
import geb.spock.GebReportingSpec
@@ -62,4 +63,4 @@ class HazelcastSpringTests extends GebReportingSpec {
then: 'sent to the log in page'
at LoginPage
}
-}
\ No newline at end of file
+}
diff --git a/samples/hazelcast-spring/src/integration-test/groovy/sample/pages/HomePage.groovy b/samples/hazelcast-spring/src/integration-test/groovy/sample/pages/HomePage.groovy
index 45634e66..b98a276e 100644
--- a/samples/hazelcast-spring/src/integration-test/groovy/sample/pages/HomePage.groovy
+++ b/samples/hazelcast-spring/src/integration-test/groovy/sample/pages/HomePage.groovy
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample.pages
import geb.Page
diff --git a/samples/hazelcast-spring/src/integration-test/groovy/sample/pages/LoginPage.groovy b/samples/hazelcast-spring/src/integration-test/groovy/sample/pages/LoginPage.groovy
index 08c7fb27..d8a5beaf 100644
--- a/samples/hazelcast-spring/src/integration-test/groovy/sample/pages/LoginPage.groovy
+++ b/samples/hazelcast-spring/src/integration-test/groovy/sample/pages/LoginPage.groovy
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample.pages
import geb.Page
diff --git a/samples/hazelcast-spring/src/main/java/sample/Config.java b/samples/hazelcast-spring/src/main/java/sample/Config.java
index 4fcbcf16..ba591e60 100644
--- a/samples/hazelcast-spring/src/main/java/sample/Config.java
+++ b/samples/hazelcast-spring/src/main/java/sample/Config.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,18 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package sample;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.session.hazelcast.config.annotation.web.http.EnableHazelcastHttpSession;
-import org.springframework.util.SocketUtils;
+package sample;
import com.hazelcast.config.NetworkConfig;
import com.hazelcast.config.SerializerConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.session.hazelcast.config.annotation.web.http.EnableHazelcastHttpSession;
+import org.springframework.util.SocketUtils;
+
// tag::class[]
@EnableHazelcastHttpSession(maxInactiveIntervalInSeconds = 300)
@Configuration
@@ -45,4 +46,4 @@ public class Config {
}
}
-// end::class[]
\ No newline at end of file
+// end::class[]
diff --git a/samples/hazelcast-spring/src/main/java/sample/Initializer.java b/samples/hazelcast-spring/src/main/java/sample/Initializer.java
index f8627a7f..6970e506 100644
--- a/samples/hazelcast-spring/src/main/java/sample/Initializer.java
+++ b/samples/hazelcast-spring/src/main/java/sample/Initializer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample;
import org.springframework.session.web.context.AbstractHttpSessionApplicationInitializer;
@@ -21,4 +22,4 @@ import org.springframework.session.web.context.AbstractHttpSessionApplicationIni
public class Initializer extends AbstractHttpSessionApplicationInitializer {
}
-// end::class[]
\ No newline at end of file
+// end::class[]
diff --git a/samples/hazelcast-spring/src/main/java/sample/ObjectStreamSerializer.java b/samples/hazelcast-spring/src/main/java/sample/ObjectStreamSerializer.java
index 11db8e8c..78b31ee6 100644
--- a/samples/hazelcast-spring/src/main/java/sample/ObjectStreamSerializer.java
+++ b/samples/hazelcast-spring/src/main/java/sample/ObjectStreamSerializer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,9 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package sample;
-import java.io.*;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
@@ -37,18 +42,19 @@ public class ObjectStreamSerializer implements StreamSerializer
*
- * @since 1.0
* @author Rob Winch
+ * @since 1.0
*/
public final class MapSession implements ExpiringSession, Serializable {
/**
- * Default {@link #setMaxInactiveIntervalInSeconds(int)} (30 minutes)
+ * Default {@link #setMaxInactiveIntervalInSeconds(int)} (30 minutes).
*/
public static final int DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS = 1800;
private String id;
private Map sessionAttrs = new HashMap();
private long creationTime = System.currentTimeMillis();
- private long lastAccessedTime = creationTime;
+ private long lastAccessedTime = this.creationTime;
/**
- * Defaults to 30 minutes
+ * Defaults to 30 minutes.
*/
private int maxInactiveInterval = DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS;
@@ -75,12 +76,12 @@ public final class MapSession implements ExpiringSession, Serializable {
}
/**
- * Creates a new instance from the provided {@link Session}
+ * Creates a new instance from the provided {@link Session}.
*
* @param session the {@link Session} to initialize this {@link Session} with. Cannot be null.
*/
public MapSession(ExpiringSession session) {
- if(session == null) {
+ if (session == null) {
throw new IllegalArgumentException("session cannot be null");
}
this.id = session.getId();
@@ -99,15 +100,15 @@ public final class MapSession implements ExpiringSession, Serializable {
}
public long getCreationTime() {
- return creationTime;
+ return this.creationTime;
}
public String getId() {
- return id;
+ return this.id;
}
public long getLastAccessedTime() {
- return lastAccessedTime;
+ return this.lastAccessedTime;
}
public void setMaxInactiveIntervalInSeconds(int interval) {
@@ -115,7 +116,7 @@ public final class MapSession implements ExpiringSession, Serializable {
}
public int getMaxInactiveIntervalInSeconds() {
- return maxInactiveInterval;
+ return this.maxInactiveInterval;
}
public boolean isExpired() {
@@ -123,31 +124,32 @@ public final class MapSession implements ExpiringSession, Serializable {
}
boolean isExpired(long now) {
- if(maxInactiveInterval < 0) {
+ if (this.maxInactiveInterval < 0) {
return false;
}
- return now - TimeUnit.SECONDS.toMillis(maxInactiveInterval) >= lastAccessedTime;
+ return now - TimeUnit.SECONDS.toMillis(this.maxInactiveInterval) >= this.lastAccessedTime;
}
@SuppressWarnings("unchecked")
public T getAttribute(String attributeName) {
- return (T) sessionAttrs.get(attributeName);
+ return (T) this.sessionAttrs.get(attributeName);
}
public Set getAttributeNames() {
- return sessionAttrs.keySet();
+ return this.sessionAttrs.keySet();
}
public void setAttribute(String attributeName, Object attributeValue) {
if (attributeValue == null) {
removeAttribute(attributeName);
- } else {
- sessionAttrs.put(attributeName, attributeValue);
+ }
+ else {
+ this.sessionAttrs.put(attributeName, attributeValue);
}
}
public void removeAttribute(String attributeName) {
- sessionAttrs.remove(attributeName);
+ this.sessionAttrs.remove(attributeName);
}
/**
@@ -168,12 +170,12 @@ public final class MapSession implements ExpiringSession, Serializable {
}
public boolean equals(Object obj) {
- return obj instanceof Session && id.equals(((Session) obj).getId());
+ return obj instanceof Session && this.id.equals(((Session) obj).getId());
}
public int hashCode() {
- return id.hashCode();
+ return this.id.hashCode();
}
private static final long serialVersionUID = 7160779239673823561L;
-}
\ No newline at end of file
+}
diff --git a/spring-session/src/main/java/org/springframework/session/MapSessionRepository.java b/spring-session/src/main/java/org/springframework/session/MapSessionRepository.java
index 15a96f48..98fc7ba0 100644
--- a/spring-session/src/main/java/org/springframework/session/MapSessionRepository.java
+++ b/spring-session/src/main/java/org/springframework/session/MapSessionRepository.java
@@ -1,26 +1,27 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
- * 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
+ * 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
+ * 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.
+ * 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.springframework.session;
-import org.springframework.session.events.SessionDeletedEvent;
-import org.springframework.session.events.SessionExpiredEvent;
+package org.springframework.session;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import org.springframework.session.events.SessionDeletedEvent;
+import org.springframework.session.events.SessionExpiredEvent;
+
/**
* A {@link SessionRepository} backed by a {@link java.util.Map} and that uses a {@link MapSession}. By default a
* {@link java.util.concurrent.ConcurrentHashMap} is used, but a custom {@link java.util.Map} can be injected to use
@@ -39,10 +40,10 @@ public class MapSessionRepository implements SessionRepository
*/
private Integer defaultMaxInactiveInterval;
- private final Map sessions;
+ private final Map sessions;
/**
- * Creates an instance backed by a {@link java.util.concurrent.ConcurrentHashMap}
+ * Creates an instance backed by a {@link java.util.concurrent.ConcurrentHashMap}.
*/
public MapSessionRepository() {
this(new ConcurrentHashMap());
@@ -53,8 +54,8 @@ public class MapSessionRepository implements SessionRepository
*
* @param sessions the {@link java.util.Map} to use. Cannot be null.
*/
- public MapSessionRepository(Map sessions) {
- if(sessions == null) {
+ public MapSessionRepository(Map sessions) {
+ if (sessions == null) {
throw new IllegalArgumentException("sessions cannot be null");
}
this.sessions = sessions;
@@ -69,15 +70,15 @@ public class MapSessionRepository implements SessionRepository
}
public void save(ExpiringSession session) {
- sessions.put(session.getId(), new MapSession(session));
+ this.sessions.put(session.getId(), new MapSession(session));
}
public ExpiringSession getSession(String id) {
- ExpiringSession saved = sessions.get(id);
- if(saved == null) {
+ ExpiringSession saved = this.sessions.get(id);
+ if (saved == null) {
return null;
}
- if(saved.isExpired()) {
+ if (saved.isExpired()) {
delete(saved.getId());
return null;
}
@@ -85,13 +86,13 @@ public class MapSessionRepository implements SessionRepository
}
public void delete(String id) {
- sessions.remove(id);
+ this.sessions.remove(id);
}
public ExpiringSession createSession() {
ExpiringSession result = new MapSession();
- if(defaultMaxInactiveInterval != null) {
- result.setMaxInactiveIntervalInSeconds(defaultMaxInactiveInterval);
+ if (this.defaultMaxInactiveInterval != null) {
+ result.setMaxInactiveIntervalInSeconds(this.defaultMaxInactiveInterval);
}
return result;
}
diff --git a/spring-session/src/main/java/org/springframework/session/Session.java b/spring-session/src/main/java/org/springframework/session/Session.java
index 7f94c2eb..5dcb1b36 100644
--- a/spring-session/src/main/java/org/springframework/session/Session.java
+++ b/spring-session/src/main/java/org/springframework/session/Session.java
@@ -1,18 +1,19 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
- * 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
+ * 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
+ * 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.
+ * 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.springframework.session;
import java.util.Set;
@@ -27,7 +28,7 @@ import java.util.Set;
public interface Session {
/**
- * Gets a unique string that identifies the {@link Session}
+ * Gets a unique string that identifies the {@link Session}.
*
* @return a unique string that identifies the {@link Session}
*/
@@ -59,8 +60,8 @@ public interface Session {
void setAttribute(String attributeName, Object attributeValue);
/**
- * Removes the attribute with the provided attribute name
+ * Removes the attribute with the provided attribute name.
* @param attributeName the name of the attribute to remove
*/
void removeAttribute(String attributeName);
-}
\ No newline at end of file
+}
diff --git a/spring-session/src/main/java/org/springframework/session/SessionRepository.java b/spring-session/src/main/java/org/springframework/session/SessionRepository.java
index c8ea352e..ae4c44f8 100644
--- a/spring-session/src/main/java/org/springframework/session/SessionRepository.java
+++ b/spring-session/src/main/java/org/springframework/session/SessionRepository.java
@@ -1,23 +1,25 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
- * 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
+ * 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
+ * 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.
+ * 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.springframework.session;
/**
* A repository interface for managing {@link Session} instances.
*
+ * @param the {@link Session} type
* @author Rob Winch
* @since 1.0
*/
@@ -59,4 +61,4 @@ public interface SessionRepository {
* @param id the {@link org.springframework.session.Session#getId()} to delete
*/
void delete(String id);
-}
\ No newline at end of file
+}
diff --git a/spring-session/src/main/java/org/springframework/session/config/annotation/web/http/EnableSpringHttpSession.java b/spring-session/src/main/java/org/springframework/session/config/annotation/web/http/EnableSpringHttpSession.java
index f3232f69..6133ce8c 100644
--- a/spring-session/src/main/java/org/springframework/session/config/annotation/web/http/EnableSpringHttpSession.java
+++ b/spring-session/src/main/java/org/springframework/session/config/annotation/web/http/EnableSpringHttpSession.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.config.annotation.web.http;
import java.lang.annotation.Documented;
@@ -73,8 +74,8 @@ import org.springframework.session.events.SessionDestroyedEvent;
* @author Rob Winch
* @since 1.1
*/
-@Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
-@Target(value = { java.lang.annotation.ElementType.TYPE })
+@Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
+@Target({ java.lang.annotation.ElementType.TYPE })
@Documented
@Import(SpringHttpSessionConfiguration.class)
@Configuration
diff --git a/spring-session/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java b/spring-session/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java
index a9056bde..b60ceeec 100644
--- a/spring-session/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java
+++ b/spring-session/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.config.annotation.web.http;
import java.util.ArrayList;
@@ -85,7 +86,7 @@ public class SpringHttpSessionConfiguration {
private CookieHttpSessionStrategy defaultHttpSessionStrategy = new CookieHttpSessionStrategy();
- private HttpSessionStrategy httpSessionStrategy = defaultHttpSessionStrategy;
+ private HttpSessionStrategy httpSessionStrategy = this.defaultHttpSessionStrategy;
private List httpSessionListeners = new ArrayList();
@@ -93,22 +94,23 @@ public class SpringHttpSessionConfiguration {
@Bean
public SessionEventHttpSessionListenerAdapter sessionEventHttpSessionListenerAdapter() {
- return new SessionEventHttpSessionListenerAdapter(httpSessionListeners);
+ return new SessionEventHttpSessionListenerAdapter(this.httpSessionListeners);
}
@Bean
public SessionRepositoryFilter extends ExpiringSession> springSessionRepositoryFilter(SessionRepository sessionRepository) {
SessionRepositoryFilter sessionRepositoryFilter = new SessionRepositoryFilter(sessionRepository);
- sessionRepositoryFilter.setServletContext(servletContext);
- if(httpSessionStrategy instanceof MultiHttpSessionStrategy) {
- sessionRepositoryFilter.setHttpSessionStrategy((MultiHttpSessionStrategy) httpSessionStrategy);
- } else {
- sessionRepositoryFilter.setHttpSessionStrategy(httpSessionStrategy);
+ sessionRepositoryFilter.setServletContext(this.servletContext);
+ if (this.httpSessionStrategy instanceof MultiHttpSessionStrategy) {
+ sessionRepositoryFilter.setHttpSessionStrategy((MultiHttpSessionStrategy) this.httpSessionStrategy);
+ }
+ else {
+ sessionRepositoryFilter.setHttpSessionStrategy(this.httpSessionStrategy);
}
return sessionRepositoryFilter;
}
- @Autowired(required=false)
+ @Autowired(required = false)
public void setServletContext(ServletContext servletContext) {
this.servletContext = servletContext;
}
diff --git a/spring-session/src/main/java/org/springframework/session/data/gemfire/AbstractGemFireOperationsSessionRepository.java b/spring-session/src/main/java/org/springframework/session/data/gemfire/AbstractGemFireOperationsSessionRepository.java
index 47230c27..f898aeee 100644
--- a/spring-session/src/main/java/org/springframework/session/data/gemfire/AbstractGemFireOperationsSessionRepository.java
+++ b/spring-session/src/main/java/org/springframework/session/data/gemfire/AbstractGemFireOperationsSessionRepository.java
@@ -1,11 +1,11 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* 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
+ * 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,
@@ -33,8 +33,17 @@ import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
+import com.gemstone.gemfire.DataSerializable;
+import com.gemstone.gemfire.DataSerializer;
+import com.gemstone.gemfire.Delta;
+import com.gemstone.gemfire.Instantiator;
+import com.gemstone.gemfire.InvalidDeltaException;
+import com.gemstone.gemfire.cache.EntryEvent;
+import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.util.CacheListenerAdapter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
@@ -54,20 +63,12 @@ import org.springframework.session.events.SessionExpiredEvent;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
-import com.gemstone.gemfire.DataSerializable;
-import com.gemstone.gemfire.DataSerializer;
-import com.gemstone.gemfire.Delta;
-import com.gemstone.gemfire.Instantiator;
-import com.gemstone.gemfire.InvalidDeltaException;
-import com.gemstone.gemfire.cache.EntryEvent;
-import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.cache.util.CacheListenerAdapter;
-
/**
* AbstractGemFireOperationsSessionRepository is an abstract base class encapsulating functionality common
* to all implementations that support SessionRepository operations backed by GemFire.
*
* @author John Blum
+ * @since 1.1.0
* @see org.springframework.beans.factory.InitializingBean
* @see org.springframework.context.ApplicationEventPublisher
* @see org.springframework.context.ApplicationEventPublisherAware
@@ -79,7 +80,6 @@ import com.gemstone.gemfire.cache.util.CacheListenerAdapter;
* @see org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration
* @see com.gemstone.gemfire.cache.Region
* @see com.gemstone.gemfire.cache.util.CacheListenerAdapter
- * @since 1.1.0
*/
public abstract class AbstractGemFireOperationsSessionRepository extends CacheListenerAdapter
implements InitializingBean, FindByIndexNameSessionRepository,
@@ -140,7 +140,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
* @see org.springframework.context.ApplicationEventPublisher
*/
protected ApplicationEventPublisher getApplicationEventPublisher() {
- return applicationEventPublisher;
+ return this.applicationEventPublisher;
}
/**
@@ -150,7 +150,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
* and manage Session data.
*/
protected String getFullyQualifiedRegionName() {
- return fullyQualifiedRegionName;
+ return this.fullyQualifiedRegionName;
}
/**
@@ -170,7 +170,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
* before it is considered expired.
*/
public int getMaxInactiveIntervalInSeconds() {
- return maxInactiveIntervalInSeconds;
+ return this.maxInactiveIntervalInSeconds;
}
/**
@@ -181,7 +181,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
* @see org.springframework.data.gemfire.GemfireOperations
*/
public GemfireOperations getTemplate() {
- return template;
+ return this.template;
}
/**
@@ -198,7 +198,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
Region region = ((GemfireAccessor) template).getRegion();
- fullyQualifiedRegionName = region.getFullPath();
+ this.fullyQualifiedRegionName = region.getFullPath();
region.getAttributesMutator().addCacheListener(this);
}
@@ -318,7 +318,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
getApplicationEventPublisher().publishEvent(event);
}
catch (Throwable t) {
- logger.error(String.format("error occurred publishing event (%1$s)", event), t);
+ this.logger.error(String.format("error occurred publishing event (%1$s)", event), t);
}
}
@@ -346,7 +346,8 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
static {
Instantiator.register(new Instantiator(GemFireSession.class, 800813552) {
- @Override public DataSerializable newInstance() {
+ @Override
+ public DataSerializable newInstance() {
return new GemFireSession();
}
});
@@ -415,37 +416,37 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public synchronized String getId() {
- return id;
+ return this.id;
}
/* (non-Javadoc) */
public synchronized long getCreationTime() {
- return creationTime;
+ return this.creationTime;
}
/* (non-Javadoc) */
public void setAttribute(String attributeName, Object attributeValue) {
- sessionAttributes.setAttribute(attributeName, attributeValue);
+ this.sessionAttributes.setAttribute(attributeName, attributeValue);
}
/* (non-Javadoc) */
public void removeAttribute(String attributeName) {
- sessionAttributes.removeAttribute(attributeName);
+ this.sessionAttributes.removeAttribute(attributeName);
}
/* (non-Javadoc) */
public T getAttribute(String attributeName) {
- return sessionAttributes.getAttribute(attributeName);
+ return this.sessionAttributes.getAttribute(attributeName);
}
/* (non-Javadoc) */
public Set getAttributeNames() {
- return sessionAttributes.getAttributeNames();
+ return this.sessionAttributes.getAttributeNames();
}
/* (non-Javadoc) */
public GemFireSessionAttributes getAttributes() {
- return sessionAttributes;
+ return this.sessionAttributes;
}
/* (non-Javadoc) */
@@ -470,7 +471,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public synchronized long getLastAccessedTime() {
- return lastAccessedTime;
+ return this.lastAccessedTime;
}
/* (non-Javadoc) */
@@ -481,7 +482,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public synchronized int getMaxInactiveIntervalInSeconds() {
- return maxInactiveIntervalInSeconds;
+ return this.maxInactiveIntervalInSeconds;
}
/* (non-Javadoc) */
@@ -497,7 +498,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
Object authentication = getAttribute(SPRING_SECURITY_CONTEXT);
if (authentication != null) {
- Expression expression = parser.parseExpression("authentication?.name");
+ Expression expression = this.parser.parseExpression("authentication?.name");
principalName = expression.getValue(authentication, String.class);
}
}
@@ -521,7 +522,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
out.writeUTF(principalName);
}
- writeObject(sessionAttributes, out);
+ writeObject(this.sessionAttributes, out);
this.delta = false;
}
@@ -533,8 +534,8 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public synchronized void fromData(DataInput in) throws ClassNotFoundException, IOException {
- id = in.readUTF();
- creationTime = in.readLong();
+ this.id = in.readUTF();
+ this.creationTime = in.readLong();
setLastAccessedTime(in.readLong());
setMaxInactiveIntervalInSeconds(in.readInt());
@@ -544,7 +545,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
setPrincipalName(in.readUTF());
}
- sessionAttributes.from(this.readObject(in));
+ this.sessionAttributes.from(this.readObject(in));
this.delta = false;
}
@@ -556,14 +557,14 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public synchronized boolean hasDelta() {
- return (delta || sessionAttributes.hasDelta());
+ return (this.delta || this.sessionAttributes.hasDelta());
}
/* (non-Javadoc) */
public synchronized void toDelta(DataOutput out) throws IOException {
out.writeLong(getLastAccessedTime());
out.writeInt(getMaxInactiveIntervalInSeconds());
- sessionAttributes.toDelta(out);
+ this.sessionAttributes.toDelta(out);
this.delta = false;
}
@@ -571,7 +572,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
public synchronized void fromDelta(DataInput in) throws IOException {
setLastAccessedTime(in.readLong());
setMaxInactiveIntervalInSeconds(in.readInt());
- sessionAttributes.fromDelta(in);
+ this.sessionAttributes.fromDelta(in);
this.delta = false;
}
@@ -640,7 +641,8 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
static {
Instantiator.register(new Instantiator(GemFireSessionAttributes.class, 800828008) {
- @Override public DataSerializable newInstance() {
+ @Override
+ public DataSerializable newInstance() {
return new GemFireSessionAttributes();
}
});
@@ -663,10 +665,10 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public void setAttribute(String attributeName, Object attributeValue) {
- synchronized (lock) {
+ synchronized (this.lock) {
if (attributeValue != null) {
- if (!attributeValue.equals(sessionAttributes.put(attributeName, attributeValue))) {
- sessionAttributeDeltas.put(attributeName, attributeValue);
+ if (!attributeValue.equals(this.sessionAttributes.put(attributeName, attributeValue))) {
+ this.sessionAttributeDeltas.put(attributeName, attributeValue);
}
}
else {
@@ -677,9 +679,9 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public void removeAttribute(String attributeName) {
- synchronized (lock) {
- if (sessionAttributes.remove(attributeName) != null) {
- sessionAttributeDeltas.put(attributeName, null);
+ synchronized (this.lock) {
+ if (this.sessionAttributes.remove(attributeName) != null) {
+ this.sessionAttributeDeltas.put(attributeName, null);
}
}
}
@@ -687,15 +689,15 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
@SuppressWarnings("unchecked")
public T getAttribute(String attributeName) {
- synchronized (lock) {
- return (T) sessionAttributes.get(attributeName);
+ synchronized (this.lock) {
+ return (T) this.sessionAttributes.get(attributeName);
}
}
/* (non-Javadoc) */
public Set getAttributeNames() {
- synchronized (lock) {
- return Collections.unmodifiableSet(new HashSet(sessionAttributes.keySet()));
+ synchronized (this.lock) {
+ return Collections.unmodifiableSet(new HashSet(this.sessionAttributes.keySet()));
}
}
@@ -709,19 +711,21 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
@SuppressWarnings("all")
public Set> entrySet() {
return new AbstractSet>() {
- @Override public Iterator> iterator() {
- return Collections.unmodifiableMap(sessionAttributes).entrySet().iterator();
+ @Override
+ public Iterator> iterator() {
+ return Collections.unmodifiableMap(GemFireSessionAttributes.this.sessionAttributes).entrySet().iterator();
}
- @Override public int size() {
- return sessionAttributes.size();
+ @Override
+ public int size() {
+ return GemFireSessionAttributes.this.sessionAttributes.size();
}
};
}
/* (non-Javadoc) */
public void from(Session session) {
- synchronized (lock) {
+ synchronized (this.lock) {
for (String attributeName : session.getAttributeNames()) {
setAttribute(attributeName, session.getAttribute(attributeName));
}
@@ -730,7 +734,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public void from(GemFireSessionAttributes sessionAttributes) {
- synchronized (lock) {
+ synchronized (this.lock) {
for (String attributeName : sessionAttributes.getAttributeNames()) {
setAttribute(attributeName, sessionAttributes.getAttribute(attributeName));
}
@@ -739,7 +743,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public void toData(DataOutput out) throws IOException {
- synchronized (lock) {
+ synchronized (this.lock) {
Set attributeNames = getAttributeNames();
out.writeInt(attributeNames.size());
@@ -758,44 +762,44 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
- synchronized (lock) {
+ synchronized (this.lock) {
for (int count = in.readInt(); count > 0; count--) {
setAttribute(in.readUTF(), readObject(in));
}
- sessionAttributeDeltas.clear();
+ this.sessionAttributeDeltas.clear();
}
}
/* (non-Javadoc) */
- T readObject(DataInput in) throws ClassNotFoundException , IOException {
+ T readObject(DataInput in) throws ClassNotFoundException, IOException {
return DataSerializer.readObject(in);
}
/* (non-Javadoc) */
public boolean hasDelta() {
- synchronized (lock) {
- return !sessionAttributeDeltas.isEmpty();
+ synchronized (this.lock) {
+ return !this.sessionAttributeDeltas.isEmpty();
}
}
/* (non-Javadoc) */
public void toDelta(DataOutput out) throws IOException {
- synchronized (lock) {
- out.writeInt(sessionAttributeDeltas.size());
+ synchronized (this.lock) {
+ out.writeInt(this.sessionAttributeDeltas.size());
- for (Map.Entry entry : sessionAttributeDeltas.entrySet()) {
+ for (Map.Entry entry : this.sessionAttributeDeltas.entrySet()) {
out.writeUTF(entry.getKey());
writeObject(entry.getValue(), out);
}
- sessionAttributeDeltas.clear();
+ this.sessionAttributeDeltas.clear();
}
}
/* (non-Javadoc) */
public void fromDelta(DataInput in) throws InvalidDeltaException, IOException {
- synchronized (lock) {
+ synchronized (this.lock) {
try {
int count = in.readInt();
@@ -807,7 +811,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
for (Map.Entry entry : deltas.entrySet()) {
setAttribute(entry.getKey(), entry.getValue());
- sessionAttributeDeltas.remove(entry.getKey());
+ this.sessionAttributeDeltas.remove(entry.getKey());
}
}
catch (ClassNotFoundException e) {
@@ -818,7 +822,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
@Override
public String toString() {
- return sessionAttributes.toString();
+ return this.sessionAttributes.toString();
}
}
diff --git a/spring-session/src/main/java/org/springframework/session/data/gemfire/GemFireOperationsSessionRepository.java b/spring-session/src/main/java/org/springframework/session/data/gemfire/GemFireOperationsSessionRepository.java
index dfa49856..28a00dd7 100644
--- a/spring-session/src/main/java/org/springframework/session/data/gemfire/GemFireOperationsSessionRepository.java
+++ b/spring-session/src/main/java/org/springframework/session/data/gemfire/GemFireOperationsSessionRepository.java
@@ -1,11 +1,11 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* 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
+ * 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,
@@ -19,21 +19,21 @@ package org.springframework.session.data.gemfire;
import java.util.HashMap;
import java.util.Map;
+import com.gemstone.gemfire.cache.query.SelectResults;
+
import org.springframework.data.gemfire.GemfireOperations;
import org.springframework.session.ExpiringSession;
-import com.gemstone.gemfire.cache.query.SelectResults;
-
/**
* The GemFireOperationsSessionRepository class is a Spring SessionRepository implementation that interfaces with
* and uses GemFire to back and store Spring Sessions.
*
* @author John Blum
+ * @since 1.1.0
* @see org.springframework.data.gemfire.GemfireOperations
* @see org.springframework.session.ExpiringSession
* @see org.springframework.session.Session
* @see org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepository
- * @since 1.1.0
*/
public class GemFireOperationsSessionRepository extends AbstractGemFireOperationsSessionRepository {
diff --git a/spring-session/src/main/java/org/springframework/session/data/gemfire/config/annotation/web/http/EnableGemFireHttpSession.java b/spring-session/src/main/java/org/springframework/session/data/gemfire/config/annotation/web/http/EnableGemFireHttpSession.java
index a6229563..b245e52d 100644
--- a/spring-session/src/main/java/org/springframework/session/data/gemfire/config/annotation/web/http/EnableGemFireHttpSession.java
+++ b/spring-session/src/main/java/org/springframework/session/data/gemfire/config/annotation/web/http/EnableGemFireHttpSession.java
@@ -1,11 +1,11 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* 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
+ * 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,
@@ -22,12 +22,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Import;
-
import com.gemstone.gemfire.cache.RegionShortcut;
import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+
/**
* Add this annotation to an {@code @Configuration} class to expose the SessionRepositoryFilter
* as a bean named "springSessionRepositoryFilter" and backed by Pivotal GemFire or Apache Geode.
diff --git a/spring-session/src/main/java/org/springframework/session/data/gemfire/config/annotation/web/http/GemFireHttpSessionConfiguration.java b/spring-session/src/main/java/org/springframework/session/data/gemfire/config/annotation/web/http/GemFireHttpSessionConfiguration.java
index 8ec6f602..d69ba30e 100644
--- a/spring-session/src/main/java/org/springframework/session/data/gemfire/config/annotation/web/http/GemFireHttpSessionConfiguration.java
+++ b/spring-session/src/main/java/org/springframework/session/data/gemfire/config/annotation/web/http/GemFireHttpSessionConfiguration.java
@@ -1,11 +1,11 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* 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
+ * 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,
@@ -18,6 +18,14 @@ package org.springframework.session.data.gemfire.config.annotation.web.http;
import java.util.concurrent.TimeUnit;
+import com.gemstone.gemfire.cache.ExpirationAction;
+import com.gemstone.gemfire.cache.ExpirationAttributes;
+import com.gemstone.gemfire.cache.GemFireCache;
+import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.RegionAttributes;
+import com.gemstone.gemfire.cache.RegionShortcut;
+import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
+
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
@@ -40,19 +48,12 @@ import org.springframework.session.data.gemfire.support.GemFireUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
-import com.gemstone.gemfire.cache.ExpirationAction;
-import com.gemstone.gemfire.cache.ExpirationAttributes;
-import com.gemstone.gemfire.cache.GemFireCache;
-import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.cache.RegionAttributes;
-import com.gemstone.gemfire.cache.RegionShortcut;
-import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
-
/**
* The GemFireHttpSessionConfiguration class is a Spring @Configuration class used to configure and initialize
* Pivotal GemFire (or Apache Geode) as a clustered, replicated HttpSession provider implementation in Spring Session.
*
* @author John Blum
+ * @since 1.1.0
* @see org.springframework.beans.factory.BeanClassLoaderAware
* @see org.springframework.context.annotation.Bean
* @see org.springframework.context.annotation.Configuration
@@ -71,23 +72,40 @@ import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
* @see com.gemstone.gemfire.cache.RegionAttributes
* @see com.gemstone.gemfire.cache.RegionShortcut
* @see com.gemstone.gemfire.cache.client.ClientRegionShortcut
- * @since 1.1.0
*/
@Configuration
public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfiguration
implements BeanClassLoaderAware, ImportAware {
+ /**
+ * The default maximum interval in seconds in which a Session can remain inactive
+ * before it is considered expired.
+ */
public static final int DEFAULT_MAX_INACTIVE_INTERVAL_IN_SECONDS = (int) TimeUnit.MINUTES.toSeconds(30);
protected static final Class SPRING_SESSION_GEMFIRE_REGION_KEY_CONSTRAINT = Object.class;
protected static final Class SPRING_SESSION_GEMFIRE_REGION_VALUE_CONSTRAINT = GemFireSession.class;
+ /**
+ * The default {@link ClientRegionShortcut} used to configure the GemFire ClientCache
+ * Region that will store Spring Sessions.
+ */
public static final ClientRegionShortcut DEFAULT_CLIENT_REGION_SHORTCUT = ClientRegionShortcut.PROXY;
+ /**
+ * The default {@link RegionShortcut} used to configure the GemFire Cache Region that
+ * will store Spring Sessions.
+ */
public static final RegionShortcut DEFAULT_SERVER_REGION_SHORTCUT = RegionShortcut.PARTITION;
+ /**
+ * The default name of the Gemfire (Client)Cache Region used to store Sessions.
+ */
public static final String DEFAULT_SPRING_SESSION_GEMFIRE_REGION_NAME = "ClusteredSpringSessions";
+ /**
+ * The default names of all Session attributes that should be indexed by GemFire.
+ */
public static final String[] DEFAULT_INDEXABLE_SESSION_ATTRIBUTES = new String[0];
private int maxInactiveIntervalInSeconds = DEFAULT_MAX_INACTIVE_INTERVAL_IN_SECONDS;
@@ -120,7 +138,7 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
* @see java.lang.ClassLoader
*/
protected ClassLoader getBeanClassLoader() {
- return beanClassLoader;
+ return this.beanClassLoader;
}
/**
@@ -143,7 +161,7 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
* @see EnableGemFireHttpSession#clientRegionShortcut()
*/
protected ClientRegionShortcut getClientRegionShortcut() {
- return (clientRegionShortcut != null ? clientRegionShortcut : DEFAULT_CLIENT_REGION_SHORTCUT);
+ return (this.clientRegionShortcut != null ? this.clientRegionShortcut : DEFAULT_CLIENT_REGION_SHORTCUT);
}
/**
@@ -164,7 +182,7 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
* @see EnableGemFireHttpSession#indexableSessionAttributes()
*/
protected String[] getIndexableSessionAttributes() {
- return (indexableSessionAttributes != null ? indexableSessionAttributes : DEFAULT_INDEXABLE_SESSION_ATTRIBUTES);
+ return (this.indexableSessionAttributes != null ? this.indexableSessionAttributes : DEFAULT_INDEXABLE_SESSION_ATTRIBUTES);
}
/**
@@ -207,7 +225,7 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
* @see EnableGemFireHttpSession#maxInactiveIntervalInSeconds()
*/
protected int getMaxInactiveIntervalInSeconds() {
- return maxInactiveIntervalInSeconds;
+ return this.maxInactiveIntervalInSeconds;
}
/**
@@ -217,7 +235,7 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
* @see com.gemstone.gemfire.cache.RegionShortcut
*/
public void setServerRegionShortcut(RegionShortcut shortcut) {
- serverRegionShortcut = shortcut;
+ this.serverRegionShortcut = shortcut;
}
/**
@@ -229,7 +247,7 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
* @see EnableGemFireHttpSession#serverRegionShortcut()
*/
protected RegionShortcut getServerRegionShortcut() {
- return (serverRegionShortcut != null ? serverRegionShortcut : DEFAULT_SERVER_REGION_SHORTCUT);
+ return (this.serverRegionShortcut != null ? this.serverRegionShortcut : DEFAULT_SERVER_REGION_SHORTCUT);
}
/**
@@ -251,7 +269,7 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
* @see EnableGemFireHttpSession#regionName()
*/
protected String getSpringSessionGemFireRegionName() {
- return (StringUtils.hasText(springSessionGemFireRegionName) ? springSessionGemFireRegionName
+ return (StringUtils.hasText(this.springSessionGemFireRegionName) ? this.springSessionGemFireRegionName
: DEFAULT_SPRING_SESSION_GEMFIRE_REGION_NAME);
}
@@ -408,7 +426,8 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
@DependsOn(DEFAULT_SPRING_SESSION_GEMFIRE_REGION_NAME)
public IndexFactoryBean principalNameIndex(final GemFireCache gemfireCache) {
IndexFactoryBean index = new IndexFactoryBean() {
- @Override public void afterPropertiesSet() throws Exception {
+ @Override
+ public void afterPropertiesSet() throws Exception {
if (GemFireUtils.isPeer(gemfireCache)) {
super.afterPropertiesSet();
}
@@ -439,7 +458,8 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
@DependsOn(DEFAULT_SPRING_SESSION_GEMFIRE_REGION_NAME)
public IndexFactoryBean sessionAttributesIndex(final GemFireCache gemfireCache) {
IndexFactoryBean index = new IndexFactoryBean() {
- @Override public void afterPropertiesSet() throws Exception {
+ @Override
+ public void afterPropertiesSet() throws Exception {
if (GemFireUtils.isPeer(gemfireCache) && !ObjectUtils.isEmpty(getIndexableSessionAttributes())) {
super.afterPropertiesSet();
}
diff --git a/spring-session/src/main/java/org/springframework/session/data/gemfire/config/annotation/web/http/support/GemFireCacheTypeAwareRegionFactoryBean.java b/spring-session/src/main/java/org/springframework/session/data/gemfire/config/annotation/web/http/support/GemFireCacheTypeAwareRegionFactoryBean.java
index 579a9674..28fea0af 100644
--- a/spring-session/src/main/java/org/springframework/session/data/gemfire/config/annotation/web/http/support/GemFireCacheTypeAwareRegionFactoryBean.java
+++ b/spring-session/src/main/java/org/springframework/session/data/gemfire/config/annotation/web/http/support/GemFireCacheTypeAwareRegionFactoryBean.java
@@ -1,11 +1,11 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* 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
+ * 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,
@@ -16,6 +16,13 @@
package org.springframework.session.data.gemfire.config.annotation.web.http.support;
+import com.gemstone.gemfire.cache.GemFireCache;
+import com.gemstone.gemfire.cache.InterestResultPolicy;
+import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.RegionAttributes;
+import com.gemstone.gemfire.cache.RegionShortcut;
+import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
+
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.data.gemfire.GenericRegionFactoryBean;
@@ -26,18 +33,14 @@ import org.springframework.session.data.gemfire.support.GemFireUtils;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
-import com.gemstone.gemfire.cache.GemFireCache;
-import com.gemstone.gemfire.cache.InterestResultPolicy;
-import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.cache.RegionAttributes;
-import com.gemstone.gemfire.cache.RegionShortcut;
-import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
-
/**
* The GemFireCacheTypeAwareRegionFactoryBean class is a Spring {@link FactoryBean} used to construct, configure
* and initialize the GemFire cache {@link Region} used to store and manage Session state.
*
+ * @param the type of keys
+ * @param the type of values
* @author John Blum
+ * @since 1.1.0
* @see org.springframework.beans.factory.FactoryBean
* @see org.springframework.beans.factory.InitializingBean
* @see org.springframework.data.gemfire.GenericRegionFactoryBean
@@ -49,7 +52,6 @@ import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
* @see com.gemstone.gemfire.cache.RegionAttributes
* @see com.gemstone.gemfire.cache.RegionShortcut
* @see com.gemstone.gemfire.cache.client.ClientRegionShortcut
- * @since 1.1.0
*/
public class GemFireCacheTypeAwareRegionFactoryBean implements FactoryBean>, InitializingBean {
@@ -88,7 +90,7 @@ public class GemFireCacheTypeAwareRegionFactoryBean implements FactoryBean
public void afterPropertiesSet() throws Exception {
GemFireCache gemfireCache = getGemfireCache();
- region = (GemFireUtils.isClient(gemfireCache) ? newClientRegion(gemfireCache)
+ this.region = (GemFireUtils.isClient(gemfireCache) ? newClientRegion(gemfireCache)
: newServerRegion(gemfireCache));
}
@@ -179,7 +181,7 @@ public class GemFireCacheTypeAwareRegionFactoryBean implements FactoryBean
* @see com.gemstone.gemfire.cache.Region
*/
public Region getObject() throws Exception {
- return region;
+ return this.region;
}
/**
@@ -191,7 +193,7 @@ public class GemFireCacheTypeAwareRegionFactoryBean implements FactoryBean
* @see java.lang.Class
*/
public Class> getObjectType() {
- return (region != null ? region.getClass() : Region.class);
+ return (this.region != null ? this.region.getClass() : Region.class);
}
/**
@@ -223,7 +225,7 @@ public class GemFireCacheTypeAwareRegionFactoryBean implements FactoryBean
* @see com.gemstone.gemfire.cache.client.ClientRegionShortcut
*/
protected ClientRegionShortcut getClientRegionShortcut() {
- return (clientRegionShortcut != null ? clientRegionShortcut : DEFAULT_CLIENT_REGION_SHORTCUT);
+ return (this.clientRegionShortcut != null ? this.clientRegionShortcut : DEFAULT_CLIENT_REGION_SHORTCUT);
}
/**
@@ -244,8 +246,8 @@ public class GemFireCacheTypeAwareRegionFactoryBean implements FactoryBean
* @throws IllegalStateException if the {@link GemFireCache} reference is null.
*/
protected GemFireCache getGemfireCache() {
- Assert.state(gemfireCache != null, "A reference to a GemFireCache was not properly configured");
- return gemfireCache;
+ Assert.state(this.gemfireCache != null, "A reference to a GemFireCache was not properly configured");
+ return this.gemfireCache;
}
/**
@@ -267,7 +269,7 @@ public class GemFireCacheTypeAwareRegionFactoryBean implements FactoryBean
* @see com.gemstone.gemfire.cache.RegionAttributes
*/
protected RegionAttributes getRegionAttributes() {
- return regionAttributes;
+ return this.regionAttributes;
}
/**
@@ -287,7 +289,7 @@ public class GemFireCacheTypeAwareRegionFactoryBean implements FactoryBean
* @see com.gemstone.gemfire.cache.Region#getName()
*/
protected String getRegionName() {
- return (StringUtils.hasText(regionName) ? regionName : DEFAULT_SPRING_SESSION_GEMFIRE_REGION_NAME);
+ return (StringUtils.hasText(this.regionName) ? this.regionName : DEFAULT_SPRING_SESSION_GEMFIRE_REGION_NAME);
}
/**
@@ -308,7 +310,7 @@ public class GemFireCacheTypeAwareRegionFactoryBean implements FactoryBean
* @see com.gemstone.gemfire.cache.RegionShortcut
*/
protected RegionShortcut getServerRegionShortcut() {
- return (serverRegionShortcut != null ? serverRegionShortcut : DEFAULT_SERVER_REGION_SHORTCUT);
+ return (this.serverRegionShortcut != null ? this.serverRegionShortcut : DEFAULT_SERVER_REGION_SHORTCUT);
}
}
diff --git a/spring-session/src/main/java/org/springframework/session/data/gemfire/support/GemFireUtils.java b/spring-session/src/main/java/org/springframework/session/data/gemfire/support/GemFireUtils.java
index 2a510e24..48234c40 100644
--- a/spring-session/src/main/java/org/springframework/session/data/gemfire/support/GemFireUtils.java
+++ b/spring-session/src/main/java/org/springframework/session/data/gemfire/support/GemFireUtils.java
@@ -1,11 +1,11 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* 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
+ * 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,
diff --git a/spring-session/src/main/java/org/springframework/session/data/redis/RedisFlushMode.java b/spring-session/src/main/java/org/springframework/session/data/redis/RedisFlushMode.java
index 089d2e93..6847a8da 100644
--- a/spring-session/src/main/java/org/springframework/session/data/redis/RedisFlushMode.java
+++ b/spring-session/src/main/java/org/springframework/session/data/redis/RedisFlushMode.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.data.redis;
import org.springframework.session.SessionRepository;
diff --git a/spring-session/src/main/java/org/springframework/session/data/redis/RedisOperationsSessionRepository.java b/spring-session/src/main/java/org/springframework/session/data/redis/RedisOperationsSessionRepository.java
index 57d0f6a8..92092a49 100644
--- a/spring-session/src/main/java/org/springframework/session/data/redis/RedisOperationsSessionRepository.java
+++ b/spring-session/src/main/java/org/springframework/session/data/redis/RedisOperationsSessionRepository.java
@@ -1,18 +1,19 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
- * 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
+ * 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
+ * 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.
+ * 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.springframework.session.data.redis;
import java.util.Collections;
@@ -23,6 +24,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.redis.connection.Message;
@@ -245,9 +247,8 @@ import org.springframework.util.Assert;
* if the TTL on that key is expired.
*
*
- * @since 1.0
- *
* @author Rob Winch
+ * @since 1.0
*/
public class RedisOperationsSessionRepository implements FindByIndexNameSessionRepository, MessageListener {
private static final Log logger = LogFactory.getLog(RedisOperationsSessionRepository.class);
@@ -257,22 +258,22 @@ public class RedisOperationsSessionRepository implements FindByIndexNameSessionR
static PrincipalNameResolver PRINCIPAL_NAME_RESOLVER = new PrincipalNameResolver();
/**
- * The default prefix for each key and channel in Redis used by Spring Session
+ * The default prefix for each key and channel in Redis used by Spring Session.
*/
static final String DEFAULT_SPRING_SESSION_REDIS_PREFIX = "spring:session:";
/**
- * The key in the Hash representing {@link org.springframework.session.ExpiringSession#getCreationTime()}
+ * The key in the Hash representing {@link org.springframework.session.ExpiringSession#getCreationTime()}.
*/
static final String CREATION_TIME_ATTR = "creationTime";
/**
- * The key in the Hash representing {@link org.springframework.session.ExpiringSession#getMaxInactiveIntervalInSeconds()}
+ * The key in the Hash representing {@link org.springframework.session.ExpiringSession#getMaxInactiveIntervalInSeconds()}.
*/
static final String MAX_INACTIVE_ATTR = "maxInactiveInterval";
/**
- * The key in the Hash representing {@link org.springframework.session.ExpiringSession#getLastAccessedTime()}
+ * The key in the Hash representing {@link org.springframework.session.ExpiringSession#getLastAccessedTime()}.
*/
static final String LAST_ACCESSED_ATTR = "lastAccessedTime";
@@ -288,7 +289,7 @@ public class RedisOperationsSessionRepository implements FindByIndexNameSessionR
*/
private String keyPrefix = DEFAULT_SPRING_SESSION_REDIS_PREFIX;
- private final RedisOperations sessionRedisOperations;
+ private final RedisOperations sessionRedisOperations;
private final RedisSessionExpirationPolicy expirationPolicy;
@@ -376,14 +377,14 @@ public class RedisOperationsSessionRepository implements FindByIndexNameSessionR
public void save(RedisSession session) {
session.saveDelta();
- if(session.isNew()) {
+ if (session.isNew()) {
String sessionCreatedKey = getSessionCreatedChannel(session.getId());
this.sessionRedisOperations.convertAndSend(sessionCreatedKey, session.delta);
session.setNew(false);
}
}
- @Scheduled(cron="0 * * * * *")
+ @Scheduled(cron = "0 * * * * *")
public void cleanupExpiredSessions() {
this.expirationPolicy.cleanExpiredSessions();
}
@@ -392,16 +393,16 @@ public class RedisOperationsSessionRepository implements FindByIndexNameSessionR
return getSession(id, false);
}
- public Map findByIndexNameAndIndexValue(String indexName, String indexValue) {
- if(!PRINCIPAL_NAME_INDEX_NAME.equals(indexName)) {
+ public Map findByIndexNameAndIndexValue(String indexName, String indexValue) {
+ if (!PRINCIPAL_NAME_INDEX_NAME.equals(indexName)) {
return Collections.emptyMap();
}
String principalKey = getPrincipalKey(indexValue);
- Set sessionIds = sessionRedisOperations.boundSetOps(principalKey).members();
- Map sessions = new HashMap(sessionIds.size());
- for(Object id : sessionIds) {
+ Set sessionIds = this.sessionRedisOperations.boundSetOps(principalKey).members();
+ Map sessions = new HashMap(sessionIds.size());
+ for (Object id : sessionIds) {
RedisSession session = getSession((String) id);
- if(session != null) {
+ if (session != null) {
sessions.put(session.getId(), session);
}
}
@@ -409,21 +410,21 @@ public class RedisOperationsSessionRepository implements FindByIndexNameSessionR
}
/**
- *
+ * Gets the session.
* @param id the session id
* @param allowExpired
* if true, will also include expired sessions that have not been
* deleted. If false, will ensure expired sessions are not
* returned.
- * @return
+ * @return the Redis session
*/
private RedisSession getSession(String id, boolean allowExpired) {
Map entries = getSessionBoundHashOperations(id).entries();
- if(entries.isEmpty()) {
+ if (entries.isEmpty()) {
return null;
}
MapSession loaded = loadSession(id, entries);
- if(!allowExpired && loaded.isExpired()) {
+ if (!allowExpired && loaded.isExpired()) {
return null;
}
RedisSession result = new RedisSession(loaded);
@@ -433,15 +434,18 @@ public class RedisOperationsSessionRepository implements FindByIndexNameSessionR
private MapSession loadSession(String id, Map entries) {
MapSession loaded = new MapSession(id);
- for(Map.Entry entry : entries.entrySet()) {
+ for (Map.Entry entry : entries.entrySet()) {
String key = (String) entry.getKey();
- if(CREATION_TIME_ATTR.equals(key)) {
+ if (CREATION_TIME_ATTR.equals(key)) {
loaded.setCreationTime((Long) entry.getValue());
- } else if(MAX_INACTIVE_ATTR.equals(key)) {
+ }
+ else if (MAX_INACTIVE_ATTR.equals(key)) {
loaded.setMaxInactiveIntervalInSeconds((Integer) entry.getValue());
- } else if(LAST_ACCESSED_ATTR.equals(key)) {
+ }
+ else if (LAST_ACCESSED_ATTR.equals(key)) {
loaded.setLastAccessedTime((Long) entry.getValue());
- } else if(key.startsWith(SESSION_ATTR_PREFIX)) {
+ }
+ else if (key.startsWith(SESSION_ATTR_PREFIX)) {
loaded.setAttribute(key.substring(SESSION_ATTR_PREFIX.length()), entry.getValue());
}
}
@@ -450,12 +454,12 @@ public class RedisOperationsSessionRepository implements FindByIndexNameSessionR
public void delete(String sessionId) {
RedisSession session = getSession(sessionId, true);
- if(session == null) {
+ if (session == null) {
return;
}
cleanupPrincipalIndex(session);
- expirationPolicy.onDelete(session);
+ this.expirationPolicy.onDelete(session);
String expireKey = getExpiredKey(session.getId());
this.sessionRedisOperations.delete(expireKey);
@@ -466,8 +470,8 @@ public class RedisOperationsSessionRepository implements FindByIndexNameSessionR
public RedisSession createSession() {
RedisSession redisSession = new RedisSession();
- if(defaultMaxInactiveInterval != null) {
- redisSession.setMaxInactiveIntervalInSeconds(defaultMaxInactiveInterval);
+ if (this.defaultMaxInactiveInterval != null) {
+ redisSession.setMaxInactiveIntervalInSeconds(this.defaultMaxInactiveInterval);
}
return redisSession;
}
@@ -476,42 +480,43 @@ public class RedisOperationsSessionRepository implements FindByIndexNameSessionR
public void onMessage(Message message, byte[] pattern) {
byte[] messageChannel = message.getChannel();
byte[] messageBody = message.getBody();
- if(messageChannel == null || messageBody == null) {
+ if (messageChannel == null || messageBody == null) {
return;
}
String channel = new String(messageChannel);
- if(channel.startsWith(getSessionCreatedChannelPrefix())) {
+ if (channel.startsWith(getSessionCreatedChannelPrefix())) {
// TODO: is this thread safe?
- Map loaded = (Map) defaultSerializer.deserialize(message.getBody());
+ Map loaded = (Map) this.defaultSerializer.deserialize(message.getBody());
handleCreated(loaded, channel);
return;
}
String body = new String(messageBody);
- if(!body.startsWith(getExpiredKeyPrefix())) {
+ if (!body.startsWith(getExpiredKeyPrefix())) {
return;
}
boolean isDeleted = channel.endsWith(":del");
- if(isDeleted || channel.endsWith(":expired")) {
+ if (isDeleted || channel.endsWith(":expired")) {
int beginIndex = body.lastIndexOf(":") + 1;
int endIndex = body.length();
String sessionId = body.substring(beginIndex, endIndex);
RedisSession session = getSession(sessionId, true);
- if(logger.isDebugEnabled()) {
+ if (logger.isDebugEnabled()) {
logger.debug("Publishing SessionDestroyedEvent for session " + sessionId);
}
cleanupPrincipalIndex(session);
- if(isDeleted) {
+ if (isDeleted) {
handleDeleted(sessionId, session);
- } else {
+ }
+ else {
handleExpired(sessionId, session);
}
@@ -520,34 +525,36 @@ public class RedisOperationsSessionRepository implements FindByIndexNameSessionR
}
private void cleanupPrincipalIndex(RedisSession session) {
- if(session == null) {
+ if (session == null) {
return;
}
String sessionId = session.getId();
String principal = PRINCIPAL_NAME_RESOLVER.resolvePrincipal(session);
- if(principal != null) {
- sessionRedisOperations.boundSetOps(getPrincipalKey(principal)).remove(sessionId);
+ if (principal != null) {
+ this.sessionRedisOperations.boundSetOps(getPrincipalKey(principal)).remove(sessionId);
}
}
- public void handleCreated(Map loaded, String channel) {
+ public void handleCreated(Map loaded, String channel) {
String id = channel.substring(channel.lastIndexOf(":") + 1);
ExpiringSession session = loadSession(id, loaded);
publishEvent(new SessionCreatedEvent(this, session));
}
private void handleDeleted(String sessionId, RedisSession session) {
- if(session == null) {
+ if (session == null) {
publishEvent(new SessionDeletedEvent(this, sessionId));
- } else {
+ }
+ else {
publishEvent(new SessionDeletedEvent(this, session));
}
}
private void handleExpired(String sessionId, RedisSession session) {
- if(session == null) {
+ if (session == null) {
publishEvent(new SessionExpiredEvent(this, sessionId));
- } else {
+ }
+ else {
publishEvent(new SessionExpiredEvent(this, session));
}
}
@@ -605,7 +612,7 @@ public class RedisOperationsSessionRepository implements FindByIndexNameSessionR
}
/**
- * Gets the {@link BoundHashOperations} to operate on a {@link Session}
+ * Gets the {@link BoundHashOperations} to operate on a {@link Session}.
* @param sessionId the id of the {@link Session} to work with
* @return the {@link BoundHashOperations} to operate on a {@link Session}
*/
@@ -615,17 +622,17 @@ public class RedisOperationsSessionRepository implements FindByIndexNameSessionR
}
/**
- * Gets the key for the specified session attribute
+ * Gets the key for the specified session attribute.
*
- * @param attributeName
- * @return
+ * @param attributeName the attribute name
+ * @return the attribute key name
*/
static String getSessionAttrNameKey(String attributeName) {
return SESSION_ATTR_PREFIX + attributeName;
}
- private static RedisTemplate createDefaultTemplate(RedisConnectionFactory connectionFactory) {
- Assert.notNull(connectionFactory,"connectionFactory cannot be null");
+ private static RedisTemplate createDefaultTemplate(RedisConnectionFactory connectionFactory) {
+ Assert.notNull(connectionFactory, "connectionFactory cannot be null");
RedisTemplate template = new RedisTemplate();
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());
@@ -640,13 +647,13 @@ public class RedisOperationsSessionRepository implements FindByIndexNameSessionR
* {@link org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession#saveDelta()} is invoked
* all the attributes that have been changed will be persisted.
*
- * @since 1.0
* @author Rob Winch
+ * @since 1.0
*/
final class RedisSession implements ExpiringSession {
private final MapSession cached;
private Long originalLastAccessTime;
- private Map delta = new HashMap();
+ private Map delta = new HashMap();
private boolean isNew;
private String originalPrincipalName;
@@ -655,15 +662,15 @@ public class RedisOperationsSessionRepository implements FindByIndexNameSessionR
*/
RedisSession() {
this(new MapSession());
- delta.put(CREATION_TIME_ATTR, getCreationTime());
- delta.put(MAX_INACTIVE_ATTR, getMaxInactiveIntervalInSeconds());
- delta.put(LAST_ACCESSED_ATTR, getLastAccessedTime());
+ this.delta.put(CREATION_TIME_ATTR, getCreationTime());
+ this.delta.put(MAX_INACTIVE_ATTR, getMaxInactiveIntervalInSeconds());
+ this.delta.put(LAST_ACCESSED_ATTR, getLastAccessedTime());
this.isNew = true;
flushImmediateIfNecessary();
}
/**
- * Creates a new instance from the provided {@link MapSession}
+ * Creates a new instance from the provided {@link MapSession}.
*
* @param cached the {@MapSession} that represents the persisted session that was retrieved. Cannot be null.
*/
@@ -678,64 +685,64 @@ public class RedisOperationsSessionRepository implements FindByIndexNameSessionR
}
public void setLastAccessedTime(long lastAccessedTime) {
- cached.setLastAccessedTime(lastAccessedTime);
- delta.put(LAST_ACCESSED_ATTR, getLastAccessedTime());
+ this.cached.setLastAccessedTime(lastAccessedTime);
+ this.delta.put(LAST_ACCESSED_ATTR, getLastAccessedTime());
flushImmediateIfNecessary();
}
public boolean isExpired() {
- return cached.isExpired();
+ return this.cached.isExpired();
}
public boolean isNew() {
- return isNew;
+ return this.isNew;
}
public long getCreationTime() {
- return cached.getCreationTime();
+ return this.cached.getCreationTime();
}
public String getId() {
- return cached.getId();
+ return this.cached.getId();
}
public long getLastAccessedTime() {
- return cached.getLastAccessedTime();
+ return this.cached.getLastAccessedTime();
}
public void setMaxInactiveIntervalInSeconds(int interval) {
- cached.setMaxInactiveIntervalInSeconds(interval);
- delta.put(MAX_INACTIVE_ATTR, getMaxInactiveIntervalInSeconds());
+ this.cached.setMaxInactiveIntervalInSeconds(interval);
+ this.delta.put(MAX_INACTIVE_ATTR, getMaxInactiveIntervalInSeconds());
flushImmediateIfNecessary();
}
public int getMaxInactiveIntervalInSeconds() {
- return cached.getMaxInactiveIntervalInSeconds();
+ return this.cached.getMaxInactiveIntervalInSeconds();
}
@SuppressWarnings("unchecked")
public Object getAttribute(String attributeName) {
- return cached.getAttribute(attributeName);
+ return this.cached.getAttribute(attributeName);
}
public Set getAttributeNames() {
- return cached.getAttributeNames();
+ return this.cached.getAttributeNames();
}
public void setAttribute(String attributeName, Object attributeValue) {
- cached.setAttribute(attributeName, attributeValue);
- delta.put(getSessionAttrNameKey(attributeName), attributeValue);
+ this.cached.setAttribute(attributeName, attributeValue);
+ this.delta.put(getSessionAttrNameKey(attributeName), attributeValue);
flushImmediateIfNecessary();
}
public void removeAttribute(String attributeName) {
- cached.removeAttribute(attributeName);
- delta.put(getSessionAttrNameKey(attributeName), null);
+ this.cached.removeAttribute(attributeName);
+ this.delta.put(getSessionAttrNameKey(attributeName), null);
flushImmediateIfNecessary();
}
private void flushImmediateIfNecessary() {
- if(redisFlushMode == RedisFlushMode.IMMEDIATE) {
+ if (RedisOperationsSessionRepository.this.redisFlushMode == RedisFlushMode.IMMEDIATE) {
saveDelta();
}
}
@@ -745,40 +752,43 @@ public class RedisOperationsSessionRepository implements FindByIndexNameSessionR
*/
private void saveDelta() {
String sessionId = getId();
- getSessionBoundHashOperations(sessionId).putAll(delta);
+ getSessionBoundHashOperations(sessionId).putAll(this.delta);
String principalSessionKey = getSessionAttrNameKey(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME);
String securityPrincipalSessionKey = getSessionAttrNameKey(SPRING_SECURITY_CONTEXT);
- if(delta.containsKey(principalSessionKey) || delta.containsKey(securityPrincipalSessionKey)) {
- if(originalPrincipalName != null) {
- String originalPrincipalRedisKey = getPrincipalKey((String) originalPrincipalName);
- sessionRedisOperations.boundSetOps(originalPrincipalRedisKey).remove(sessionId);
+ if (this.delta.containsKey(principalSessionKey) || this.delta.containsKey(securityPrincipalSessionKey)) {
+ if (this.originalPrincipalName != null) {
+ String originalPrincipalRedisKey = getPrincipalKey((String) this.originalPrincipalName);
+ RedisOperationsSessionRepository.this.sessionRedisOperations.boundSetOps(originalPrincipalRedisKey).remove(sessionId);
}
String principal = PRINCIPAL_NAME_RESOLVER.resolvePrincipal(this);
- originalPrincipalName = principal;
- if(principal != null) {
+ this.originalPrincipalName = principal;
+ if (principal != null) {
String principalRedisKey = getPrincipalKey(principal);
- sessionRedisOperations.boundSetOps(principalRedisKey).add(sessionId);
+ RedisOperationsSessionRepository.this.sessionRedisOperations.boundSetOps(principalRedisKey).add(sessionId);
}
}
- delta = new HashMap(delta.size());
+ this.delta = new HashMap(this.delta.size());
- Long originalExpiration = originalLastAccessTime == null ? null : originalLastAccessTime + TimeUnit.SECONDS.toMillis(getMaxInactiveIntervalInSeconds()) ;
- expirationPolicy.onExpirationUpdated(originalExpiration, this);
+ Long originalExpiration = this.originalLastAccessTime == null ? null : this.originalLastAccessTime + TimeUnit.SECONDS.toMillis(getMaxInactiveIntervalInSeconds());
+ RedisOperationsSessionRepository.this.expirationPolicy.onExpirationUpdated(originalExpiration, this);
}
}
+ /**
+ * Principal name resolver helper class.
+ */
static class PrincipalNameResolver {
private SpelExpressionParser parser = new SpelExpressionParser();
public String resolvePrincipal(Session session) {
String principalName = session.getAttribute(PRINCIPAL_NAME_INDEX_NAME);
- if(principalName != null) {
+ if (principalName != null) {
return principalName;
}
Object authentication = session.getAttribute(SPRING_SECURITY_CONTEXT);
- if(authentication != null) {
- Expression expression = parser.parseExpression("authentication?.name");
+ if (authentication != null) {
+ Expression expression = this.parser.parseExpression("authentication?.name");
return expression.getValue(authentication, String.class);
}
return null;
diff --git a/spring-session/src/main/java/org/springframework/session/data/redis/RedisSessionExpirationPolicy.java b/spring-session/src/main/java/org/springframework/session/data/redis/RedisSessionExpirationPolicy.java
index c8782a26..cb986e8f 100644
--- a/spring-session/src/main/java/org/springframework/session/data/redis/RedisSessionExpirationPolicy.java
+++ b/spring-session/src/main/java/org/springframework/session/data/redis/RedisSessionExpirationPolicy.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.data.redis;
import java.util.Calendar;
@@ -22,6 +23,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.springframework.data.redis.core.BoundSetOperations;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.session.ExpiringSession;
@@ -49,12 +51,12 @@ final class RedisSessionExpirationPolicy {
private static final Log logger = LogFactory.getLog(RedisSessionExpirationPolicy.class);
- private final RedisOperations redis;
+ private final RedisOperations redis;
private final RedisOperationsSessionRepository redisSession;
- public RedisSessionExpirationPolicy(
- RedisOperations sessionRedisOperations, RedisOperationsSessionRepository redisSession) {
+ RedisSessionExpirationPolicy(
+ RedisOperations sessionRedisOperations, RedisOperationsSessionRepository redisSession) {
super();
this.redis = sessionRedisOperations;
this.redisSession = redisSession;
@@ -63,23 +65,23 @@ final class RedisSessionExpirationPolicy {
public void onDelete(ExpiringSession session) {
long toExpire = roundUpToNextMinute(expiresInMillis(session));
String expireKey = getExpirationKey(toExpire);
- redis.boundSetOps(expireKey).remove(session.getId());
+ this.redis.boundSetOps(expireKey).remove(session.getId());
}
public void onExpirationUpdated(Long originalExpirationTimeInMilli, ExpiringSession session) {
String keyToExpire = "expires:" + session.getId();
long toExpire = roundUpToNextMinute(expiresInMillis(session));
- if(originalExpirationTimeInMilli != null) {
+ if (originalExpirationTimeInMilli != null) {
long originalRoundedUp = roundUpToNextMinute(originalExpirationTimeInMilli);
- if(toExpire != originalRoundedUp) {
+ if (toExpire != originalRoundedUp) {
String expireKey = getExpirationKey(originalRoundedUp);
- redis.boundSetOps(expireKey).remove(keyToExpire);
+ this.redis.boundSetOps(expireKey).remove(keyToExpire);
}
}
String expireKey = getExpirationKey(toExpire);
- BoundSetOperations expireOperations = redis.boundSetOps(expireKey);
+ BoundSetOperations expireOperations = this.redis.boundSetOps(expireKey);
expireOperations.add(keyToExpire);
long sessionExpireInSeconds = session.getMaxInactiveIntervalInSeconds();
@@ -87,13 +89,14 @@ final class RedisSessionExpirationPolicy {
String sessionKey = getSessionKey(keyToExpire);
expireOperations.expire(fiveMinutesAfterExpires, TimeUnit.SECONDS);
- if(sessionExpireInSeconds == 0) {
- redis.delete(sessionKey);
- } else {
- redis.boundValueOps(sessionKey).append("");
- redis.boundValueOps(sessionKey).expire(sessionExpireInSeconds, TimeUnit.SECONDS);
+ if (sessionExpireInSeconds == 0) {
+ this.redis.delete(sessionKey);
}
- redis.boundHashOps(getSessionKey(session.getId())).expire(fiveMinutesAfterExpires, TimeUnit.SECONDS);
+ else {
+ this.redis.boundValueOps(sessionKey).append("");
+ this.redis.boundValueOps(sessionKey).expire(sessionExpireInSeconds, TimeUnit.SECONDS);
+ }
+ this.redis.boundHashOps(getSessionKey(session.getId())).expire(fiveMinutesAfterExpires, TimeUnit.SECONDS);
}
String getExpirationKey(long expires) {
@@ -108,14 +111,14 @@ final class RedisSessionExpirationPolicy {
long now = System.currentTimeMillis();
long prevMin = roundDownMinute(now);
- if(logger.isDebugEnabled()) {
- logger.debug("Cleaning up sessions expiring at "+ new Date(prevMin));
+ if (logger.isDebugEnabled()) {
+ logger.debug("Cleaning up sessions expiring at " + new Date(prevMin));
}
String expirationKey = getExpirationKey(prevMin);
- Set sessionsToExpire = redis.boundSetOps(expirationKey).members();
- redis.delete(expirationKey);
- for(Object session : sessionsToExpire) {
+ Set sessionsToExpire = this.redis.boundSetOps(expirationKey).members();
+ this.redis.delete(expirationKey);
+ for (Object session : sessionsToExpire) {
String sessionKey = getSessionKey((String) session);
touch(sessionKey);
}
@@ -125,10 +128,10 @@ final class RedisSessionExpirationPolicy {
* By trying to access the session we only trigger a deletion if it the TTL is expired. This is done to handle
* https://github.com/spring-projects/spring-session/issues/93
*
- * @param key
+ * @param key the key
*/
private void touch(String key) {
- redis.hasKey(key);
+ this.redis.hasKey(key);
}
static long expiresInMillis(ExpiringSession session) {
diff --git a/spring-session/src/main/java/org/springframework/session/data/redis/SessionMessageListener.java b/spring-session/src/main/java/org/springframework/session/data/redis/SessionMessageListener.java
index a9ca014b..26111583 100644
--- a/spring-session/src/main/java/org/springframework/session/data/redis/SessionMessageListener.java
+++ b/spring-session/src/main/java/org/springframework/session/data/redis/SessionMessageListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,10 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.data.redis;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.redis.connection.Message;
@@ -42,7 +44,7 @@ public class SessionMessageListener implements MessageListener {
private final ApplicationEventPublisher eventPublisher;
/**
- * Creates a new instance
+ * Creates a new instance.
*
* @param eventPublisher the {@link ApplicationEventPublisher} to use. Cannot be null.
*/
@@ -54,15 +56,15 @@ public class SessionMessageListener implements MessageListener {
public void onMessage(Message message, byte[] pattern) {
byte[] messageChannel = message.getChannel();
byte[] messageBody = message.getBody();
- if(messageChannel == null || messageBody == null) {
+ if (messageChannel == null || messageBody == null) {
return;
}
String channel = new String(messageChannel);
- if(!(channel.endsWith(":del") || channel.endsWith(":expired"))) {
+ if (!(channel.endsWith(":del") || channel.endsWith(":expired"))) {
return;
}
String body = new String(messageBody);
- if(!body.startsWith("spring:session:sessions:")) {
+ if (!body.startsWith("spring:session:sessions:")) {
return;
}
@@ -70,13 +72,14 @@ public class SessionMessageListener implements MessageListener {
int endIndex = body.length();
String sessionId = body.substring(beginIndex, endIndex);
- if(logger.isDebugEnabled()) {
+ if (logger.isDebugEnabled()) {
logger.debug("Publishing SessionDestroyedEvent for session " + sessionId);
}
- if(channel.endsWith(":del")) {
+ if (channel.endsWith(":del")) {
publishEvent(new SessionDeletedEvent(this, sessionId));
- } else {
+ }
+ else {
publishEvent(new SessionExpiredEvent(this, sessionId));
}
}
diff --git a/spring-session/src/main/java/org/springframework/session/data/redis/config/ConfigureNotifyKeyspaceEventsAction.java b/spring-session/src/main/java/org/springframework/session/data/redis/config/ConfigureNotifyKeyspaceEventsAction.java
index 2a6ea150..6aef3ad5 100644
--- a/spring-session/src/main/java/org/springframework/session/data/redis/config/ConfigureNotifyKeyspaceEventsAction.java
+++ b/spring-session/src/main/java/org/springframework/session/data/redis/config/ConfigureNotifyKeyspaceEventsAction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.data.redis.config;
import java.util.List;
@@ -49,17 +50,17 @@ public class ConfigureNotifyKeyspaceEventsAction implements ConfigureRedisAction
public void configure(RedisConnection connection) {
String notifyOptions = getNotifyOptions(connection);
String customizedNotifyOptions = notifyOptions;
- if(!customizedNotifyOptions.contains("E")) {
+ if (!customizedNotifyOptions.contains("E")) {
customizedNotifyOptions += "E";
}
boolean A = customizedNotifyOptions.contains("A");
- if(!(A || customizedNotifyOptions.contains("g"))) {
+ if (!(A || customizedNotifyOptions.contains("g"))) {
customizedNotifyOptions += "g";
}
- if(!(A || customizedNotifyOptions.contains("x"))) {
+ if (!(A || customizedNotifyOptions.contains("x"))) {
customizedNotifyOptions += "x";
}
- if(!notifyOptions.equals(customizedNotifyOptions)) {
+ if (!notifyOptions.equals(customizedNotifyOptions)) {
connection.setConfig(CONFIG_NOTIFY_KEYSPACE_EVENTS, customizedNotifyOptions);
}
}
@@ -67,11 +68,12 @@ public class ConfigureNotifyKeyspaceEventsAction implements ConfigureRedisAction
private String getNotifyOptions(RedisConnection connection) {
try {
List config = connection.getConfig(CONFIG_NOTIFY_KEYSPACE_EVENTS);
- if(config.size() < 2) {
+ if (config.size() < 2) {
return "";
}
return config.get(1);
- } catch(InvalidDataAccessApiUsageException e) {
+ }
+ catch (InvalidDataAccessApiUsageException e) {
throw new IllegalStateException("Unable to configure Redis to keyspace notifications. See http://docs.spring.io/spring-session/docs/current/reference/html5/#api-redisoperationssessionrepository-sessiondestroyedevent", e);
}
}
diff --git a/spring-session/src/main/java/org/springframework/session/data/redis/config/ConfigureRedisAction.java b/spring-session/src/main/java/org/springframework/session/data/redis/config/ConfigureRedisAction.java
index 28fabbbb..d896e7d0 100644
--- a/spring-session/src/main/java/org/springframework/session/data/redis/config/ConfigureRedisAction.java
+++ b/spring-session/src/main/java/org/springframework/session/data/redis/config/ConfigureRedisAction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.data.redis.config;
import org.springframework.data.redis.connection.RedisConnection;
diff --git a/spring-session/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/EnableRedisHttpSession.java b/spring-session/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/EnableRedisHttpSession.java
index 1f89b2fe..eee65100 100644
--- a/spring-session/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/EnableRedisHttpSession.java
+++ b/spring-session/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/EnableRedisHttpSession.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.data.redis.config.annotation.web.http;
import java.lang.annotation.Documented;
@@ -52,8 +53,8 @@ import org.springframework.session.data.redis.RedisFlushMode;
* @since 1.0
* @see EnableSpringHttpSession
*/
-@Retention(value=java.lang.annotation.RetentionPolicy.RUNTIME)
-@Target(value={java.lang.annotation.ElementType.TYPE})
+@Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
+@Target({java.lang.annotation.ElementType.TYPE})
@Documented
@Import(RedisHttpSessionConfiguration.class)
@Configuration
@@ -96,4 +97,4 @@ public @interface EnableRedisHttpSession {
* @since 1.1
*/
RedisFlushMode redisFlushMode() default RedisFlushMode.ON_SAVE;
-}
\ No newline at end of file
+}
diff --git a/spring-session/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.java b/spring-session/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.java
index e6bcdf19..0d8e24c2 100644
--- a/spring-session/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.java
+++ b/spring-session/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.data.redis.config.annotation.web.http;
import java.util.Arrays;
@@ -80,11 +81,11 @@ public class RedisHttpSessionConfiguration extends SpringHttpSessionConfiguratio
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
- if (redisTaskExecutor != null) {
- container.setTaskExecutor(redisTaskExecutor);
+ if (this.redisTaskExecutor != null) {
+ container.setTaskExecutor(this.redisTaskExecutor);
}
- if (redisSubscriptionExecutor != null) {
- container.setSubscriptionExecutor(redisSubscriptionExecutor);
+ if (this.redisSubscriptionExecutor != null) {
+ container.setSubscriptionExecutor(this.redisSubscriptionExecutor);
}
container.addMessageListener(messageListener,
Arrays.asList(new PatternTopic("__keyevent@*:del"), new PatternTopic("__keyevent@*:expired")));
@@ -93,12 +94,12 @@ public class RedisHttpSessionConfiguration extends SpringHttpSessionConfiguratio
}
@Bean
- public RedisTemplate sessionRedisTemplate(RedisConnectionFactory connectionFactory) {
+ public RedisTemplate sessionRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate template = new RedisTemplate();
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());
- if(defaultRedisSerializer != null) {
- template.setDefaultSerializer(defaultRedisSerializer);
+ if (this.defaultRedisSerializer != null) {
+ template.setDefaultSerializer(this.defaultRedisSerializer);
}
template.setConnectionFactory(connectionFactory);
return template;
@@ -108,17 +109,17 @@ public class RedisHttpSessionConfiguration extends SpringHttpSessionConfiguratio
public RedisOperationsSessionRepository sessionRepository(@Qualifier("sessionRedisTemplate") RedisOperations sessionRedisTemplate, ApplicationEventPublisher applicationEventPublisher) {
RedisOperationsSessionRepository sessionRepository = new RedisOperationsSessionRepository(sessionRedisTemplate);
sessionRepository.setApplicationEventPublisher(applicationEventPublisher);
- sessionRepository.setDefaultMaxInactiveInterval(maxInactiveIntervalInSeconds);
- if(defaultRedisSerializer != null) {
- sessionRepository.setDefaultSerializer(defaultRedisSerializer);
+ sessionRepository.setDefaultMaxInactiveInterval(this.maxInactiveIntervalInSeconds);
+ if (this.defaultRedisSerializer != null) {
+ sessionRepository.setDefaultSerializer(this.defaultRedisSerializer);
}
String redisNamespace = getRedisNamespace();
- if(StringUtils.hasText(redisNamespace)) {
+ if (StringUtils.hasText(redisNamespace)) {
sessionRepository.setRedisKeyNamespace(redisNamespace);
}
- sessionRepository.setRedisFlushMode(redisFlushMode);
+ sessionRepository.setRedisFlushMode(this.redisFlushMode);
return sessionRepository;
}
@@ -136,45 +137,24 @@ public class RedisHttpSessionConfiguration extends SpringHttpSessionConfiguratio
}
private String getRedisNamespace() {
- if(StringUtils.hasText(this.redisNamespace)) {
+ if (StringUtils.hasText(this.redisNamespace)) {
return this.redisNamespace;
}
- return System.getProperty("spring.session.redis.namespace","");
+ return System.getProperty("spring.session.redis.namespace", "");
}
public void setImportMetadata(AnnotationMetadata importMetadata) {
Map enableAttrMap = importMetadata.getAnnotationAttributes(EnableRedisHttpSession.class.getName());
AnnotationAttributes enableAttrs = AnnotationAttributes.fromMap(enableAttrMap);
- maxInactiveIntervalInSeconds = enableAttrs.getNumber("maxInactiveIntervalInSeconds");
+ this.maxInactiveIntervalInSeconds = enableAttrs.getNumber("maxInactiveIntervalInSeconds");
this.redisNamespace = enableAttrs.getString("redisNamespace");
this.redisFlushMode = enableAttrs.getEnum("redisFlushMode");
}
@Bean
public InitializingBean enableRedisKeyspaceNotificationsInitializer(RedisConnectionFactory connectionFactory) {
- return new EnableRedisKeyspaceNotificationsInitializer(connectionFactory, configureRedisAction);
- }
-
- /**
- * Ensures that Redis is configured to send keyspace notifications. This is important to ensure that expiration and
- * deletion of sessions trigger SessionDestroyedEvents. Without the SessionDestroyedEvent resources may not get
- * cleaned up properly. For example, the mapping of the Session to WebSocket connections may not get cleaned up.
- */
- static class EnableRedisKeyspaceNotificationsInitializer implements InitializingBean {
- private final RedisConnectionFactory connectionFactory;
-
- private ConfigureRedisAction configure;
-
- EnableRedisKeyspaceNotificationsInitializer(RedisConnectionFactory connectionFactory, ConfigureRedisAction configure) {
- this.connectionFactory = connectionFactory;
- this.configure = configure;
- }
-
- public void afterPropertiesSet() throws Exception {
- RedisConnection connection = connectionFactory.getConnection();
- configure.configure(connection);
- }
+ return new EnableRedisKeyspaceNotificationsInitializer(connectionFactory, this.configureRedisAction);
}
/**
@@ -204,4 +184,26 @@ public class RedisHttpSessionConfiguration extends SpringHttpSessionConfiguratio
public void setRedisSubscriptionExecutor(Executor redisSubscriptionExecutor) {
this.redisSubscriptionExecutor = redisSubscriptionExecutor;
}
+
+ /**
+ * Ensures that Redis is configured to send keyspace notifications. This is important to ensure that expiration and
+ * deletion of sessions trigger SessionDestroyedEvents. Without the SessionDestroyedEvent resources may not get
+ * cleaned up properly. For example, the mapping of the Session to WebSocket connections may not get cleaned up.
+ */
+ static class EnableRedisKeyspaceNotificationsInitializer implements InitializingBean {
+ private final RedisConnectionFactory connectionFactory;
+
+ private ConfigureRedisAction configure;
+
+ EnableRedisKeyspaceNotificationsInitializer(RedisConnectionFactory connectionFactory, ConfigureRedisAction configure) {
+ this.connectionFactory = connectionFactory;
+ this.configure = configure;
+ }
+
+ public void afterPropertiesSet() throws Exception {
+ RedisConnection connection = this.connectionFactory.getConnection();
+ this.configure.configure(connection);
+ }
+ }
+
}
diff --git a/spring-session/src/main/java/org/springframework/session/events/AbstractSessionEvent.java b/spring-session/src/main/java/org/springframework/session/events/AbstractSessionEvent.java
index 3c78d3b3..c5a52bb7 100644
--- a/spring-session/src/main/java/org/springframework/session/events/AbstractSessionEvent.java
+++ b/spring-session/src/main/java/org/springframework/session/events/AbstractSessionEvent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.events;
import org.springframework.context.ApplicationEvent;
@@ -38,7 +39,7 @@ public abstract class AbstractSessionEvent extends ApplicationEvent {
this.session = null;
}
- AbstractSessionEvent(Object source, Session session) {
+ AbstractSessionEvent(Object source, Session session) {
super(source);
this.session = session;
this.sessionId = session.getId();
@@ -54,10 +55,10 @@ public abstract class AbstractSessionEvent extends ApplicationEvent {
*/
@SuppressWarnings("unchecked")
public S getSession() {
- return (S) session;
+ return (S) this.session;
}
public String getSessionId() {
- return sessionId;
+ return this.sessionId;
}
}
diff --git a/spring-session/src/main/java/org/springframework/session/events/SessionCreatedEvent.java b/spring-session/src/main/java/org/springframework/session/events/SessionCreatedEvent.java
index a47231d1..d51ba694 100644
--- a/spring-session/src/main/java/org/springframework/session/events/SessionCreatedEvent.java
+++ b/spring-session/src/main/java/org/springframework/session/events/SessionCreatedEvent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.events;
import org.springframework.session.Session;
@@ -35,6 +36,7 @@ public class SessionCreatedEvent extends AbstractSessionEvent {
}
/**
+ * Create a new {@link SessionCreatedEvent}.
* @param source The Source of the SessionCreatedEvent
* @param session the Session that was created
*/
@@ -42,4 +44,4 @@ public class SessionCreatedEvent extends AbstractSessionEvent {
super(source, session);
}
-}
\ No newline at end of file
+}
diff --git a/spring-session/src/main/java/org/springframework/session/events/SessionDeletedEvent.java b/spring-session/src/main/java/org/springframework/session/events/SessionDeletedEvent.java
index 1c4ab05b..9d5cd81b 100644
--- a/spring-session/src/main/java/org/springframework/session/events/SessionDeletedEvent.java
+++ b/spring-session/src/main/java/org/springframework/session/events/SessionDeletedEvent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.events;
import org.springframework.session.Session;
@@ -37,4 +38,4 @@ public class SessionDeletedEvent extends SessionDestroyedEvent {
public SessionDeletedEvent(Object source, Session session) {
super(source, session);
}
-}
\ No newline at end of file
+}
diff --git a/spring-session/src/main/java/org/springframework/session/events/SessionDestroyedEvent.java b/spring-session/src/main/java/org/springframework/session/events/SessionDestroyedEvent.java
index 6a97f28c..9eacbe43 100644
--- a/spring-session/src/main/java/org/springframework/session/events/SessionDestroyedEvent.java
+++ b/spring-session/src/main/java/org/springframework/session/events/SessionDestroyedEvent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.events;
import org.springframework.session.Session;
@@ -32,10 +33,11 @@ public class SessionDestroyedEvent extends AbstractSessionEvent {
}
/**
+ * Create a new {@link SessionDestroyedEvent}.
* @param source The Source of the SessionDestoryedEvent
* @param session the Session that was created
*/
public SessionDestroyedEvent(Object source, Session session) {
super(source, session);
}
-}
\ No newline at end of file
+}
diff --git a/spring-session/src/main/java/org/springframework/session/events/SessionExpiredEvent.java b/spring-session/src/main/java/org/springframework/session/events/SessionExpiredEvent.java
index 8323fbe4..3c7bbb07 100644
--- a/spring-session/src/main/java/org/springframework/session/events/SessionExpiredEvent.java
+++ b/spring-session/src/main/java/org/springframework/session/events/SessionExpiredEvent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.events;
import org.springframework.session.Session;
@@ -37,4 +38,4 @@ public class SessionExpiredEvent extends SessionDestroyedEvent {
public SessionExpiredEvent(Object source, Session session) {
super(source, session);
}
-}
\ No newline at end of file
+}
diff --git a/spring-session/src/main/java/org/springframework/session/hazelcast/SessionEntryListener.java b/spring-session/src/main/java/org/springframework/session/hazelcast/SessionEntryListener.java
index 0e712513..249ae42e 100644
--- a/spring-session/src/main/java/org/springframework/session/hazelcast/SessionEntryListener.java
+++ b/spring-session/src/main/java/org/springframework/session/hazelcast/SessionEntryListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,10 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.hazelcast;
+import com.hazelcast.core.EntryEvent;
+import com.hazelcast.map.listener.EntryAddedListener;
+import com.hazelcast.map.listener.EntryEvictedListener;
+import com.hazelcast.map.listener.EntryRemovedListener;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.session.ExpiringSession;
import org.springframework.session.events.SessionCreatedEvent;
@@ -24,11 +30,6 @@ import org.springframework.session.events.SessionDeletedEvent;
import org.springframework.session.events.SessionExpiredEvent;
import org.springframework.util.Assert;
-import com.hazelcast.core.EntryEvent;
-import com.hazelcast.map.listener.EntryAddedListener;
-import com.hazelcast.map.listener.EntryEvictedListener;
-import com.hazelcast.map.listener.EntryRemovedListener;
-
/**
* Listen for events on the Hazelcast-backed SessionRepository and
* translate those events into the corresponding Spring Session events.
@@ -55,21 +56,21 @@ public class SessionEntryListener implements EntryAddedListener event) {
- if(logger.isDebugEnabled()) {
+ if (logger.isDebugEnabled()) {
logger.debug("Session created with id: " + event.getValue().getId());
}
this.eventPublisher.publishEvent(new SessionCreatedEvent(this, event.getValue()));
}
public void entryEvicted(EntryEvent event) {
- if(logger.isDebugEnabled()) {
+ if (logger.isDebugEnabled()) {
logger.debug("Session expired with id: " + event.getOldValue().getId());
}
this.eventPublisher.publishEvent(new SessionExpiredEvent(this, event.getOldValue()));
}
public void entryRemoved(EntryEvent event) {
- if(logger.isDebugEnabled()) {
+ if (logger.isDebugEnabled()) {
logger.debug("Session deleted with id: " + event.getOldValue().getId());
}
this.eventPublisher.publishEvent(new SessionDeletedEvent(this, event.getOldValue()));
diff --git a/spring-session/src/main/java/org/springframework/session/hazelcast/config/annotation/web/http/EnableHazelcastHttpSession.java b/spring-session/src/main/java/org/springframework/session/hazelcast/config/annotation/web/http/EnableHazelcastHttpSession.java
index 35dd2bd3..ac613806 100644
--- a/spring-session/src/main/java/org/springframework/session/hazelcast/config/annotation/web/http/EnableHazelcastHttpSession.java
+++ b/spring-session/src/main/java/org/springframework/session/hazelcast/config/annotation/web/http/EnableHazelcastHttpSession.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.hazelcast.config.annotation.web.http;
import java.lang.annotation.Documented;
@@ -50,8 +51,8 @@ import org.springframework.session.config.annotation.web.http.EnableSpringHttpSe
* @since 1.1
* @see EnableSpringHttpSession
*/
-@Retention(value=java.lang.annotation.RetentionPolicy.RUNTIME)
-@Target(value={java.lang.annotation.ElementType.TYPE})
+@Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
+@Target({java.lang.annotation.ElementType.TYPE})
@Documented
@Import(HazelcastHttpSessionConfiguration.class)
@Configuration
diff --git a/spring-session/src/main/java/org/springframework/session/hazelcast/config/annotation/web/http/HazelcastHttpSessionConfiguration.java b/spring-session/src/main/java/org/springframework/session/hazelcast/config/annotation/web/http/HazelcastHttpSessionConfiguration.java
index a0e1df7e..a14208b4 100644
--- a/spring-session/src/main/java/org/springframework/session/hazelcast/config/annotation/web/http/HazelcastHttpSessionConfiguration.java
+++ b/spring-session/src/main/java/org/springframework/session/hazelcast/config/annotation/web/http/HazelcastHttpSessionConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.hazelcast.config.annotation.web.http;
import java.util.Collection;
@@ -22,6 +23,9 @@ import java.util.concurrent.TimeUnit;
import javax.annotation.PreDestroy;
+import com.hazelcast.core.HazelcastInstance;
+import com.hazelcast.core.IMap;
+
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -35,9 +39,6 @@ import org.springframework.session.config.annotation.web.http.SpringHttpSessionC
import org.springframework.session.hazelcast.SessionEntryListener;
import org.springframework.session.web.http.SessionRepositoryFilter;
-import com.hazelcast.core.HazelcastInstance;
-import com.hazelcast.core.IMap;
-
/**
* Exposes the {@link SessionRepositoryFilter} as a bean named
* "springSessionRepositoryFilter". In order to use this a single
@@ -60,11 +61,11 @@ public class HazelcastHttpSessionConfiguration extends SpringHttpSessionConfigur
@Bean
public SessionRepository sessionRepository(HazelcastInstance hazelcastInstance, SessionEntryListener sessionListener) {
- this.sessionsMap = hazelcastInstance.getMap(sessionMapName);
+ this.sessionsMap = hazelcastInstance.getMap(this.sessionMapName);
this.sessionListenerUid = this.sessionsMap.addEntryListener(sessionListener, true);
MapSessionRepository sessionRepository = new MapSessionRepository(new ExpiringSessionMap(this.sessionsMap));
- sessionRepository.setDefaultMaxInactiveInterval(maxInactiveIntervalInSeconds);
+ sessionRepository.setDefaultMaxInactiveInterval(this.maxInactiveIntervalInSeconds);
return sessionRepository;
}
@@ -99,69 +100,72 @@ public class HazelcastHttpSessionConfiguration extends SpringHttpSessionConfigur
this.sessionMapName = sessionMapName;
}
+ /**
+ * A wrapper for Hazelcast's {@link IMap} which is used to store the sessions.
+ */
static class ExpiringSessionMap implements Map {
- private IMap delegate;
+ private IMap delegate;
- ExpiringSessionMap(IMap delegate) {
+ ExpiringSessionMap(IMap delegate) {
this.delegate = delegate;
}
public ExpiringSession put(String key, ExpiringSession value) {
- if(value == null) {
- return delegate.put(key, value);
+ if (value == null) {
+ return this.delegate.put(key, value);
}
- return delegate.put(key, value, value.getMaxInactiveIntervalInSeconds(), TimeUnit.SECONDS);
+ return this.delegate.put(key, value, value.getMaxInactiveIntervalInSeconds(), TimeUnit.SECONDS);
}
public int size() {
- return delegate.size();
+ return this.delegate.size();
}
public boolean isEmpty() {
- return delegate.isEmpty();
+ return this.delegate.isEmpty();
}
public boolean containsKey(Object key) {
- return delegate.containsKey(key);
+ return this.delegate.containsKey(key);
}
public boolean containsValue(Object value) {
- return delegate.containsValue(value);
+ return this.delegate.containsValue(value);
}
public ExpiringSession get(Object key) {
- return delegate.get(key);
+ return this.delegate.get(key);
}
public ExpiringSession remove(Object key) {
- return delegate.remove(key);
+ return this.delegate.remove(key);
}
public void putAll(Map extends String, ? extends ExpiringSession> m) {
- delegate.putAll(m);
+ this.delegate.putAll(m);
}
public void clear() {
- delegate.clear();
+ this.delegate.clear();
}
public Set keySet() {
- return delegate.keySet();
+ return this.delegate.keySet();
}
public Collection values() {
- return delegate.values();
+ return this.delegate.values();
}
public Set> entrySet() {
- return delegate.entrySet();
+ return this.delegate.entrySet();
}
public boolean equals(Object o) {
- return delegate.equals(o);
+ return this.delegate.equals(o);
}
public int hashCode() {
- return delegate.hashCode();
+ return this.delegate.hashCode();
}
}
}
diff --git a/spring-session/src/main/java/org/springframework/session/web/context/AbstractHttpSessionApplicationInitializer.java b/spring-session/src/main/java/org/springframework/session/web/context/AbstractHttpSessionApplicationInitializer.java
index 940eab53..00bb0d94 100644
--- a/spring-session/src/main/java/org/springframework/session/web/context/AbstractHttpSessionApplicationInitializer.java
+++ b/spring-session/src/main/java/org/springframework/session/web/context/AbstractHttpSessionApplicationInitializer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.web.context;
import java.util.Arrays;
@@ -75,6 +76,9 @@ public abstract class AbstractHttpSessionApplicationInitializer implements WebAp
private static final String SERVLET_CONTEXT_PREFIX = "org.springframework.web.servlet.FrameworkServlet.CONTEXT.";
+ /**
+ * The default name for Spring Session's repository filter.
+ */
public static final String DEFAULT_FILTER_NAME = "springSessionRepositoryFilter";
private final Class>[] configurationClasses;
@@ -105,9 +109,9 @@ public abstract class AbstractHttpSessionApplicationInitializer implements WebAp
public void onStartup(ServletContext servletContext)
throws ServletException {
beforeSessionRepositoryFilter(servletContext);
- if(configurationClasses != null) {
+ if (this.configurationClasses != null) {
AnnotationConfigWebApplicationContext rootAppContext = new AnnotationConfigWebApplicationContext();
- rootAppContext.register(configurationClasses);
+ rootAppContext.register(this.configurationClasses);
servletContext.addListener(new ContextLoaderListener(rootAppContext));
}
insertSessionRepositoryFilter(servletContext);
@@ -115,14 +119,14 @@ public abstract class AbstractHttpSessionApplicationInitializer implements WebAp
}
/**
- * Registers the springSessionRepositoryFilter
+ * Registers the springSessionRepositoryFilter.
* @param servletContext the {@link ServletContext}
*/
private void insertSessionRepositoryFilter(ServletContext servletContext) {
String filterName = DEFAULT_FILTER_NAME;
DelegatingFilterProxy springSessionRepositoryFilter = new DelegatingFilterProxy(filterName);
String contextAttribute = getWebApplicationContextAttribute();
- if(contextAttribute != null) {
+ if (contextAttribute != null) {
springSessionRepositoryFilter.setContextAttribute(contextAttribute);
}
registerFilter(servletContext, true, filterName, springSessionRepositoryFilter);
@@ -138,7 +142,7 @@ public abstract class AbstractHttpSessionApplicationInitializer implements WebAp
* @param filters
* the {@link Filter}s to register
*/
- protected final void insertFilters(ServletContext servletContext,Filter... filters) {
+ protected final void insertFilters(ServletContext servletContext, Filter... filters) {
registerFilters(servletContext, true, filters);
}
@@ -152,7 +156,7 @@ public abstract class AbstractHttpSessionApplicationInitializer implements WebAp
* @param filters
* the {@link Filter}s to register
*/
- protected final void appendFilters(ServletContext servletContext,Filter... filters) {
+ protected final void appendFilters(ServletContext servletContext, Filter... filters) {
registerFilters(servletContext, false, filters);
}
@@ -173,8 +177,8 @@ public abstract class AbstractHttpSessionApplicationInitializer implements WebAp
private void registerFilters(ServletContext servletContext, boolean insertBeforeOtherFilters, Filter... filters) {
Assert.notEmpty(filters, "filters cannot be null or empty");
- for(Filter filter : filters) {
- if(filter == null) {
+ for (Filter filter : filters) {
+ if (filter == null) {
throw new IllegalArgumentException("filters cannot contain null values. Got " + Arrays.asList(filters));
}
String filterName = Conventions.getVariableName(filter);
@@ -185,15 +189,15 @@ public abstract class AbstractHttpSessionApplicationInitializer implements WebAp
/**
* Registers the provided filter using the {@link #isAsyncSessionSupported()} and {@link #getSessionDispatcherTypes()}.
*
- * @param servletContext
+ * @param servletContext the servlet context
* @param insertBeforeOtherFilters should this Filter be inserted before or after other {@link Filter}
- * @param filterName
- * @param filter
+ * @param filterName the filter name
+ * @param filter the filter
*/
- private final void registerFilter(ServletContext servletContext, boolean insertBeforeOtherFilters, String filterName, Filter filter) {
+ private void registerFilter(ServletContext servletContext, boolean insertBeforeOtherFilters, String filterName, Filter filter) {
Dynamic registration = servletContext.addFilter(filterName, filter);
- if(registration == null) {
- throw new IllegalStateException("Duplicate Filter registration for '" + filterName +"'. Check to ensure the Filter is only configured once.");
+ if (registration == null) {
+ throw new IllegalStateException("Duplicate Filter registration for '" + filterName + "'. Check to ensure the Filter is only configured once.");
}
registration.setAsyncSupported(isAsyncSessionSupported());
EnumSet dispatcherTypes = getSessionDispatcherTypes();
@@ -217,7 +221,7 @@ public abstract class AbstractHttpSessionApplicationInitializer implements WebAp
*/
private String getWebApplicationContextAttribute() {
String dispatcherServletName = getDispatcherWebApplicationContextSuffix();
- if(dispatcherServletName == null) {
+ if (dispatcherServletName == null) {
return null;
}
return SERVLET_CONTEXT_PREFIX + dispatcherServletName;
diff --git a/spring-session/src/main/java/org/springframework/session/web/http/CookieHttpSessionStrategy.java b/spring-session/src/main/java/org/springframework/session/web/http/CookieHttpSessionStrategy.java
index 8c3ebc13..af059f08 100644
--- a/spring-session/src/main/java/org/springframework/session/web/http/CookieHttpSessionStrategy.java
+++ b/spring-session/src/main/java/org/springframework/session/web/http/CookieHttpSessionStrategy.java
@@ -1,18 +1,19 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
- * 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
+ * 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
+ * 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.
+ * 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.springframework.session.web.http;
import java.io.UnsupportedEncodingException;
@@ -150,8 +151,8 @@ import org.springframework.util.Assert;
* }
*
*
- * @since 1.0
* @author Rob Winch
+ * @since 1.0
*/
public final class CookieHttpSessionStrategy implements MultiHttpSessionStrategy, HttpSessionManager {
private static final String SESSION_IDS_WRITTEN_ATTR = CookieHttpSessionStrategy.class.getName().concat(".SESSIONS_WRITTEN_ATTR");
@@ -160,27 +161,27 @@ public final class CookieHttpSessionStrategy implements MultiHttpSessionStrategy
static final String DEFAULT_SESSION_ALIAS_PARAM_NAME = "_s";
- private Pattern ALIAS_PATTERN = Pattern.compile("^[\\w-]{1,50}$");
+ private static final Pattern ALIAS_PATTERN = Pattern.compile("^[\\w-]{1,50}$");
private String sessionParam = DEFAULT_SESSION_ALIAS_PARAM_NAME;
private CookieSerializer cookieSerializer = new DefaultCookieSerializer();
public String getRequestedSessionId(HttpServletRequest request) {
- Map sessionIds = getSessionIds(request);
+ Map sessionIds = getSessionIds(request);
String sessionAlias = getCurrentSessionAlias(request);
return sessionIds.get(sessionAlias);
}
public String getCurrentSessionAlias(HttpServletRequest request) {
- if(sessionParam == null) {
+ if (this.sessionParam == null) {
return DEFAULT_ALIAS;
}
- String u = request.getParameter(sessionParam);
- if(u == null) {
+ String u = request.getParameter(this.sessionParam);
+ if (u == null) {
return DEFAULT_ALIAS;
}
- if(!ALIAS_PATTERN.matcher(u).matches()) {
+ if (!ALIAS_PATTERN.matcher(u).matches()) {
return DEFAULT_ALIAS;
}
return u;
@@ -188,13 +189,13 @@ public final class CookieHttpSessionStrategy implements MultiHttpSessionStrategy
public String getNewSessionAlias(HttpServletRequest request) {
Set sessionAliases = getSessionIds(request).keySet();
- if(sessionAliases.isEmpty()) {
+ if (sessionAliases.isEmpty()) {
return DEFAULT_ALIAS;
}
long lastAlias = Long.decode(DEFAULT_ALIAS);
- for(String alias : sessionAliases) {
+ for (String alias : sessionAliases) {
long selectedAlias = safeParse(alias);
- if(selectedAlias > lastAlias) {
+ if (selectedAlias > lastAlias) {
lastAlias = selectedAlias;
}
}
@@ -204,30 +205,31 @@ public final class CookieHttpSessionStrategy implements MultiHttpSessionStrategy
private long safeParse(String hex) {
try {
return Long.decode("0x" + hex);
- } catch(NumberFormatException notNumber) {
+ }
+ catch (NumberFormatException notNumber) {
return 0;
}
}
public void onNewSession(Session session, HttpServletRequest request, HttpServletResponse response) {
Set sessionIdsWritten = getSessionIdsWritten(request);
- if(sessionIdsWritten.contains(session.getId())) {
+ if (sessionIdsWritten.contains(session.getId())) {
return;
}
sessionIdsWritten.add(session.getId());
- Map sessionIds = getSessionIds(request);
+ Map sessionIds = getSessionIds(request);
String sessionAlias = getCurrentSessionAlias(request);
sessionIds.put(sessionAlias, session.getId());
String cookieValue = createSessionCookieValue(sessionIds);
- cookieSerializer.writeCookieValue(new CookieValue(request,response,cookieValue));
+ this.cookieSerializer.writeCookieValue(new CookieValue(request, response, cookieValue));
}
@SuppressWarnings("unchecked")
private Set getSessionIdsWritten(HttpServletRequest request) {
Set sessionsWritten = (Set) request.getAttribute(SESSION_IDS_WRITTEN_ATTR);
- if(sessionsWritten == null) {
+ if (sessionsWritten == null) {
sessionsWritten = new HashSet();
request.setAttribute(SESSION_IDS_WRITTEN_ATTR, sessionsWritten);
}
@@ -235,15 +237,15 @@ public final class CookieHttpSessionStrategy implements MultiHttpSessionStrategy
}
private String createSessionCookieValue(Map sessionIds) {
- if(sessionIds.isEmpty()) {
+ if (sessionIds.isEmpty()) {
return "";
}
- if(sessionIds.size() == 1 && sessionIds.keySet().contains(DEFAULT_ALIAS)) {
+ if (sessionIds.size() == 1 && sessionIds.keySet().contains(DEFAULT_ALIAS)) {
return sessionIds.values().iterator().next();
}
StringBuffer buffer = new StringBuffer();
- for(Map.Entry entry : sessionIds.entrySet()) {
+ for (Map.Entry entry : sessionIds.entrySet()) {
String alias = entry.getKey();
String id = entry.getValue();
@@ -252,17 +254,17 @@ public final class CookieHttpSessionStrategy implements MultiHttpSessionStrategy
buffer.append(id);
buffer.append(" ");
}
- buffer.deleteCharAt(buffer.length()-1);
+ buffer.deleteCharAt(buffer.length() - 1);
return buffer.toString();
}
public void onInvalidateSession(HttpServletRequest request, HttpServletResponse response) {
- Map sessionIds = getSessionIds(request);
+ Map sessionIds = getSessionIds(request);
String requestedAlias = getCurrentSessionAlias(request);
sessionIds.remove(requestedAlias);
String cookieValue = createSessionCookieValue(sessionIds);
- cookieSerializer.writeCookieValue(new CookieValue(request,response,cookieValue));
+ this.cookieSerializer.writeCookieValue(new CookieValue(request, response, cookieValue));
}
/**
@@ -290,7 +292,7 @@ public final class CookieHttpSessionStrategy implements MultiHttpSessionStrategy
}
/**
- * Sets the name of the cookie to be used
+ * Sets the name of the cookie to be used.
* @param cookieName the name of the cookie to be used
* @deprecated use {@link #setCookieSerializer(CookieSerializer)}
*/
@@ -301,18 +303,18 @@ public final class CookieHttpSessionStrategy implements MultiHttpSessionStrategy
this.cookieSerializer = serializer;
}
- public Map getSessionIds(HttpServletRequest request) {
- List cookieValues = cookieSerializer.readCookieValues(request);
+ public Map getSessionIds(HttpServletRequest request) {
+ List cookieValues = this.cookieSerializer.readCookieValues(request);
String sessionCookieValue = cookieValues.isEmpty() ? "" : cookieValues.iterator().next();
- Map result = new LinkedHashMap();
+ Map result = new LinkedHashMap();
StringTokenizer tokens = new StringTokenizer(sessionCookieValue, " ");
- if(tokens.countTokens() == 1) {
+ if (tokens.countTokens() == 1) {
result.put(DEFAULT_ALIAS, tokens.nextToken());
return result;
}
- while(tokens.hasMoreTokens()) {
+ while (tokens.hasMoreTokens()) {
String alias = tokens.nextToken();
- if(!tokens.hasMoreTokens()) {
+ if (!tokens.hasMoreTokens()) {
break;
}
String id = tokens.nextToken();
@@ -330,46 +332,23 @@ public final class CookieHttpSessionStrategy implements MultiHttpSessionStrategy
return new MultiSessionHttpServletResponse(response, request);
}
- class MultiSessionHttpServletResponse extends HttpServletResponseWrapper {
- private final HttpServletRequest request;
-
- public MultiSessionHttpServletResponse(HttpServletResponse response, HttpServletRequest request) {
- super(response);
- this.request = request;
- }
-
- @Override
- public String encodeRedirectURL(String url) {
- url = super.encodeRedirectURL(url);
- return CookieHttpSessionStrategy.this.encodeURL(url, getCurrentSessionAlias(request));
- }
-
- @Override
- public String encodeURL(String url) {
- url = super.encodeURL(url);
-
- String alias = getCurrentSessionAlias(request);
- return CookieHttpSessionStrategy.this.encodeURL(url, alias);
- }
- }
-
public String encodeURL(String url, String sessionAlias) {
String encodedSessionAlias = urlEncode(sessionAlias);
int queryStart = url.indexOf("?");
boolean isDefaultAlias = DEFAULT_ALIAS.equals(encodedSessionAlias);
- if(queryStart < 0) {
- return isDefaultAlias ? url : url + "?" + sessionParam + "=" + encodedSessionAlias;
+ if (queryStart < 0) {
+ return isDefaultAlias ? url : url + "?" + this.sessionParam + "=" + encodedSessionAlias;
}
String path = url.substring(0, queryStart);
String query = url.substring(queryStart + 1, url.length());
- String replacement = isDefaultAlias ? "" : "$1"+encodedSessionAlias;
- query = query.replaceFirst( "((^|&)" + sessionParam + "=)([^&]+)?", replacement);
- if(!isDefaultAlias && url.endsWith(query)) {
+ String replacement = isDefaultAlias ? "" : "$1" + encodedSessionAlias;
+ query = query.replaceFirst("((^|&)" + this.sessionParam + "=)([^&]+)?", replacement);
+ if (!isDefaultAlias && url.endsWith(query)) {
// no existing alias
- if(!(query.endsWith("&") || query.length() == 0)) {
+ if (!(query.endsWith("&") || query.length() == 0)) {
query += "&";
}
- query += sessionParam + "=" + encodedSessionAlias;
+ query += this.sessionParam + "=" + encodedSessionAlias;
}
return path + "?" + query;
@@ -378,8 +357,36 @@ public final class CookieHttpSessionStrategy implements MultiHttpSessionStrategy
private String urlEncode(String value) {
try {
return URLEncoder.encode(value, "UTF-8");
- } catch (UnsupportedEncodingException e) {
+ }
+ catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
-}
\ No newline at end of file
+
+ /**
+ * A {@link CookieHttpSessionStrategy} aware {@link HttpServletResponseWrapper}.
+ */
+ class MultiSessionHttpServletResponse extends HttpServletResponseWrapper {
+ private final HttpServletRequest request;
+
+ MultiSessionHttpServletResponse(HttpServletResponse response, HttpServletRequest request) {
+ super(response);
+ this.request = request;
+ }
+
+ @Override
+ public String encodeRedirectURL(String url) {
+ url = super.encodeRedirectURL(url);
+ return CookieHttpSessionStrategy.this.encodeURL(url, getCurrentSessionAlias(this.request));
+ }
+
+ @Override
+ public String encodeURL(String url) {
+ url = super.encodeURL(url);
+
+ String alias = getCurrentSessionAlias(this.request);
+ return CookieHttpSessionStrategy.this.encodeURL(url, alias);
+ }
+ }
+
+}
diff --git a/spring-session/src/main/java/org/springframework/session/web/http/CookieSerializer.java b/spring-session/src/main/java/org/springframework/session/web/http/CookieSerializer.java
index ba49b95e..38e96b16 100644
--- a/spring-session/src/main/java/org/springframework/session/web/http/CookieSerializer.java
+++ b/spring-session/src/main/java/org/springframework/session/web/http/CookieSerializer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.web.http;
import java.util.List;
@@ -32,7 +33,7 @@ public interface CookieSerializer {
/**
* Writes a given {@link CookieValue} to the provided
- * {@link HttpServletResponse}
+ * {@link HttpServletResponse}.
*
* @param cookieValue
* the {@link CookieValue} to write to
@@ -61,13 +62,13 @@ public interface CookieSerializer {
* @author Rob Winch
* @since 1.1
*/
- public class CookieValue {
+ class CookieValue {
private final HttpServletRequest request;
private final HttpServletResponse response;
private final String cookieValue;
/**
- * Creates a new instance
+ * Creates a new instance.
*
* @param request
* the {@link HttpServletRequest} to use. Useful for
@@ -92,7 +93,7 @@ public interface CookieSerializer {
* @return the request to use. Cannot be null.
*/
public HttpServletRequest getRequest() {
- return request;
+ return this.request;
}
/**
@@ -100,7 +101,7 @@ public interface CookieSerializer {
* @return the response to write to. Cannot be null.
*/
public HttpServletResponse getResponse() {
- return response;
+ return this.response;
}
/**
@@ -109,7 +110,7 @@ public interface CookieSerializer {
* @return the value to be written
*/
public String getCookieValue() {
- return cookieValue;
+ return this.cookieValue;
}
}
}
diff --git a/spring-session/src/main/java/org/springframework/session/web/http/DefaultCookieSerializer.java b/spring-session/src/main/java/org/springframework/session/web/http/DefaultCookieSerializer.java
index 36d0814e..b79ff143 100644
--- a/spring-session/src/main/java/org/springframework/session/web/http/DefaultCookieSerializer.java
+++ b/spring-session/src/main/java/org/springframework/session/web/http/DefaultCookieSerializer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.web.http;
import java.util.ArrayList;
@@ -26,7 +27,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
- * The default implementation of {@link CookieSerializer}
+ * The default implementation of {@link CookieSerializer}.
*
* @author Rob Winch
* @since 1.1
@@ -53,17 +54,17 @@ public class DefaultCookieSerializer implements CookieSerializer {
* @see org.springframework.session.web.http.CookieSerializer#readCookieValues(javax.servlet.http.HttpServletRequest)
*/
public List readCookieValues(HttpServletRequest request) {
- Cookie cookies[] = request.getCookies();
+ Cookie[] cookies = request.getCookies();
List matchingCookieValues = new ArrayList();
if (cookies != null) {
for (Cookie cookie : cookies) {
- if (cookieName.equals(cookie.getName())) {
+ if (this.cookieName.equals(cookie.getName())) {
String sessionId = cookie.getValue();
- if(sessionId == null) {
+ if (sessionId == null) {
continue;
}
- if(jvmRoute != null && sessionId.endsWith(jvmRoute)) {
- sessionId = sessionId.substring(0, sessionId.length() - jvmRoute.length());
+ if (this.jvmRoute != null && sessionId.endsWith(this.jvmRoute)) {
+ sessionId = sessionId.substring(0, sessionId.length() - this.jvmRoute.length());
}
matchingCookieValues.add(sessionId);
}
@@ -83,9 +84,9 @@ public class DefaultCookieSerializer implements CookieSerializer {
HttpServletResponse response = cookieValue.getResponse();
String requestedCookieValue = cookieValue.getCookieValue();
- String actualCookieValue = jvmRoute == null ? requestedCookieValue : requestedCookieValue + jvmRoute;
+ String actualCookieValue = this.jvmRoute == null ? requestedCookieValue : requestedCookieValue + this.jvmRoute;
- Cookie sessionCookie = new Cookie(cookieName, actualCookieValue);
+ Cookie sessionCookie = new Cookie(this.cookieName, actualCookieValue);
sessionCookie.setSecure(isSecureCookie(request));
sessionCookie.setPath(getCookiePath(request));
String domainName = getDomainName(request);
@@ -93,14 +94,15 @@ public class DefaultCookieSerializer implements CookieSerializer {
sessionCookie.setDomain(domainName);
}
- if (useHttpOnlyCookie) {
+ if (this.useHttpOnlyCookie) {
sessionCookie.setHttpOnly(true);
}
if ("".equals(requestedCookieValue)) {
sessionCookie.setMaxAge(0);
- } else {
- sessionCookie.setMaxAge(cookieMaxAge);
+ }
+ else {
+ sessionCookie.setMaxAge(this.cookieMaxAge);
}
response.addCookie(sessionCookie);
@@ -125,17 +127,17 @@ public class DefaultCookieSerializer implements CookieSerializer {
* determines if the cookie should be marked as HTTP Only.
*/
public void setUseHttpOnlyCookie(boolean useHttpOnlyCookie) {
- if(useHttpOnlyCookie && !isServlet3()) {
+ if (useHttpOnlyCookie && !isServlet3()) {
throw new IllegalArgumentException("You cannot set useHttpOnlyCookie to true in pre Servlet 3 environment");
}
this.useHttpOnlyCookie = useHttpOnlyCookie;
}
private boolean isSecureCookie(HttpServletRequest request) {
- if (useSecureCookie == null) {
+ if (this.useSecureCookie == null) {
return request.isSecure();
}
- return useSecureCookie;
+ return this.useSecureCookie;
}
/**
@@ -247,11 +249,11 @@ public class DefaultCookieSerializer implements CookieSerializer {
}
private String getDomainName(HttpServletRequest request) {
- if (domainName != null) {
- return domainName;
+ if (this.domainName != null) {
+ return this.domainName;
}
- if (domainNamePattern != null) {
- Matcher matcher = domainNamePattern.matcher(request.getServerName());
+ if (this.domainNamePattern != null) {
+ Matcher matcher = this.domainNamePattern.matcher(request.getServerName());
if (matcher.matches()) {
return matcher.group(1);
}
@@ -260,22 +262,23 @@ public class DefaultCookieSerializer implements CookieSerializer {
}
private String getCookiePath(HttpServletRequest request) {
- if (cookiePath == null) {
+ if (this.cookiePath == null) {
return request.getContextPath() + "/";
}
- return cookiePath;
+ return this.cookiePath;
}
/**
* Returns true if the Servlet 3 APIs are detected.
*
- * @return
+ * @return whether the Servlet 3 APIs are detected
*/
private boolean isServlet3() {
try {
ServletRequest.class.getMethod("startAsync");
return true;
- } catch (NoSuchMethodException e) {
+ }
+ catch (NoSuchMethodException e) {
}
return false;
}
diff --git a/spring-session/src/main/java/org/springframework/session/web/http/ExpiringSessionHttpSession.java b/spring-session/src/main/java/org/springframework/session/web/http/ExpiringSessionHttpSession.java
index 51717089..b9b6cf53 100644
--- a/spring-session/src/main/java/org/springframework/session/web/http/ExpiringSessionHttpSession.java
+++ b/spring-session/src/main/java/org/springframework/session/web/http/ExpiringSessionHttpSession.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.web.http;
import java.util.Collections;
@@ -29,6 +30,7 @@ import org.springframework.session.ExpiringSession;
/**
* Adapts Spring Session's {@link ExpiringSession} to an {@link HttpSession}.
*
+ * @param the {@link ExpiringSession} type
* @author Rob Winch
* @since 1.1
*/
@@ -39,7 +41,7 @@ class ExpiringSessionHttpSession implements HttpSessi
private boolean invalidated;
private boolean old;
- public ExpiringSessionHttpSession(S session, ServletContext servletContext) {
+ ExpiringSessionHttpSession(S session, ServletContext servletContext) {
this.session = session;
this.servletContext = servletContext;
}
@@ -49,33 +51,33 @@ class ExpiringSessionHttpSession implements HttpSessi
}
public S getSession() {
- return session;
+ return this.session;
}
public long getCreationTime() {
checkState();
- return session.getCreationTime();
+ return this.session.getCreationTime();
}
public String getId() {
- return session.getId();
+ return this.session.getId();
}
public long getLastAccessedTime() {
checkState();
- return session.getLastAccessedTime();
+ return this.session.getLastAccessedTime();
}
public ServletContext getServletContext() {
- return servletContext;
+ return this.servletContext;
}
public void setMaxInactiveInterval(int interval) {
- session.setMaxInactiveIntervalInSeconds(interval);
+ this.session.setMaxInactiveIntervalInSeconds(interval);
}
public int getMaxInactiveInterval() {
- return session.getMaxInactiveIntervalInSeconds();
+ return this.session.getMaxInactiveIntervalInSeconds();
}
public HttpSessionContext getSessionContext() {
@@ -84,7 +86,7 @@ class ExpiringSessionHttpSession implements HttpSessi
public Object getAttribute(String name) {
checkState();
- return session.getAttribute(name);
+ return this.session.getAttribute(name);
}
public Object getValue(String name) {
@@ -93,18 +95,18 @@ class ExpiringSessionHttpSession implements HttpSessi
public Enumeration getAttributeNames() {
checkState();
- return Collections.enumeration(session.getAttributeNames());
+ return Collections.enumeration(this.session.getAttributeNames());
}
public String[] getValueNames() {
checkState();
- Set attrs = session.getAttributeNames();
+ Set attrs = this.session.getAttributeNames();
return attrs.toArray(new String[0]);
}
public void setAttribute(String name, Object value) {
checkState();
- session.setAttribute(name, value);
+ this.session.setAttribute(name, value);
}
public void putValue(String name, Object value) {
@@ -113,7 +115,7 @@ class ExpiringSessionHttpSession implements HttpSessi
public void removeAttribute(String name) {
checkState();
- session.removeAttribute(name);
+ this.session.removeAttribute(name);
}
public void removeValue(String name) {
@@ -131,11 +133,11 @@ class ExpiringSessionHttpSession implements HttpSessi
public boolean isNew() {
checkState();
- return !old;
+ return !this.old;
}
private void checkState() {
- if(invalidated) {
+ if (this.invalidated) {
throw new IllegalStateException("The HttpSession has already be invalidated.");
}
}
diff --git a/spring-session/src/main/java/org/springframework/session/web/http/HeaderHttpSessionStrategy.java b/spring-session/src/main/java/org/springframework/session/web/http/HeaderHttpSessionStrategy.java
index e9dfc9f3..77331616 100644
--- a/spring-session/src/main/java/org/springframework/session/web/http/HeaderHttpSessionStrategy.java
+++ b/spring-session/src/main/java/org/springframework/session/web/http/HeaderHttpSessionStrategy.java
@@ -1,26 +1,27 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
- * 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
+ * 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
+ * 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.
+ * 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.springframework.session.web.http;
-import org.springframework.session.Session;
-import org.springframework.util.Assert;
+package org.springframework.session.web.http;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.springframework.session.Session;
+import org.springframework.util.Assert;
+
/**
* A {@link HttpSessionStrategy} that uses a header to obtain the session from. Specifically, this implementation will
* allow specifying a header name using {@link HeaderHttpSessionStrategy#setHeaderName(String)}. The default is "x-auth-token".
@@ -47,22 +48,22 @@ import javax.servlet.http.HttpServletResponse;
* x-auth-token:
*
*
- * @since 1.0
* @author Rob Winch
+ * @since 1.0
*/
public class HeaderHttpSessionStrategy implements HttpSessionStrategy {
private String headerName = "x-auth-token";
public String getRequestedSessionId(HttpServletRequest request) {
- return request.getHeader(headerName);
+ return request.getHeader(this.headerName);
}
public void onNewSession(Session session, HttpServletRequest request, HttpServletResponse response) {
- response.setHeader(headerName, session.getId());
+ response.setHeader(this.headerName, session.getId());
}
public void onInvalidateSession(HttpServletRequest request, HttpServletResponse response) {
- response.setHeader(headerName, "");
+ response.setHeader(this.headerName, "");
}
/**
@@ -74,4 +75,4 @@ public class HeaderHttpSessionStrategy implements HttpSessionStrategy {
Assert.notNull(headerName, "headerName cannot be null");
this.headerName = headerName;
}
-}
\ No newline at end of file
+}
diff --git a/spring-session/src/main/java/org/springframework/session/web/http/HttpSessionManager.java b/spring-session/src/main/java/org/springframework/session/web/http/HttpSessionManager.java
index cc6a76f3..a20a964d 100644
--- a/spring-session/src/main/java/org/springframework/session/web/http/HttpSessionManager.java
+++ b/spring-session/src/main/java/org/springframework/session/web/http/HttpSessionManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.web.http;
import java.util.Map;
@@ -39,7 +40,7 @@ public interface HttpSessionManager {
/**
* Gets a mapping of the session alias to the session id from the
- * {@link HttpServletRequest}
+ * {@link HttpServletRequest}.
*
* @param request the {@link HttpServletRequest} to obtain the mapping from. Cannot be null.
* @return a mapping of the session alias to the session id from the
diff --git a/spring-session/src/main/java/org/springframework/session/web/http/HttpSessionStrategy.java b/spring-session/src/main/java/org/springframework/session/web/http/HttpSessionStrategy.java
index 003d67ea..aad14698 100644
--- a/spring-session/src/main/java/org/springframework/session/web/http/HttpSessionStrategy.java
+++ b/spring-session/src/main/java/org/springframework/session/web/http/HttpSessionStrategy.java
@@ -1,30 +1,31 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
- * 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
+ * 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
+ * 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.
+ * 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.springframework.session.web.http;
-import org.springframework.session.Session;
+package org.springframework.session.web.http;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.springframework.session.Session;
+
/**
* A strategy for mapping HTTP request and responses to a {@link Session}.
*
- * @since 1.0
* @author Rob Winch
+ * @since 1.0
*/
public interface HttpSessionStrategy {
diff --git a/spring-session/src/main/java/org/springframework/session/web/http/MultiHttpSessionStrategy.java b/spring-session/src/main/java/org/springframework/session/web/http/MultiHttpSessionStrategy.java
index 522f0cc5..5c0e8212 100644
--- a/spring-session/src/main/java/org/springframework/session/web/http/MultiHttpSessionStrategy.java
+++ b/spring-session/src/main/java/org/springframework/session/web/http/MultiHttpSessionStrategy.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.web.http;
import javax.servlet.http.HttpServletRequest;
@@ -28,10 +29,9 @@ import javax.servlet.http.HttpServletResponse;
* are active.
*
*
- * @see CookieHttpSessionStrategy
- *
* @author Rob Winch
* @since 1.0
+ * @see CookieHttpSessionStrategy
*/
public interface MultiHttpSessionStrategy extends HttpSessionStrategy, RequestResponsePostProcessor {
-}
\ No newline at end of file
+}
diff --git a/spring-session/src/main/java/org/springframework/session/web/http/OnCommittedResponseWrapper.java b/spring-session/src/main/java/org/springframework/session/web/http/OnCommittedResponseWrapper.java
index 9feb5daf..4d681c31 100644
--- a/spring-session/src/main/java/org/springframework/session/web/http/OnCommittedResponseWrapper.java
+++ b/spring-session/src/main/java/org/springframework/session/web/http/OnCommittedResponseWrapper.java
@@ -1,33 +1,38 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
- * 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
+ * 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
+ * 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.
+ * 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.springframework.session.web.http;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Locale;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.Locale;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
* Base class for response wrappers which encapsulate the logic for handling an event when the
* {@link javax.servlet.http.HttpServletResponse} is committed.
*
- * @since 1.0
* @author Rob Winch
+ * @since 1.0
*/
abstract class OnCommittedResponseWrapper extends HttpServletResponseWrapper {
private final Log logger = LogFactory.getLog(getClass());
@@ -46,15 +51,16 @@ abstract class OnCommittedResponseWrapper extends HttpServletResponseWrapper {
private long contentWritten;
/**
+ * Create a new {@link OnCommittedResponseWrapper}.
* @param response the response to be wrapped
*/
- public OnCommittedResponseWrapper(HttpServletResponse response) {
+ OnCommittedResponseWrapper(HttpServletResponse response) {
super(response);
}
@Override
public void addHeader(String name, String value) {
- if("Content-Length".equalsIgnoreCase(name)) {
+ if ("Content-Length".equalsIgnoreCase(name)) {
setContentLength(Long.parseLong(value));
}
super.addHeader(name, value);
@@ -81,13 +87,14 @@ abstract class OnCommittedResponseWrapper extends HttpServletResponseWrapper {
}
/**
- * Implement the logic for handling the {@link javax.servlet.http.HttpServletResponse} being committed
+ * Implement the logic for handling the {@link javax.servlet.http.HttpServletResponse} being committed.
*/
protected abstract void onResponseCommitted();
/**
* Makes sure {@link OnCommittedResponseWrapper#onResponseCommitted()} is invoked before calling the
- * superclass sendError()
+ * superclass sendError().
+ * @param sc the error status code
*/
@Override
public final void sendError(int sc) throws IOException {
@@ -97,7 +104,8 @@ abstract class OnCommittedResponseWrapper extends HttpServletResponseWrapper {
/**
* Makes sure {@link OnCommittedResponseWrapper#onResponseCommitted()} is invoked before calling the
- * superclass sendError()
+ * superclass sendError().
+ * @param sc the error status code
*/
@Override
public final void sendError(int sc, String msg) throws IOException {
@@ -107,7 +115,8 @@ abstract class OnCommittedResponseWrapper extends HttpServletResponseWrapper {
/**
* Makes sure {@link OnCommittedResponseWrapper#onResponseCommitted()} is invoked before calling the
- * superclass sendRedirect()
+ * superclass sendRedirect().
+ * @param location the redirect URL location
*/
@Override
public final void sendRedirect(String location) throws IOException {
@@ -117,7 +126,8 @@ abstract class OnCommittedResponseWrapper extends HttpServletResponseWrapper {
/**
* Makes sure {@link OnCommittedResponseWrapper#onResponseCommitted()} is invoked before calling the calling
- * getOutputStream().close() or getOutputStream().flush()
+ * getOutputStream().close() or getOutputStream().flush().
+ * @throws IOException if an input or output exception occurred
*/
@Override
public ServletOutputStream getOutputStream() throws IOException {
@@ -126,7 +136,8 @@ abstract class OnCommittedResponseWrapper extends HttpServletResponseWrapper {
/**
* Makes sure {@link OnCommittedResponseWrapper#onResponseCommitted()} is invoked before calling the
- * getWriter().close() or getWriter().flush()
+ * getWriter().close() or getWriter().flush().
+ * @throws IOException if an input or output exception occurred
*/
@Override
public PrintWriter getWriter() throws IOException {
@@ -135,7 +146,8 @@ abstract class OnCommittedResponseWrapper extends HttpServletResponseWrapper {
/**
* Makes sure {@link OnCommittedResponseWrapper#onResponseCommitted()} is invoked before calling the
- * superclass flushBuffer()
+ * superclass flushBuffer().
+ * @throws IOException if an input or output exception occurred
*/
@Override
public void flushBuffer() throws IOException {
@@ -190,25 +202,26 @@ abstract class OnCommittedResponseWrapper extends HttpServletResponseWrapper {
* @param contentLengthToWrite the size of the content that is about to be written.
*/
private void checkContentLength(long contentLengthToWrite) {
- contentWritten += contentLengthToWrite;
- boolean isBodyFullyWritten = contentLength > 0 && contentWritten >= contentLength;
+ this.contentWritten += contentLengthToWrite;
+ boolean isBodyFullyWritten = this.contentLength > 0 && this.contentWritten >= this.contentLength;
int bufferSize = getBufferSize();
- boolean requiresFlush = bufferSize > 0 && contentWritten >= bufferSize;
- if(isBodyFullyWritten || requiresFlush) {
+ boolean requiresFlush = bufferSize > 0 && this.contentWritten >= bufferSize;
+ if (isBodyFullyWritten || requiresFlush) {
doOnResponseCommitted();
}
}
/**
* Calls onResponseCommmitted() with the current contents as long as
- * {@link #disableOnResponseCommitted()()} was not invoked.
+ * {@link #disableOnResponseCommitted()} was not invoked.
*/
private void doOnResponseCommitted() {
- if(!disableOnCommitted) {
+ if (!this.disableOnCommitted) {
onResponseCommitted();
disableOnResponseCommitted();
- } else if(logger.isDebugEnabled()){
- logger.debug("Skip invoking on");
+ }
+ else if (this.logger.isDebugEnabled()) {
+ this.logger.debug("Skip invoking on");
}
}
@@ -221,195 +234,195 @@ abstract class OnCommittedResponseWrapper extends HttpServletResponseWrapper {
private class SaveContextPrintWriter extends PrintWriter {
private final PrintWriter delegate;
- public SaveContextPrintWriter(PrintWriter delegate) {
+ SaveContextPrintWriter(PrintWriter delegate) {
super(delegate);
this.delegate = delegate;
}
public void flush() {
doOnResponseCommitted();
- delegate.flush();
+ this.delegate.flush();
}
public void close() {
doOnResponseCommitted();
- delegate.close();
+ this.delegate.close();
}
public int hashCode() {
- return delegate.hashCode();
+ return this.delegate.hashCode();
}
public boolean equals(Object obj) {
- return delegate.equals(obj);
+ return this.delegate.equals(obj);
}
public String toString() {
- return getClass().getName() + "[delegate=" + delegate.toString() + "]";
+ return getClass().getName() + "[delegate=" + this.delegate.toString() + "]";
}
public boolean checkError() {
- return delegate.checkError();
+ return this.delegate.checkError();
}
public void write(int c) {
trackContentLength(c);
- delegate.write(c);
+ this.delegate.write(c);
}
public void write(char[] buf, int off, int len) {
checkContentLength(len);
- delegate.write(buf, off, len);
+ this.delegate.write(buf, off, len);
}
public void write(char[] buf) {
trackContentLength(buf);
- delegate.write(buf);
+ this.delegate.write(buf);
}
public void write(String s, int off, int len) {
checkContentLength(len);
- delegate.write(s, off, len);
+ this.delegate.write(s, off, len);
}
public void write(String s) {
trackContentLength(s);
- delegate.write(s);
+ this.delegate.write(s);
}
public void print(boolean b) {
trackContentLength(b);
- delegate.print(b);
+ this.delegate.print(b);
}
public void print(char c) {
trackContentLength(c);
- delegate.print(c);
+ this.delegate.print(c);
}
public void print(int i) {
trackContentLength(i);
- delegate.print(i);
+ this.delegate.print(i);
}
public void print(long l) {
trackContentLength(l);
- delegate.print(l);
+ this.delegate.print(l);
}
public void print(float f) {
trackContentLength(f);
- delegate.print(f);
+ this.delegate.print(f);
}
public void print(double d) {
trackContentLength(d);
- delegate.print(d);
+ this.delegate.print(d);
}
public void print(char[] s) {
trackContentLength(s);
- delegate.print(s);
+ this.delegate.print(s);
}
public void print(String s) {
trackContentLength(s);
- delegate.print(s);
+ this.delegate.print(s);
}
public void print(Object obj) {
trackContentLength(obj);
- delegate.print(obj);
+ this.delegate.print(obj);
}
public void println() {
trackContentLengthLn();
- delegate.println();
+ this.delegate.println();
}
public void println(boolean x) {
trackContentLength(x);
trackContentLengthLn();
- delegate.println(x);
+ this.delegate.println(x);
}
public void println(char x) {
trackContentLength(x);
trackContentLengthLn();
- delegate.println(x);
+ this.delegate.println(x);
}
public void println(int x) {
trackContentLength(x);
trackContentLengthLn();
- delegate.println(x);
+ this.delegate.println(x);
}
public void println(long x) {
trackContentLength(x);
trackContentLengthLn();
- delegate.println(x);
+ this.delegate.println(x);
}
public void println(float x) {
trackContentLength(x);
trackContentLengthLn();
- delegate.println(x);
+ this.delegate.println(x);
}
public void println(double x) {
trackContentLength(x);
trackContentLengthLn();
- delegate.println(x);
+ this.delegate.println(x);
}
public void println(char[] x) {
trackContentLength(x);
trackContentLengthLn();
- delegate.println(x);
+ this.delegate.println(x);
}
public void println(String x) {
trackContentLength(x);
trackContentLengthLn();
- delegate.println(x);
+ this.delegate.println(x);
}
public void println(Object x) {
trackContentLength(x);
trackContentLengthLn();
- delegate.println(x);
+ this.delegate.println(x);
}
public PrintWriter printf(String format, Object... args) {
- return delegate.printf(format, args);
+ return this.delegate.printf(format, args);
}
public PrintWriter printf(Locale l, String format, Object... args) {
- return delegate.printf(l, format, args);
+ return this.delegate.printf(l, format, args);
}
public PrintWriter format(String format, Object... args) {
- return delegate.format(format, args);
+ return this.delegate.format(format, args);
}
public PrintWriter format(Locale l, String format, Object... args) {
- return delegate.format(l, format, args);
+ return this.delegate.format(l, format, args);
}
public PrintWriter append(CharSequence csq) {
checkContentLength(csq.length());
- return delegate.append(csq);
+ return this.delegate.append(csq);
}
public PrintWriter append(CharSequence csq, int start, int end) {
checkContentLength(end - start);
- return delegate.append(csq, start, end);
+ return this.delegate.append(csq, start, end);
}
public PrintWriter append(char c) {
trackContentLength(c);
- return delegate.append(c);
+ return this.delegate.append(c);
}
}
@@ -423,7 +436,7 @@ abstract class OnCommittedResponseWrapper extends HttpServletResponseWrapper {
private class SaveContextServletOutputStream extends ServletOutputStream {
private final ServletOutputStream delegate;
- public SaveContextServletOutputStream(ServletOutputStream delegate) {
+ SaveContextServletOutputStream(ServletOutputStream delegate) {
this.delegate = delegate;
}
@@ -434,116 +447,116 @@ abstract class OnCommittedResponseWrapper extends HttpServletResponseWrapper {
public void flush() throws IOException {
doOnResponseCommitted();
- delegate.flush();
+ this.delegate.flush();
}
public void close() throws IOException {
doOnResponseCommitted();
- delegate.close();
+ this.delegate.close();
}
public int hashCode() {
- return delegate.hashCode();
+ return this.delegate.hashCode();
}
public boolean equals(Object obj) {
- return delegate.equals(obj);
+ return this.delegate.equals(obj);
}
public void print(boolean b) throws IOException {
trackContentLength(b);
- delegate.print(b);
+ this.delegate.print(b);
}
public void print(char c) throws IOException {
trackContentLength(c);
- delegate.print(c);
+ this.delegate.print(c);
}
public void print(double d) throws IOException {
trackContentLength(d);
- delegate.print(d);
+ this.delegate.print(d);
}
public void print(float f) throws IOException {
trackContentLength(f);
- delegate.print(f);
+ this.delegate.print(f);
}
public void print(int i) throws IOException {
trackContentLength(i);
- delegate.print(i);
+ this.delegate.print(i);
}
public void print(long l) throws IOException {
trackContentLength(l);
- delegate.print(l);
+ this.delegate.print(l);
}
public void print(String s) throws IOException {
trackContentLength(s);
- delegate.print(s);
+ this.delegate.print(s);
}
public void println() throws IOException {
trackContentLengthLn();
- delegate.println();
+ this.delegate.println();
}
public void println(boolean b) throws IOException {
trackContentLength(b);
trackContentLengthLn();
- delegate.println(b);
+ this.delegate.println(b);
}
public void println(char c) throws IOException {
trackContentLength(c);
trackContentLengthLn();
- delegate.println(c);
+ this.delegate.println(c);
}
public void println(double d) throws IOException {
trackContentLength(d);
trackContentLengthLn();
- delegate.println(d);
+ this.delegate.println(d);
}
public void println(float f) throws IOException {
trackContentLength(f);
trackContentLengthLn();
- delegate.println(f);
+ this.delegate.println(f);
}
public void println(int i) throws IOException {
trackContentLength(i);
trackContentLengthLn();
- delegate.println(i);
+ this.delegate.println(i);
}
public void println(long l) throws IOException {
trackContentLength(l);
trackContentLengthLn();
- delegate.println(l);
+ this.delegate.println(l);
}
public void println(String s) throws IOException {
trackContentLength(s);
trackContentLengthLn();
- delegate.println(s);
+ this.delegate.println(s);
}
public void write(byte[] b) throws IOException {
trackContentLength(b);
- delegate.write(b);
+ this.delegate.write(b);
}
public void write(byte[] b, int off, int len) throws IOException {
checkContentLength(len);
- delegate.write(b, off, len);
+ this.delegate.write(b, off, len);
}
public String toString() {
- return getClass().getName() + "[delegate=" + delegate.toString() + "]";
+ return getClass().getName() + "[delegate=" + this.delegate.toString() + "]";
}
}
-}
\ No newline at end of file
+}
diff --git a/spring-session/src/main/java/org/springframework/session/web/http/OncePerRequestFilter.java b/spring-session/src/main/java/org/springframework/session/web/http/OncePerRequestFilter.java
index 871af861..29bf864d 100644
--- a/spring-session/src/main/java/org/springframework/session/web/http/OncePerRequestFilter.java
+++ b/spring-session/src/main/java/org/springframework/session/web/http/OncePerRequestFilter.java
@@ -1,31 +1,38 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
- * 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
+ * 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
+ * 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.
+ * 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.springframework.session.web.http;
-import javax.servlet.*;
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
/**
* Allows for easily ensuring that a request is only invoked once per request. This is a simplified version of spring-web's
* OncePerRequestFilter and copied to reduce the foot print required to use the session support.
*
- * @since 1.0
* @author Rob Winch
+ * @since 1.0
*/
abstract class OncePerRequestFilter implements Filter {
/**
@@ -41,6 +48,11 @@ abstract class OncePerRequestFilter implements Filter {
* This {@code doFilter} implementation stores a request attribute for
* "already filtered", proceeding without filtering again if the
* attribute is already there.
+ * @param request the request
+ * @param response the response
+ * @param filterChain the filter chain
+ * @throws ServletException if request is not HTTP request
+ * @throws IOException in case of I/O operation exception
*/
public final void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
@@ -50,7 +62,7 @@ abstract class OncePerRequestFilter implements Filter {
}
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
- boolean hasAlreadyFilteredAttribute = request.getAttribute(alreadyFilteredAttributeName) != null;
+ boolean hasAlreadyFilteredAttribute = request.getAttribute(this.alreadyFilteredAttributeName) != null;
if (hasAlreadyFilteredAttribute) {
@@ -60,13 +72,13 @@ abstract class OncePerRequestFilter implements Filter {
}
else {
// Do invoke this filter...
- request.setAttribute(alreadyFilteredAttributeName, Boolean.TRUE);
+ request.setAttribute(this.alreadyFilteredAttributeName, Boolean.TRUE);
try {
doFilterInternal(httpRequest, httpResponse, filterChain);
}
finally {
// Remove the "already filtered" request attribute for this request.
- request.removeAttribute(alreadyFilteredAttributeName);
+ request.removeAttribute(this.alreadyFilteredAttributeName);
}
}
}
@@ -88,7 +100,9 @@ abstract class OncePerRequestFilter implements Filter {
HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException;
- public void init(FilterConfig config) {}
+ public void init(FilterConfig config) {
+ }
- public void destroy() {}
+ public void destroy() {
+ }
}
diff --git a/spring-session/src/main/java/org/springframework/session/web/http/RequestResponsePostProcessor.java b/spring-session/src/main/java/org/springframework/session/web/http/RequestResponsePostProcessor.java
index 9c44effd..617e37de 100644
--- a/spring-session/src/main/java/org/springframework/session/web/http/RequestResponsePostProcessor.java
+++ b/spring-session/src/main/java/org/springframework/session/web/http/RequestResponsePostProcessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.web.http;
import javax.servlet.http.HttpServletRequest;
diff --git a/spring-session/src/main/java/org/springframework/session/web/http/SessionEventHttpSessionListenerAdapter.java b/spring-session/src/main/java/org/springframework/session/web/http/SessionEventHttpSessionListenerAdapter.java
index aa4566cd..e05a722a 100644
--- a/spring-session/src/main/java/org/springframework/session/web/http/SessionEventHttpSessionListenerAdapter.java
+++ b/spring-session/src/main/java/org/springframework/session/web/http/SessionEventHttpSessionListenerAdapter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.web.http;
import java.util.List;
@@ -51,16 +52,17 @@ public class SessionEventHttpSessionListenerAdapter implements ApplicationListen
* @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
*/
public void onApplicationEvent(AbstractSessionEvent event) {
- if(listeners.isEmpty()) {
+ if (this.listeners.isEmpty()) {
return;
}
HttpSessionEvent httpSessionEvent = createHttpSessionEvent(event);
- for(HttpSessionListener listener : listeners) {
- if(event instanceof SessionDestroyedEvent) {
+ for (HttpSessionListener listener : this.listeners) {
+ if (event instanceof SessionDestroyedEvent) {
listener.sessionDestroyed(httpSessionEvent);
- } else if(event instanceof SessionCreatedEvent) {
+ }
+ else if (event instanceof SessionCreatedEvent) {
listener.sessionCreated(httpSessionEvent);
}
}
@@ -68,7 +70,7 @@ public class SessionEventHttpSessionListenerAdapter implements ApplicationListen
private HttpSessionEvent createHttpSessionEvent(AbstractSessionEvent event) {
ExpiringSession session = event.getSession();
- HttpSession httpSession = new ExpiringSessionHttpSession(session, context);
+ HttpSession httpSession = new ExpiringSessionHttpSession(session, this.context);
HttpSessionEvent httpSessionEvent = new HttpSessionEvent(httpSession);
return httpSessionEvent;
}
diff --git a/spring-session/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java b/spring-session/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java
index ae765dfa..d838e4b8 100644
--- a/spring-session/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java
+++ b/spring-session/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java
@@ -1,18 +1,19 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
- * 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
+ * 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
+ * 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.
+ * 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.springframework.session.web.http;
import java.io.IOException;
@@ -30,6 +31,7 @@ import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.springframework.core.annotation.Order;
import org.springframework.session.ExpiringSession;
import org.springframework.session.Session;
@@ -58,6 +60,7 @@ import org.springframework.session.SessionRepository;
* to ensure the session is overridden and persisted properly.
*
*
+ * @param the {@link ExpiringSession} type.
* @since 1.0
* @author Rob Winch
*/
@@ -67,8 +70,14 @@ public class SessionRepositoryFilter extends OncePerR
private static final Log SESSION_LOGGER = LogFactory.getLog(SESSION_LOGGER_NAME);
+ /**
+ * The session repository request attribute name.
+ */
public static final String SESSION_REPOSITORY_ATTR = SessionRepository.class.getName();
+ /**
+ * The default filter order.
+ */
public static final int DEFAULT_ORDER = Integer.MIN_VALUE + 50;
private final SessionRepository sessionRepository;
@@ -78,12 +87,12 @@ public class SessionRepositoryFilter extends OncePerR
private MultiHttpSessionStrategy httpSessionStrategy = new CookieHttpSessionStrategy();
/**
- * Creates a new instance
+ * Creates a new instance.
*
* @param sessionRepository the SessionRepository to use. Cannot be null.
*/
public SessionRepositoryFilter(SessionRepository sessionRepository) {
- if(sessionRepository == null) {
+ if (sessionRepository == null) {
throw new IllegalArgumentException("sessionRepository cannot be null");
}
this.sessionRepository = sessionRepository;
@@ -95,7 +104,7 @@ public class SessionRepositoryFilter extends OncePerR
* @param httpSessionStrategy the {@link HttpSessionStrategy} to use. Cannot be null.
*/
public void setHttpSessionStrategy(HttpSessionStrategy httpSessionStrategy) {
- if(httpSessionStrategy == null) {
+ if (httpSessionStrategy == null) {
throw new IllegalArgumentException("httpSessionStrategy cannot be null");
}
this.httpSessionStrategy = new MultiHttpSessionStrategyAdapter(httpSessionStrategy);
@@ -107,24 +116,25 @@ public class SessionRepositoryFilter extends OncePerR
* @param httpSessionStrategy the {@link MultiHttpSessionStrategy} to use. Cannot be null.
*/
public void setHttpSessionStrategy(MultiHttpSessionStrategy httpSessionStrategy) {
- if(httpSessionStrategy == null) {
+ if (httpSessionStrategy == null) {
throw new IllegalArgumentException("httpSessionStrategy cannot be null");
}
this.httpSessionStrategy = httpSessionStrategy;
}
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
- request.setAttribute(SESSION_REPOSITORY_ATTR, sessionRepository);
+ request.setAttribute(SESSION_REPOSITORY_ATTR, this.sessionRepository);
- SessionRepositoryRequestWrapper wrappedRequest = new SessionRepositoryRequestWrapper(request, response, servletContext);
- SessionRepositoryResponseWrapper wrappedResponse = new SessionRepositoryResponseWrapper(wrappedRequest,response);
+ SessionRepositoryRequestWrapper wrappedRequest = new SessionRepositoryRequestWrapper(request, response, this.servletContext);
+ SessionRepositoryResponseWrapper wrappedResponse = new SessionRepositoryResponseWrapper(wrappedRequest, response);
- HttpServletRequest strategyRequest = httpSessionStrategy.wrapRequest(wrappedRequest, wrappedResponse);
- HttpServletResponse strategyResponse = httpSessionStrategy.wrapResponse(wrappedRequest, wrappedResponse);
+ HttpServletRequest strategyRequest = this.httpSessionStrategy.wrapRequest(wrappedRequest, wrappedResponse);
+ HttpServletResponse strategyResponse = this.httpSessionStrategy.wrapResponse(wrappedRequest, wrappedResponse);
try {
filterChain.doFilter(strategyRequest, strategyResponse);
- } finally {
+ }
+ finally {
wrappedRequest.commitSession();
}
}
@@ -144,11 +154,13 @@ public class SessionRepositoryFilter extends OncePerR
private final SessionRepositoryRequestWrapper request;
/**
+ * Create a new {@link SessionRepositoryResponseWrapper}.
+ * @param request the request to be wrapped
* @param response the response to be wrapped
*/
- public SessionRepositoryResponseWrapper(SessionRepositoryRequestWrapper request, HttpServletResponse response) {
+ SessionRepositoryResponseWrapper(SessionRepositoryRequestWrapper request, HttpServletResponse response) {
super(response);
- if(request == null) {
+ if (request == null) {
throw new IllegalArgumentException("request cannot be null");
}
this.request = request;
@@ -156,7 +168,7 @@ public class SessionRepositoryFilter extends OncePerR
@Override
protected void onResponseCommitted() {
- request.commitSession();
+ this.request.commitSession();
}
}
@@ -185,29 +197,31 @@ public class SessionRepositoryFilter extends OncePerR
*/
private void commitSession() {
HttpSessionWrapper wrappedSession = getCurrentSession();
- if(wrappedSession == null) {
- if(isInvalidateClientSession()) {
- httpSessionStrategy.onInvalidateSession(this, response);
+ if (wrappedSession == null) {
+ if (isInvalidateClientSession()) {
+ SessionRepositoryFilter.this.httpSessionStrategy.onInvalidateSession(this, this.response);
}
- } else {
+ }
+ else {
S session = wrappedSession.getSession();
- sessionRepository.save(session);
- if(!isRequestedSessionIdValid() || !session.getId().equals(getRequestedSessionId())) {
- httpSessionStrategy.onNewSession(session, this, response);
+ SessionRepositoryFilter.this.sessionRepository.save(session);
+ if (!isRequestedSessionIdValid() || !session.getId().equals(getRequestedSessionId())) {
+ SessionRepositoryFilter.this.httpSessionStrategy.onNewSession(session, this, this.response);
}
}
}
@SuppressWarnings("unchecked")
private HttpSessionWrapper getCurrentSession() {
- return (HttpSessionWrapper) getAttribute(CURRENT_SESSION_ATTR);
+ return (HttpSessionWrapper) getAttribute(this.CURRENT_SESSION_ATTR);
}
private void setCurrentSession(HttpSessionWrapper currentSession) {
- if(currentSession == null) {
- removeAttribute(CURRENT_SESSION_ATTR);
- } else {
- setAttribute(CURRENT_SESSION_ATTR, currentSession);
+ if (currentSession == null) {
+ removeAttribute(this.CURRENT_SESSION_ATTR);
+ }
+ else {
+ setAttribute(this.CURRENT_SESSION_ATTR, currentSession);
}
}
@@ -215,21 +229,21 @@ public class SessionRepositoryFilter extends OncePerR
public String changeSessionId() {
HttpSession session = getSession(false);
- if(session == null) {
+ if (session == null) {
throw new IllegalStateException("Cannot change session ID. There is no session associated with this request.");
}
// eagerly get session attributes in case implementation lazily loads them
- Map attrs = new HashMap();
+ Map attrs = new HashMap();
Enumeration iAttrNames = session.getAttributeNames();
- while(iAttrNames.hasMoreElements()) {
+ while (iAttrNames.hasMoreElements()) {
String attrName = iAttrNames.nextElement();
Object value = session.getAttribute(attrName);
attrs.put(attrName, value);
}
- sessionRepository.delete(session.getId());
+ SessionRepositoryFilter.this.sessionRepository.delete(session.getId());
HttpSessionWrapper original = getCurrentSession();
setCurrentSession(null);
@@ -237,7 +251,7 @@ public class SessionRepositoryFilter extends OncePerR
original.setSession(newSession.getSession());
newSession.setMaxInactiveInterval(session.getMaxInactiveInterval());
- for(Map.Entry attr : attrs.entrySet()) {
+ for (Map.Entry attr : attrs.entrySet()) {
String attrName = attr.getKey();
Object attrValue = attr.getValue();
newSession.setAttribute(attrName, attrValue);
@@ -246,29 +260,29 @@ public class SessionRepositoryFilter extends OncePerR
}
public boolean isRequestedSessionIdValid() {
- if(requestedSessionIdValid == null) {
+ if (this.requestedSessionIdValid == null) {
String sessionId = getRequestedSessionId();
S session = sessionId == null ? null : getSession(sessionId);
return isRequestedSessionIdValid(session);
}
- return requestedSessionIdValid;
+ return this.requestedSessionIdValid;
}
private boolean isRequestedSessionIdValid(S session) {
- if(requestedSessionIdValid == null) {
- requestedSessionIdValid = session != null;
+ if (this.requestedSessionIdValid == null) {
+ this.requestedSessionIdValid = session != null;
}
- return requestedSessionIdValid;
+ return this.requestedSessionIdValid;
}
private boolean isInvalidateClientSession() {
- return getCurrentSession() == null && requestedSessionInvalidated;
+ return getCurrentSession() == null && this.requestedSessionInvalidated;
}
private S getSession(String sessionId) {
- S session = sessionRepository.getSession(sessionId);
- if(session == null) {
+ S session = SessionRepositoryFilter.this.sessionRepository.getSession(sessionId);
+ if (session == null) {
return null;
}
session.setLastAccessedTime(System.currentTimeMillis());
@@ -278,13 +292,13 @@ public class SessionRepositoryFilter extends OncePerR
@Override
public HttpSessionWrapper getSession(boolean create) {
HttpSessionWrapper currentSession = getCurrentSession();
- if(currentSession != null) {
+ if (currentSession != null) {
return currentSession;
}
String requestedSessionId = getRequestedSessionId();
- if(requestedSessionId != null) {
+ if (requestedSessionId != null) {
S session = getSession(requestedSessionId);
- if(session != null) {
+ if (session != null) {
this.requestedSessionIdValid = true;
currentSession = new HttpSessionWrapper(session, getServletContext());
currentSession.setNew(false);
@@ -292,15 +306,15 @@ public class SessionRepositoryFilter extends OncePerR
return currentSession;
}
}
- if(!create) {
+ if (!create) {
return null;
}
- if(SESSION_LOGGER.isDebugEnabled()) {
+ if (SESSION_LOGGER.isDebugEnabled()) {
SESSION_LOGGER
.debug("A new session was created. To help you troubleshoot where the session was created we provided a StackTrace (this is not an error). You can prevent this from appearing by disabling DEBUG logging for "
+ SESSION_LOGGER_NAME, new RuntimeException("For debugging purposes only (not an error)"));
}
- S session = sessionRepository.createSession();
+ S session = SessionRepositoryFilter.this.sessionRepository.createSession();
session.setLastAccessedTime(System.currentTimeMillis());
currentSession = new HttpSessionWrapper(session, getServletContext());
setCurrentSession(currentSession);
@@ -308,8 +322,8 @@ public class SessionRepositoryFilter extends OncePerR
}
public ServletContext getServletContext() {
- if(servletContext != null) {
- return servletContext;
+ if (this.servletContext != null) {
+ return this.servletContext;
}
// Servlet 3.0+
return super.getServletContext();
@@ -322,7 +336,7 @@ public class SessionRepositoryFilter extends OncePerR
@Override
public String getRequestedSessionId() {
- return httpSessionStrategy.getRequestedSessionId(this);
+ return SessionRepositoryFilter.this.httpSessionStrategy.getRequestedSessionId(this);
}
/**
@@ -333,38 +347,45 @@ public class SessionRepositoryFilter extends OncePerR
*/
private final class HttpSessionWrapper extends ExpiringSessionHttpSession {
- public HttpSessionWrapper(S session, ServletContext servletContext) {
+ HttpSessionWrapper(S session, ServletContext servletContext) {
super(session, servletContext);
}
public void invalidate() {
super.invalidate();
- requestedSessionInvalidated = true;
+ SessionRepositoryRequestWrapper.this.requestedSessionInvalidated = true;
setCurrentSession(null);
- sessionRepository.delete(getId());
+ SessionRepositoryFilter.this.sessionRepository.delete(getId());
}
}
}
+ /**
+ * A delegating implementation of {@link MultiHttpSessionStrategy}.
+ */
static class MultiHttpSessionStrategyAdapter implements MultiHttpSessionStrategy {
private HttpSessionStrategy delegate;
- public MultiHttpSessionStrategyAdapter(HttpSessionStrategy delegate) {
+ /**
+ * Create a new {@link MultiHttpSessionStrategyAdapter} instance.
+ * @param delegate the delegate HTTP session strategy
+ */
+ MultiHttpSessionStrategyAdapter(HttpSessionStrategy delegate) {
this.delegate = delegate;
}
public String getRequestedSessionId(HttpServletRequest request) {
- return delegate.getRequestedSessionId(request);
+ return this.delegate.getRequestedSessionId(request);
}
public void onNewSession(Session session, HttpServletRequest request,
HttpServletResponse response) {
- delegate.onNewSession(session, request, response);
+ this.delegate.onNewSession(session, request, response);
}
public void onInvalidateSession(HttpServletRequest request,
HttpServletResponse response) {
- delegate.onInvalidateSession(request, response);
+ this.delegate.onInvalidateSession(request, response);
}
public HttpServletRequest wrapRequest(HttpServletRequest request,
diff --git a/spring-session/src/main/java/org/springframework/session/web/socket/config/annotation/AbstractSessionWebSocketMessageBrokerConfigurer.java b/spring-session/src/main/java/org/springframework/session/web/socket/config/annotation/AbstractSessionWebSocketMessageBrokerConfigurer.java
index 2e239fe9..d7cd9912 100644
--- a/spring-session/src/main/java/org/springframework/session/web/socket/config/annotation/AbstractSessionWebSocketMessageBrokerConfigurer.java
+++ b/spring-session/src/main/java/org/springframework/session/web/socket/config/annotation/AbstractSessionWebSocketMessageBrokerConfigurer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.web.socket.config.annotation;
import org.springframework.beans.factory.annotation.Autowired;
@@ -69,11 +70,10 @@ import org.springframework.web.util.UrlPathHelper;
* }
*
*
- * @author Rob Winch
- * @since 1.0
- *
* @param
* the type of ExpiringSession
+ * @author Rob Winch
+ * @since 1.0
*/
public abstract class AbstractSessionWebSocketMessageBrokerConfigurer extends AbstractWebSocketMessageBrokerConfigurer {
@@ -90,7 +90,7 @@ public abstract class AbstractSessionWebSocketMessageBrokerConfigurer sessionRepositoryInterceptor() {
- return new SessionRepositoryMessageInterceptor(sessionRepository);
+ return new SessionRepositoryMessageInterceptor(this.sessionRepository);
}
+ /**
+ * A {@link StompEndpointRegistry} that applies {@link HandshakeInterceptor}.
+ */
static class SessionStompEndpointRegistry implements StompEndpointRegistry {
private final WebMvcStompEndpointRegistry registry;
private final HandshakeInterceptor interceptor;
- public SessionStompEndpointRegistry(WebMvcStompEndpointRegistry registry,
+ SessionStompEndpointRegistry(WebMvcStompEndpointRegistry registry,
HandshakeInterceptor interceptor) {
this.registry = registry;
this.interceptor = interceptor;
}
public StompWebSocketEndpointRegistration addEndpoint(String... paths) {
- StompWebSocketEndpointRegistration endpoints = registry.addEndpoint(paths);
- endpoints.addInterceptors(interceptor);
+ StompWebSocketEndpointRegistration endpoints = this.registry.addEndpoint(paths);
+ endpoints.addInterceptors(this.interceptor);
return endpoints;
}
@@ -159,4 +162,4 @@ public abstract class AbstractSessionWebSocketMessageBrokerConfigurer> httpSessionIdToWsSessions = new ConcurrentHashMap>();
+ private final ConcurrentHashMap> httpSessionIdToWsSessions = new ConcurrentHashMap>();
public void onApplicationEvent(ApplicationEvent event) {
- if(event instanceof SessionDestroyedEvent) {
+ if (event instanceof SessionDestroyedEvent) {
SessionDestroyedEvent e = (SessionDestroyedEvent) event;
closeWsSessions(e.getSessionId());
- } else if(event instanceof SessionConnectEvent) {
+ }
+ else if (event instanceof SessionConnectEvent) {
SessionConnectEvent e = (SessionConnectEvent) event;
afterConnectionEstablished(e.getWebSocketSession());
- } else if(event instanceof SessionDisconnectEvent) {
+ }
+ else if (event instanceof SessionDisconnectEvent) {
SessionDisconnectEvent e = (SessionDisconnectEvent) event;
Map sessionAttributes = SimpMessageHeaderAccessor.getSessionAttributes(e.getMessage().getHeaders());
String httpSessionId = sessionAttributes == null ? null : SessionRepositoryMessageInterceptor.getSessionId(sessionAttributes);
@@ -70,7 +74,7 @@ public final class WebSocketRegistryListener implements ApplicationListener sessions = httpSessionIdToWsSessions.get(httpSessionId);
- if(sessions != null) {
+ Map sessions = this.httpSessionIdToWsSessions.get(httpSessionId);
+ if (sessions != null) {
boolean result = sessions.remove(wsSessionId) != null;
- if(logger.isDebugEnabled()) {
+ if (logger.isDebugEnabled()) {
logger.debug("Removal of " + wsSessionId + " was " + result);
}
- if(sessions.isEmpty()) {
- httpSessionIdToWsSessions.remove(httpSessionId);
- if(logger.isDebugEnabled()) {
+ if (sessions.isEmpty()) {
+ this.httpSessionIdToWsSessions.remove(httpSessionId);
+ if (logger.isDebugEnabled()) {
logger.debug("Removed the corresponding HTTP Session for " + wsSessionId + " since it contained no WebSocket mappings");
}
}
@@ -104,30 +108,31 @@ public final class WebSocketRegistryListener implements ApplicationListener sessions = httpSessionIdToWsSessions.get(httpSessionId);
- if(sessions == null) {
+ Map sessions = this.httpSessionIdToWsSessions.get(httpSessionId);
+ if (sessions == null) {
sessions =
- new ConcurrentHashMap();
- httpSessionIdToWsSessions.putIfAbsent(httpSessionId, sessions);
- sessions = httpSessionIdToWsSessions.get(httpSessionId);
+ new ConcurrentHashMap();
+ this.httpSessionIdToWsSessions.putIfAbsent(httpSessionId, sessions);
+ sessions = this.httpSessionIdToWsSessions.get(httpSessionId);
}
sessions.put(wsSession.getId(), wsSession);
}
private void closeWsSessions(String httpSessionId) {
- Map sessionsToClose = httpSessionIdToWsSessions.remove(httpSessionId);
- if(sessionsToClose == null) {
+ Map sessionsToClose = this.httpSessionIdToWsSessions.remove(httpSessionId);
+ if (sessionsToClose == null) {
return;
}
- if(logger.isDebugEnabled()) {
+ if (logger.isDebugEnabled()) {
logger.debug("Closing WebSocket connections associated to expired HTTP Session " + httpSessionId);
}
- for(WebSocketSession toClose : sessionsToClose.values()) {
+ for (WebSocketSession toClose : sessionsToClose.values()) {
try {
toClose.close(SESSION_EXPIRED_STATUS);
- } catch (IOException e) {
- logger.debug("Failed to close WebSocketSession (this is nothing to worry about but for debugging only)",e);
+ }
+ catch (IOException e) {
+ logger.debug("Failed to close WebSocketSession (this is nothing to worry about but for debugging only)", e);
}
}
}
-}
\ No newline at end of file
+}
diff --git a/spring-session/src/main/java/org/springframework/session/web/socket/server/SessionRepositoryMessageInterceptor.java b/spring-session/src/main/java/org/springframework/session/web/socket/server/SessionRepositoryMessageInterceptor.java
index f36352fd..b331729a 100644
--- a/spring-session/src/main/java/org/springframework/session/web/socket/server/SessionRepositoryMessageInterceptor.java
+++ b/spring-session/src/main/java/org/springframework/session/web/socket/server/SessionRepositoryMessageInterceptor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.session.web.socket.server;
import java.util.EnumSet;
@@ -62,6 +63,7 @@ import org.springframework.web.socket.server.HandshakeInterceptor;
* .
*
*
+ * @param the {@link ExpiringSession} type
* @author Rob Winch
* @since 1.0
*/
@@ -75,7 +77,7 @@ public final class SessionRepositoryMessageInterceptor matchingMessageTypes;
/**
- * Creates a new instance
+ * Creates a new instance.
*
* @param sessionRepository the {@link SessionRepository} to use. Cannot be null.
*/
@@ -105,27 +107,27 @@ public final class SessionRepositoryMessageInterceptor matchingMessageTypes) {
- Assert.notEmpty(matchingMessageTypes,"matchingMessageTypes cannot be null or empty");
+ Assert.notEmpty(matchingMessageTypes, "matchingMessageTypes cannot be null or empty");
this.matchingMessageTypes = matchingMessageTypes;
}
@Override
public Message> preSend(Message> message, MessageChannel channel) {
- if(message == null) {
+ if (message == null) {
return message;
}
SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(message.getHeaders());
- if(!this.matchingMessageTypes.contains(messageType)) {
+ if (!this.matchingMessageTypes.contains(messageType)) {
return super.preSend(message, channel);
}
Map sessionHeaders = SimpMessageHeaderAccessor.getSessionAttributes(message.getHeaders());
String sessionId = sessionHeaders == null ? null : (String) sessionHeaders.get(SPRING_SESSION_ID_ATTR_NAME);
if (sessionId != null) {
- S session = sessionRepository.getSession(sessionId);
+ S session = this.sessionRepository.getSession(sessionId);
if (session != null) {
// update the last accessed time
session.setLastAccessedTime(System.currentTimeMillis());
- sessionRepository.save(session);
+ this.sessionRepository.save(session);
}
}
return super.preSend(message, channel);
@@ -156,4 +158,4 @@ public final class SessionRepositoryMessageInterceptor attributes, String sessionId) {
attributes.put(SPRING_SESSION_ID_ATTR_NAME, sessionId);
}
-}
\ No newline at end of file
+}
diff --git a/spring-session/src/test/java/org/springframework/session/MapSessionRepositoryTests.java b/spring-session/src/test/java/org/springframework/session/MapSessionRepositoryTests.java
index da15f14e..475d780f 100644
--- a/spring-session/src/test/java/org/springframework/session/MapSessionRepositoryTests.java
+++ b/spring-session/src/test/java/org/springframework/session/MapSessionRepositoryTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,15 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.session;
-import static org.assertj.core.api.Assertions.*;
+package org.springframework.session;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class MapSessionRepositoryTests {
MapSessionRepository repository;
@@ -29,22 +30,22 @@ public class MapSessionRepositoryTests {
@Before
public void setup() {
- repository = new MapSessionRepository();
- session = new MapSession();
+ this.repository = new MapSessionRepository();
+ this.session = new MapSession();
}
@Test
public void getSessionExpired() {
- session.setMaxInactiveIntervalInSeconds(1);
- session.setLastAccessedTime(System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(5));
- repository.save(session);
+ this.session.setMaxInactiveIntervalInSeconds(1);
+ this.session.setLastAccessedTime(System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(5));
+ this.repository.save(this.session);
- assertThat(repository.getSession(session.getId())).isNull();
+ assertThat(this.repository.getSession(this.session.getId())).isNull();
}
@Test
public void createSessionDefaultExpiration() {
- ExpiringSession session = repository.createSession();
+ ExpiringSession session = this.repository.createSession();
assertThat(session).isInstanceOf(MapSession.class);
assertThat(session.getMaxInactiveIntervalInSeconds()).isEqualTo(new MapSession().getMaxInactiveIntervalInSeconds());
@@ -53,10 +54,10 @@ public class MapSessionRepositoryTests {
@Test
public void createSessionCustomDefaultExpiration() {
final int expectedMaxInterval = new MapSession().getMaxInactiveIntervalInSeconds() + 10;
- repository.setDefaultMaxInactiveInterval(expectedMaxInterval);
+ this.repository.setDefaultMaxInactiveInterval(expectedMaxInterval);
- ExpiringSession session = repository.createSession();
+ ExpiringSession session = this.repository.createSession();
assertThat(session.getMaxInactiveIntervalInSeconds()).isEqualTo(expectedMaxInterval);
}
-}
\ No newline at end of file
+}
diff --git a/spring-session/src/test/java/org/springframework/session/MapSessionTests.java b/spring-session/src/test/java/org/springframework/session/MapSessionTests.java
index af7880b5..3088495a 100644
--- a/spring-session/src/test/java/org/springframework/session/MapSessionTests.java
+++ b/spring-session/src/test/java/org/springframework/session/MapSessionTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,23 +13,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.session;
-import static org.assertj.core.api.Assertions.*;
+package org.springframework.session;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class MapSessionTests {
private MapSession session;
@Before
public void setup() {
- session = new MapSession();
- session.setLastAccessedTime(1413258262962L);
+ this.session = new MapSession();
+ this.session.setLastAccessedTime(1413258262962L);
}
@Test(expected = IllegalArgumentException.class)
@@ -43,45 +44,45 @@ public class MapSessionTests {
@Test
public void setAttributeNullObjectRemoves() {
String attr = "attr";
- session.setAttribute(attr, new Object());
- session.setAttribute(attr, null);
- assertThat(session.getAttributeNames()).isEmpty();
+ this.session.setAttribute(attr, new Object());
+ this.session.setAttribute(attr, null);
+ assertThat(this.session.getAttributeNames()).isEmpty();
}
@Test
public void equalsNonSessionFalse() {
- assertThat(session.equals(new Object())).isFalse();
+ assertThat(this.session.equals(new Object())).isFalse();
}
@Test
public void equalsCustomSession() {
CustomSession other = new CustomSession();
- session.setId(other.getId());
- assertThat(session.equals(other)).isTrue();
+ this.session.setId(other.getId());
+ assertThat(this.session.equals(other)).isTrue();
}
@Test
public void hashCodeEqualsIdHashCode() {
- session.setId("constantId");
- assertThat(session.hashCode()).isEqualTo(session.getId().hashCode());
+ this.session.setId("constantId");
+ assertThat(this.session.hashCode()).isEqualTo(this.session.getId().hashCode());
}
@Test
public void isExpiredExact() {
long now = 1413260062962L;
- assertThat(session.isExpired(now)).isTrue();
+ assertThat(this.session.isExpired(now)).isTrue();
}
@Test
public void isExpiredOneMsTooSoon() {
long now = 1413260062961L;
- assertThat(session.isExpired(now)).isFalse();
+ assertThat(this.session.isExpired(now)).isFalse();
}
@Test
public void isExpiredOneMsAfter() {
long now = 1413260062963L;
- assertThat(session.isExpired(now)).isTrue();
+ assertThat(this.session.isExpired(now)).isTrue();
}
static class CustomSession implements ExpiringSession {
@@ -131,4 +132,4 @@ public class MapSessionTests {
}
}
-}
\ No newline at end of file
+}
diff --git a/spring-session/src/test/java/org/springframework/session/config/annotation/web/http/EnableSpringHttpSessionCustomCookieSerializerTests.java b/spring-session/src/test/java/org/springframework/session/config/annotation/web/http/EnableSpringHttpSessionCustomCookieSerializerTests.java
index 339d4ad7..0f4a13bf 100644
--- a/spring-session/src/test/java/org/springframework/session/config/annotation/web/http/EnableSpringHttpSessionCustomCookieSerializerTests.java
+++ b/spring-session/src/test/java/org/springframework/session/config/annotation/web/http/EnableSpringHttpSessionCustomCookieSerializerTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,13 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.session.config.annotation.web.http;
-import static org.assertj.core.api.Assertions.*;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+package org.springframework.session.config.annotation.web.http;
import java.io.IOException;
import java.util.Arrays;
@@ -32,6 +27,7 @@ import javax.servlet.http.HttpServletRequest;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -47,6 +43,12 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
/**
* @author Rob Winch
*
@@ -70,22 +72,22 @@ public class EnableSpringHttpSessionCustomCookieSerializerTests {
@Before
public void setup() {
- chain = new MockFilterChain();
+ this.chain = new MockFilterChain();
}
@Test
public void usesReadSessionIds() throws Exception {
String sessionId = "sessionId";
- when(cookieSerializer.readCookieValues(any(HttpServletRequest.class))).thenReturn(Arrays.asList(sessionId));
+ given(this.cookieSerializer.readCookieValues(any(HttpServletRequest.class))).willReturn(Arrays.asList(sessionId));
- sessionRepositoryFilter.doFilter(request, response, chain);
+ this.sessionRepositoryFilter.doFilter(this.request, this.response, this.chain);
assertThat(getRequest().getRequestedSessionId()).isEqualTo(sessionId);
}
@Test
public void usesWrite() throws Exception {
- sessionRepositoryFilter.doFilter(request, response, new MockFilterChain() {
+ this.sessionRepositoryFilter.doFilter(this.request, this.response, new MockFilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response)
@@ -95,11 +97,11 @@ public class EnableSpringHttpSessionCustomCookieSerializerTests {
}
});
- verify(cookieSerializer).writeCookieValue(any(CookieValue.class));
+ verify(this.cookieSerializer).writeCookieValue(any(CookieValue.class));
}
private HttpServletRequest getRequest() {
- return (HttpServletRequest) chain.getRequest();
+ return (HttpServletRequest) this.chain.getRequest();
}
@EnableSpringHttpSession
diff --git a/spring-session/src/test/java/org/springframework/session/config/annotation/web/http/EnableSpringHttpSessionCustomMultiHttpSessionStrategyTests.java b/spring-session/src/test/java/org/springframework/session/config/annotation/web/http/EnableSpringHttpSessionCustomMultiHttpSessionStrategyTests.java
index 5d92c0ee..1624776a 100644
--- a/spring-session/src/test/java/org/springframework/session/config/annotation/web/http/EnableSpringHttpSessionCustomMultiHttpSessionStrategyTests.java
+++ b/spring-session/src/test/java/org/springframework/session/config/annotation/web/http/EnableSpringHttpSessionCustomMultiHttpSessionStrategyTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,12 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.session.config.annotation.web.http;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+package org.springframework.session.config.annotation.web.http;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -26,6 +22,7 @@ import javax.servlet.http.HttpServletResponse;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -40,6 +37,11 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
/**
* @author Rob Winch
*
@@ -63,18 +65,18 @@ public class EnableSpringHttpSessionCustomMultiHttpSessionStrategyTests {
@Before
public void setup() {
- chain = new MockFilterChain();
+ this.chain = new MockFilterChain();
}
@Test
public void wrapRequestAndResponseUsed() throws Exception {
- when(strategy.wrapRequest(any(HttpServletRequest.class), any(HttpServletResponse.class))).thenReturn(request);
- when(strategy.wrapResponse(any(HttpServletRequest.class), any(HttpServletResponse.class))).thenReturn(response);
+ given(this.strategy.wrapRequest(any(HttpServletRequest.class), any(HttpServletResponse.class))).willReturn(this.request);
+ given(this.strategy.wrapResponse(any(HttpServletRequest.class), any(HttpServletResponse.class))).willReturn(this.response);
- sessionRepositoryFilter.doFilter(request, response, chain);
+ this.sessionRepositoryFilter.doFilter(this.request, this.response, this.chain);
- verify(strategy).wrapRequest(any(HttpServletRequest.class), any(HttpServletResponse.class));
- verify(strategy).wrapResponse(any(HttpServletRequest.class), any(HttpServletResponse.class));
+ verify(this.strategy).wrapRequest(any(HttpServletRequest.class), any(HttpServletResponse.class));
+ verify(this.strategy).wrapResponse(any(HttpServletRequest.class), any(HttpServletResponse.class));
}
@EnableSpringHttpSession
diff --git a/spring-session/src/test/java/org/springframework/session/data/gemfire/AbstractGemFireOperationsSessionRepositoryTest.java b/spring-session/src/test/java/org/springframework/session/data/gemfire/AbstractGemFireOperationsSessionRepositoryTest.java
index bb4607cf..17c61e51 100644
--- a/spring-session/src/test/java/org/springframework/session/data/gemfire/AbstractGemFireOperationsSessionRepositoryTest.java
+++ b/spring-session/src/test/java/org/springframework/session/data/gemfire/AbstractGemFireOperationsSessionRepositoryTest.java
@@ -1,11 +1,11 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* 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
+ * 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,
@@ -16,24 +16,6 @@
package org.springframework.session.data.gemfire;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Fail.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Matchers.isA;
-import static org.mockito.Matchers.same;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepository.GemFireSession;
-import static org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInput;
@@ -48,6 +30,11 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
+import com.gemstone.gemfire.cache.AttributesMutator;
+import com.gemstone.gemfire.cache.EntryEvent;
+import com.gemstone.gemfire.cache.Region;
+import edu.umd.cs.mtc.MultithreadedTestCase;
+import edu.umd.cs.mtc.TestFramework;
import org.apache.commons.logging.Log;
import org.junit.Before;
import org.junit.Rule;
@@ -58,6 +45,7 @@ import org.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
+
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.gemfire.GemfireOperations;
@@ -72,18 +60,28 @@ import org.springframework.session.events.SessionDeletedEvent;
import org.springframework.session.events.SessionDestroyedEvent;
import org.springframework.session.events.SessionExpiredEvent;
-import com.gemstone.gemfire.cache.AttributesMutator;
-import com.gemstone.gemfire.cache.EntryEvent;
-import com.gemstone.gemfire.cache.Region;
-
-import edu.umd.cs.mtc.MultithreadedTestCase;
-import edu.umd.cs.mtc.TestFramework;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.BDDMockito.willAnswer;
+import static org.mockito.BDDMockito.willThrow;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.isA;
+import static org.mockito.Matchers.same;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
/**
* The AbstractGemFireOperationsSessionRepositoryTest class is a test suite of test cases testing the contract
* and functionality of the AbstractGemFireOperationsSessionRepository class.
*
* @author John Blum
+ * @since 1.1.0
* @see org.junit.Rule
* @see org.junit.Test
* @see org.junit.rules.ExpectedException
@@ -97,7 +95,6 @@ import edu.umd.cs.mtc.TestFramework;
* @see org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepository
* @see edu.umd.cs.mtc.MultithreadedTestCase
* @see edu.umd.cs.mtc.TestFramework
- * @since 1.1.0
*/
@RunWith(MockitoJUnitRunner.class)
public class AbstractGemFireOperationsSessionRepositoryTest {
@@ -117,9 +114,10 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
@Before
public void setup() {
- sessionRepository = new TestGemFireOperationsSessionRepository(mockGemfireOperations) {
- @Override Log newLogger() {
- return mockLog;
+ this.sessionRepository = new TestGemFireOperationsSessionRepository(this.mockGemfireOperations) {
+ @Override
+ Log newLogger() {
+ return AbstractGemFireOperationsSessionRepositoryTest.this.mockLog;
}
};
}
@@ -142,18 +140,18 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
ExpiringSession mockSession = mock(ExpiringSession.class, sessionId);
- when(mockSession.getId()).thenReturn(sessionId);
- when(mockSession.getCreationTime()).thenReturn(creationTime);
- when(mockSession.getLastAccessedTime()).thenReturn(lastAccessedTime);
- when(mockSession.getMaxInactiveIntervalInSeconds()).thenReturn(maxInactiveIntervalInSeconds);
+ given(mockSession.getId()).willReturn(sessionId);
+ given(mockSession.getCreationTime()).willReturn(creationTime);
+ given(mockSession.getLastAccessedTime()).willReturn(lastAccessedTime);
+ given(mockSession.getMaxInactiveIntervalInSeconds()).willReturn(maxInactiveIntervalInSeconds);
return mockSession;
}
@Test
public void constructGemFireOperationsSessionRepositoryWithNullTemplate() {
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("GemfireOperations must not be null");
+ this.expectedException.expect(IllegalArgumentException.class);
+ this.expectedException.expectMessage("GemfireOperations must not be null");
new TestGemFireOperationsSessionRepository(null);
}
@@ -161,11 +159,11 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
@SuppressWarnings("unchecked")
public void gemfireOperationsSessionRepositoryIsProperlyConstructedAndInitialized() throws Exception {
ApplicationEventPublisher mockApplicationEventPublisher = mock(ApplicationEventPublisher.class);
- AttributesMutator mockAttributesMutator = mock(AttributesMutator.class);
- Region mockRegion = mock(Region.class);
+ AttributesMutator mockAttributesMutator = mock(AttributesMutator.class);
+ Region mockRegion = mock(Region.class);
- when(mockRegion.getFullPath()).thenReturn("/Example");
- when(mockRegion.getAttributesMutator()).thenReturn(mockAttributesMutator);
+ given(mockRegion.getFullPath()).willReturn("/Example");
+ given(mockRegion.getAttributesMutator()).willReturn(mockAttributesMutator);
GemfireTemplate template = new GemfireTemplate(mockRegion);
@@ -196,24 +194,24 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
@Test
public void maxInactiveIntervalInSecondsAllowsNegativeValuesAndExtremelyLargeValues() {
- assertThat(sessionRepository.getMaxInactiveIntervalInSeconds()).isEqualTo(
+ assertThat(this.sessionRepository.getMaxInactiveIntervalInSeconds()).isEqualTo(
GemFireHttpSessionConfiguration.DEFAULT_MAX_INACTIVE_INTERVAL_IN_SECONDS);
- sessionRepository.setMaxInactiveIntervalInSeconds(-1);
+ this.sessionRepository.setMaxInactiveIntervalInSeconds(-1);
- assertThat(sessionRepository.getMaxInactiveIntervalInSeconds()).isEqualTo(-1);
+ assertThat(this.sessionRepository.getMaxInactiveIntervalInSeconds()).isEqualTo(-1);
- sessionRepository.setMaxInactiveIntervalInSeconds(Integer.MIN_VALUE);
+ this.sessionRepository.setMaxInactiveIntervalInSeconds(Integer.MIN_VALUE);
- assertThat(sessionRepository.getMaxInactiveIntervalInSeconds()).isEqualTo(Integer.MIN_VALUE);
+ assertThat(this.sessionRepository.getMaxInactiveIntervalInSeconds()).isEqualTo(Integer.MIN_VALUE);
- sessionRepository.setMaxInactiveIntervalInSeconds(3600);
+ this.sessionRepository.setMaxInactiveIntervalInSeconds(3600);
- assertThat(sessionRepository.getMaxInactiveIntervalInSeconds()).isEqualTo(3600);
+ assertThat(this.sessionRepository.getMaxInactiveIntervalInSeconds()).isEqualTo(3600);
- sessionRepository.setMaxInactiveIntervalInSeconds(Integer.MAX_VALUE);
+ this.sessionRepository.setMaxInactiveIntervalInSeconds(Integer.MAX_VALUE);
- assertThat(sessionRepository.getMaxInactiveIntervalInSeconds()).isEqualTo(Integer.MAX_VALUE);
+ assertThat(this.sessionRepository.getMaxInactiveIntervalInSeconds()).isEqualTo(Integer.MAX_VALUE);
}
@Test
@@ -222,11 +220,11 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
final String sessionId = "abc123";
final ExpiringSession mockSession = mock(ExpiringSession.class);
- when(mockSession.getId()).thenReturn(sessionId);
+ given(mockSession.getId()).willReturn(sessionId);
ApplicationEventPublisher mockApplicationEventPublisher = mock(ApplicationEventPublisher.class);
- doAnswer(new Answer() {
+ willAnswer(new Answer() {
public Void answer(InvocationOnMock invocation) throws Throwable {
ApplicationEvent applicationEvent = invocation.getArgumentAt(0, ApplicationEvent.class);
@@ -234,23 +232,23 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
AbstractSessionEvent sessionEvent = (AbstractSessionEvent) applicationEvent;
- assertThat(sessionEvent.getSource()).isEqualTo(sessionRepository);
+ assertThat(sessionEvent.getSource()).isEqualTo(AbstractGemFireOperationsSessionRepositoryTest.this.sessionRepository);
assertThat(sessionEvent.getSession()).isEqualTo(mockSession);
assertThat(sessionEvent.getSessionId()).isEqualTo(sessionId);
return null;
}
- }).when(mockApplicationEventPublisher).publishEvent(isA(ApplicationEvent.class));
+ }).given(mockApplicationEventPublisher).publishEvent(isA(ApplicationEvent.class));
EntryEvent mockEntryEvent = mock(EntryEvent.class);
- when(mockEntryEvent.getKey()).thenReturn(sessionId);
- when(mockEntryEvent.getNewValue()).thenReturn(mockSession);
+ given(mockEntryEvent.getKey()).willReturn(sessionId);
+ given(mockEntryEvent.getNewValue()).willReturn(mockSession);
- sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
- sessionRepository.afterCreate(mockEntryEvent);
+ this.sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
+ this.sessionRepository.afterCreate(mockEntryEvent);
- assertThat(sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
+ assertThat(this.sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
verify(mockEntryEvent, times(1)).getKey();
verify(mockEntryEvent, times(2)).getNewValue();
@@ -266,7 +264,7 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
ApplicationEventPublisher mockApplicationEventPublisher = mock(ApplicationEventPublisher.class);
- doAnswer(new Answer() {
+ willAnswer(new Answer() {
public Void answer(InvocationOnMock invocation) throws Throwable {
ApplicationEvent applicationEvent = invocation.getArgumentAt(0, ApplicationEvent.class);
@@ -274,23 +272,23 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
AbstractSessionEvent sessionEvent = (AbstractSessionEvent) applicationEvent;
- assertThat(sessionEvent.getSource()).isEqualTo(sessionRepository);
+ assertThat(sessionEvent.getSource()).isEqualTo(AbstractGemFireOperationsSessionRepositoryTest.this.sessionRepository);
assertThat(sessionEvent.getSession()).isNull();
assertThat(sessionEvent.getSessionId()).isEqualTo(sessionId);
return null;
}
- }).when(mockApplicationEventPublisher).publishEvent(isA(ApplicationEvent.class));
+ }).given(mockApplicationEventPublisher).publishEvent(isA(ApplicationEvent.class));
EntryEvent mockEntryEvent = mock(EntryEvent.class);
- when(mockEntryEvent.getKey()).thenReturn(sessionId);
- when(mockEntryEvent.getNewValue()).thenReturn(null);
+ given(mockEntryEvent.getKey()).willReturn(sessionId);
+ given(mockEntryEvent.getNewValue()).willReturn(null);
- sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
- sessionRepository.afterCreate(mockEntryEvent);
+ this.sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
+ this.sessionRepository.afterCreate(mockEntryEvent);
- assertThat(sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
+ assertThat(this.sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
verify(mockEntryEvent, times(1)).getKey();
verify(mockEntryEvent, times(2)).getNewValue();
@@ -301,16 +299,17 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void afterCreatedWithNonSessionTypeDoesNotPublishSessionCreatedEvent() {
- TestGemFireOperationsSessionRepository sessionRepository = new TestGemFireOperationsSessionRepository(mockGemfireOperations) {
- @Override protected void handleCreated(String sessionId, ExpiringSession session) {
+ TestGemFireOperationsSessionRepository sessionRepository = new TestGemFireOperationsSessionRepository(this.mockGemfireOperations) {
+ @Override
+ protected void handleCreated(String sessionId, ExpiringSession session) {
fail("handleCreated(..) should not have been called");
}
};
EntryEvent mockEntryEvent = mock(EntryEvent.class);
- when(mockEntryEvent.getKey()).thenReturn("abc123");
- when(mockEntryEvent.getNewValue()).thenReturn(new Tombstone());
+ given(mockEntryEvent.getKey()).willReturn("abc123");
+ given(mockEntryEvent.getNewValue()).willReturn(new Tombstone());
sessionRepository.afterCreate((EntryEvent) mockEntryEvent);
@@ -325,11 +324,11 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
final String sessionId = "def456";
final ExpiringSession mockSession = mock(ExpiringSession.class);
- when(mockSession.getId()).thenReturn(sessionId);
+ given(mockSession.getId()).willReturn(sessionId);
ApplicationEventPublisher mockApplicationEventPublisher = mock(ApplicationEventPublisher.class);
- doAnswer(new Answer() {
+ willAnswer(new Answer() {
public Void answer(InvocationOnMock invocation) throws Throwable {
ApplicationEvent applicationEvent = invocation.getArgumentAt(0, ApplicationEvent.class);
@@ -337,23 +336,23 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
AbstractSessionEvent sessionEvent = (AbstractSessionEvent) applicationEvent;
- assertThat(sessionEvent.getSource()).isEqualTo(sessionRepository);
+ assertThat(sessionEvent.getSource()).isEqualTo(AbstractGemFireOperationsSessionRepositoryTest.this.sessionRepository);
assertThat(sessionEvent.getSession()).isEqualTo(mockSession);
assertThat(sessionEvent.getSessionId()).isEqualTo(sessionId);
return null;
}
- }).when(mockApplicationEventPublisher).publishEvent(isA(ApplicationEvent.class));
+ }).given(mockApplicationEventPublisher).publishEvent(isA(ApplicationEvent.class));
EntryEvent mockEntryEvent = mock(EntryEvent.class);
- when(mockEntryEvent.getKey()).thenReturn(sessionId);
- when(mockEntryEvent.getOldValue()).thenReturn(mockSession);
+ given(mockEntryEvent.getKey()).willReturn(sessionId);
+ given(mockEntryEvent.getOldValue()).willReturn(mockSession);
- sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
- sessionRepository.afterDestroy(mockEntryEvent);
+ this.sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
+ this.sessionRepository.afterDestroy(mockEntryEvent);
- assertThat(sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
+ assertThat(this.sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
verify(mockEntryEvent, times(1)).getKey();
verify(mockEntryEvent, never()).getNewValue();
@@ -369,7 +368,7 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
ApplicationEventPublisher mockApplicationEventPublisher = mock(ApplicationEventPublisher.class);
- doAnswer(new Answer() {
+ willAnswer(new Answer() {
public Void answer(InvocationOnMock invocation) throws Throwable {
ApplicationEvent applicationEvent = invocation.getArgumentAt(0, ApplicationEvent.class);
@@ -377,23 +376,23 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
AbstractSessionEvent sessionEvent = (AbstractSessionEvent) applicationEvent;
- assertThat(sessionEvent.getSource()).isEqualTo(sessionRepository);
+ assertThat(sessionEvent.getSource()).isEqualTo(AbstractGemFireOperationsSessionRepositoryTest.this.sessionRepository);
assertThat(sessionEvent.getSession()).isNull();
assertThat(sessionEvent.getSessionId()).isEqualTo(sessionId);
return null;
}
- }).when(mockApplicationEventPublisher).publishEvent(isA(ApplicationEvent.class));
+ }).given(mockApplicationEventPublisher).publishEvent(isA(ApplicationEvent.class));
EntryEvent mockEntryEvent = mock(EntryEvent.class);
- when(mockEntryEvent.getKey()).thenReturn(sessionId);
- when(mockEntryEvent.getOldValue()).thenReturn(null);
+ given(mockEntryEvent.getKey()).willReturn(sessionId);
+ given(mockEntryEvent.getOldValue()).willReturn(null);
- sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
- sessionRepository.afterDestroy(mockEntryEvent);
+ this.sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
+ this.sessionRepository.afterDestroy(mockEntryEvent);
- assertThat(sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
+ assertThat(this.sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
verify(mockEntryEvent, times(1)).getKey();
verify(mockEntryEvent, never()).getNewValue();
@@ -408,7 +407,7 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
ApplicationEventPublisher mockApplicationEventPublisher = mock(ApplicationEventPublisher.class);
- doAnswer(new Answer() {
+ willAnswer(new Answer() {
public Void answer(InvocationOnMock invocation) throws Throwable {
ApplicationEvent applicationEvent = invocation.getArgumentAt(0, ApplicationEvent.class);
@@ -416,23 +415,23 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
AbstractSessionEvent sessionEvent = (AbstractSessionEvent) applicationEvent;
- assertThat(sessionEvent.getSource()).isEqualTo(sessionRepository);
+ assertThat(sessionEvent.getSource()).isEqualTo(AbstractGemFireOperationsSessionRepositoryTest.this.sessionRepository);
assertThat(sessionEvent.getSession()).isNull();
assertThat(sessionEvent.getSessionId()).isEqualTo(sessionId);
return null;
}
- }).when(mockApplicationEventPublisher).publishEvent(isA(ApplicationEvent.class));
+ }).given(mockApplicationEventPublisher).publishEvent(isA(ApplicationEvent.class));
EntryEvent mockEntryEvent = mock(EntryEvent.class);
- when(mockEntryEvent.getKey()).thenReturn(sessionId);
- when(mockEntryEvent.getOldValue()).thenReturn(new Tombstone());
+ given(mockEntryEvent.getKey()).willReturn(sessionId);
+ given(mockEntryEvent.getOldValue()).willReturn(new Tombstone());
- sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
- sessionRepository.afterDestroy((EntryEvent) mockEntryEvent);
+ this.sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
+ this.sessionRepository.afterDestroy((EntryEvent) mockEntryEvent);
- assertThat(sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
+ assertThat(this.sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
verify(mockEntryEvent, times(1)).getKey();
verify(mockEntryEvent, never()).getNewValue();
@@ -446,11 +445,11 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
final String sessionId = "ghi789";
final ExpiringSession mockSession = mock(ExpiringSession.class);
- when(mockSession.getId()).thenReturn(sessionId);
+ given(mockSession.getId()).willReturn(sessionId);
ApplicationEventPublisher mockApplicationEventPublisher = mock(ApplicationEventPublisher.class);
- doAnswer(new Answer() {
+ willAnswer(new Answer() {
public Void answer(InvocationOnMock invocation) throws Throwable {
ApplicationEvent applicationEvent = invocation.getArgumentAt(0, ApplicationEvent.class);
@@ -458,23 +457,23 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
AbstractSessionEvent sessionEvent = (AbstractSessionEvent) applicationEvent;
- assertThat(sessionEvent.getSource()).isEqualTo(sessionRepository);
+ assertThat(sessionEvent.getSource()).isEqualTo(AbstractGemFireOperationsSessionRepositoryTest.this.sessionRepository);
assertThat(sessionEvent.getSession()).isEqualTo(mockSession);
assertThat(sessionEvent.getSessionId()).isEqualTo(sessionId);
return null;
}
- }).when(mockApplicationEventPublisher).publishEvent(isA(ApplicationEvent.class));
+ }).given(mockApplicationEventPublisher).publishEvent(isA(ApplicationEvent.class));
EntryEvent mockEntryEvent = mock(EntryEvent.class);
- when(mockEntryEvent.getKey()).thenReturn(sessionId);
- when(mockEntryEvent.getOldValue()).thenReturn(mockSession);
+ given(mockEntryEvent.getKey()).willReturn(sessionId);
+ given(mockEntryEvent.getOldValue()).willReturn(mockSession);
- sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
- sessionRepository.afterInvalidate(mockEntryEvent);
+ this.sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
+ this.sessionRepository.afterInvalidate(mockEntryEvent);
- assertThat(sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
+ assertThat(this.sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
verify(mockEntryEvent, times(1)).getKey();
verify(mockEntryEvent, never()).getNewValue();
@@ -490,7 +489,7 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
ApplicationEventPublisher mockApplicationEventPublisher = mock(ApplicationEventPublisher.class);
- doAnswer(new Answer() {
+ willAnswer(new Answer() {
public Void answer(InvocationOnMock invocation) throws Throwable {
ApplicationEvent applicationEvent = invocation.getArgumentAt(0, ApplicationEvent.class);
@@ -498,23 +497,23 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
AbstractSessionEvent sessionEvent = (AbstractSessionEvent) applicationEvent;
- assertThat(sessionEvent.getSource()).isEqualTo(sessionRepository);
+ assertThat(sessionEvent.getSource()).isEqualTo(AbstractGemFireOperationsSessionRepositoryTest.this.sessionRepository);
assertThat(sessionEvent.getSession()).isNull();
assertThat(sessionEvent.getSessionId()).isEqualTo(sessionId);
return null;
}
- }).when(mockApplicationEventPublisher).publishEvent(isA(ApplicationEvent.class));
+ }).given(mockApplicationEventPublisher).publishEvent(isA(ApplicationEvent.class));
EntryEvent mockEntryEvent = mock(EntryEvent.class);
- when(mockEntryEvent.getKey()).thenReturn(sessionId);
- when(mockEntryEvent.getOldValue()).thenReturn(null);
+ given(mockEntryEvent.getKey()).willReturn(sessionId);
+ given(mockEntryEvent.getOldValue()).willReturn(null);
- sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
- sessionRepository.afterInvalidate(mockEntryEvent);
+ this.sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
+ this.sessionRepository.afterInvalidate(mockEntryEvent);
- assertThat(sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
+ assertThat(this.sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
verify(mockEntryEvent, times(1)).getKey();
verify(mockEntryEvent, never()).getNewValue();
@@ -529,7 +528,7 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
ApplicationEventPublisher mockApplicationEventPublisher = mock(ApplicationEventPublisher.class);
- doAnswer(new Answer() {
+ willAnswer(new Answer() {
public Void answer(InvocationOnMock invocation) throws Throwable {
ApplicationEvent applicationEvent = invocation.getArgumentAt(0, ApplicationEvent.class);
@@ -537,23 +536,23 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
AbstractSessionEvent sessionEvent = (AbstractSessionEvent) applicationEvent;
- assertThat(sessionEvent.getSource()).isEqualTo(sessionRepository);
+ assertThat(sessionEvent.getSource()).isEqualTo(AbstractGemFireOperationsSessionRepositoryTest.this.sessionRepository);
assertThat(sessionEvent.getSession()).isNull();
assertThat(sessionEvent.getSessionId()).isEqualTo(sessionId);
return null;
}
- }).when(mockApplicationEventPublisher).publishEvent(isA(ApplicationEvent.class));
+ }).given(mockApplicationEventPublisher).publishEvent(isA(ApplicationEvent.class));
EntryEvent mockEntryEvent = mock(EntryEvent.class);
- when(mockEntryEvent.getKey()).thenReturn(sessionId);
- when(mockEntryEvent.getOldValue()).thenReturn(new Tombstone());
+ given(mockEntryEvent.getKey()).willReturn(sessionId);
+ given(mockEntryEvent.getOldValue()).willReturn(new Tombstone());
- sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
- sessionRepository.afterInvalidate((EntryEvent) mockEntryEvent);
+ this.sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
+ this.sessionRepository.afterInvalidate((EntryEvent) mockEntryEvent);
- assertThat(sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
+ assertThat(this.sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
verify(mockEntryEvent, times(1)).getKey();
verify(mockEntryEvent, never()).getNewValue();
@@ -566,11 +565,11 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
final String sessionId = "abc123";
final ExpiringSession mockSession = mock(ExpiringSession.class);
- when(mockSession.getId()).thenReturn(sessionId);
+ given(mockSession.getId()).willReturn(sessionId);
ApplicationEventPublisher mockApplicationEventPublisher = mock(ApplicationEventPublisher.class);
- doAnswer(new Answer() {
+ willAnswer(new Answer() {
public Void answer(InvocationOnMock invocation) throws Throwable {
ApplicationEvent applicationEvent = invocation.getArgumentAt(0, ApplicationEvent.class);
@@ -578,18 +577,18 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
AbstractSessionEvent sessionEvent = (AbstractSessionEvent) applicationEvent;
- assertThat(sessionEvent.getSource()).isEqualTo(sessionRepository);
+ assertThat(sessionEvent.getSource()).isEqualTo(AbstractGemFireOperationsSessionRepositoryTest.this.sessionRepository);
assertThat(sessionEvent.getSession()).isEqualTo(mockSession);
assertThat(sessionEvent.getSessionId()).isEqualTo(sessionId);
return null;
}
- }).when(mockApplicationEventPublisher).publishEvent(isA(ApplicationEvent.class));
+ }).given(mockApplicationEventPublisher).publishEvent(isA(ApplicationEvent.class));
- sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
- sessionRepository.handleDeleted(sessionId, mockSession);
+ this.sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
+ this.sessionRepository.handleDeleted(sessionId, mockSession);
- assertThat(sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
+ assertThat(this.sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
verify(mockSession, times(1)).getId();
verify(mockApplicationEventPublisher, times(1)).publishEvent(isA(SessionDeletedEvent.class));
@@ -601,7 +600,7 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
ApplicationEventPublisher mockApplicationEventPublisher = mock(ApplicationEventPublisher.class);
- doAnswer(new Answer() {
+ willAnswer(new Answer() {
public Void answer(InvocationOnMock invocation) throws Throwable {
ApplicationEvent applicationEvent = invocation.getArgumentAt(0, ApplicationEvent.class);
@@ -609,18 +608,18 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
AbstractSessionEvent sessionEvent = (AbstractSessionEvent) applicationEvent;
- assertThat(sessionEvent.getSource()).isEqualTo(sessionRepository);
+ assertThat(sessionEvent.getSource()).isEqualTo(AbstractGemFireOperationsSessionRepositoryTest.this.sessionRepository);
assertThat(sessionEvent.getSession()).isNull();
assertThat(sessionEvent.getSessionId()).isEqualTo(sessionId);
return null;
}
- }).when(mockApplicationEventPublisher).publishEvent(isA(ApplicationEvent.class));
+ }).given(mockApplicationEventPublisher).publishEvent(isA(ApplicationEvent.class));
- sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
- sessionRepository.handleDeleted(sessionId, null);
+ this.sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
+ this.sessionRepository.handleDeleted(sessionId, null);
- assertThat(sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
+ assertThat(this.sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
verify(mockApplicationEventPublisher, times(1)).publishEvent(isA(SessionDeletedEvent.class));
}
@@ -631,16 +630,16 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
ApplicationEventPublisher mockApplicationEventPublisher = mock(ApplicationEventPublisher.class);
- doThrow(new IllegalStateException("test")).when(mockApplicationEventPublisher)
+ willThrow(new IllegalStateException("test")).given(mockApplicationEventPublisher)
.publishEvent(any(ApplicationEvent.class));
- sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
- sessionRepository.publishEvent(mockApplicationEvent);
+ this.sessionRepository.setApplicationEventPublisher(mockApplicationEventPublisher);
+ this.sessionRepository.publishEvent(mockApplicationEvent);
- assertThat(sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
+ assertThat(this.sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
verify(mockApplicationEventPublisher, times(1)).publishEvent(eq(mockApplicationEvent));
- verify(mockLog, times(1)).error(eq(String.format("error occurred publishing event (%1$s)", mockApplicationEvent)),
+ verify(this.mockLog, times(1)).error(eq(String.format("error occurred publishing event (%1$s)", mockApplicationEvent)),
isA(IllegalStateException.class));
}
@@ -648,7 +647,8 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
public void constructGemFireSessionWithDefaultInitialization() {
final long beforeOrAtCreationTime = System.currentTimeMillis();
- GemFireSession session = new GemFireSession();
+ AbstractGemFireOperationsSessionRepository.GemFireSession session =
+ new AbstractGemFireOperationsSessionRepository.GemFireSession();
assertThat(session.getId()).isNotNull();
assertThat(session.getCreationTime()).isGreaterThanOrEqualTo(beforeOrAtCreationTime);
@@ -662,7 +662,8 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
public void constructGemFireSessionWithId() {
final long beforeOrAtCreationTime = System.currentTimeMillis();
- GemFireSession session = new GemFireSession("1");
+ AbstractGemFireOperationsSessionRepository.GemFireSession session =
+ new AbstractGemFireOperationsSessionRepository.GemFireSession("1");
assertThat(session.getId()).isEqualTo("1");
assertThat(session.getCreationTime()).isGreaterThanOrEqualTo(beforeOrAtCreationTime);
@@ -674,19 +675,20 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
@Test
public void constructGemFireSessionWithSession() {
- final long expectedCreationTime = 1l;
- final long expectedLastAccessTime = 2l;
+ final long expectedCreationTime = 1L;
+ final long expectedLastAccessTime = 2L;
ExpiringSession mockSession = mockSession("2", expectedCreationTime, expectedLastAccessTime,
MAX_INACTIVE_INTERVAL_IN_SECONDS);
Set expectedAttributedNames = asSet("attrOne", "attrTwo");
- when(mockSession.getAttributeNames()).thenReturn(expectedAttributedNames);
- when(mockSession.getAttribute(eq("attrOne"))).thenReturn("testOne");
- when(mockSession.getAttribute(eq("attrTwo"))).thenReturn("testTwo");
+ given(mockSession.getAttributeNames()).willReturn(expectedAttributedNames);
+ given(mockSession.getAttribute(eq("attrOne"))).willReturn("testOne");
+ given(mockSession.getAttribute(eq("attrTwo"))).willReturn("testTwo");
- GemFireSession gemfireSession = new GemFireSession(mockSession);
+ AbstractGemFireOperationsSessionRepository.GemFireSession gemfireSession =
+ new AbstractGemFireOperationsSessionRepository.GemFireSession(mockSession);
assertThat(gemfireSession.getId()).isEqualTo("2");
assertThat(gemfireSession.getCreationTime()).isEqualTo(expectedCreationTime);
@@ -707,23 +709,24 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
@Test
public void constructGemFireSessionWithNullSession() {
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("The ExpiringSession to copy cannot be null");
- new GemFireSession((ExpiringSession) null);
+ this.expectedException.expect(IllegalArgumentException.class);
+ this.expectedException.expectMessage("The ExpiringSession to copy cannot be null");
+ new AbstractGemFireOperationsSessionRepository.GemFireSession((ExpiringSession) null);
}
@Test
public void constructGemFireSessionWithUnspecifiedId() {
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("ID must be specified");
- new GemFireSession(" ");
+ this.expectedException.expect(IllegalArgumentException.class);
+ this.expectedException.expectMessage("ID must be specified");
+ new AbstractGemFireOperationsSessionRepository.GemFireSession(" ");
}
@Test
public void createNewGemFireSession() {
final long beforeOrAtCreationTime = System.currentTimeMillis();
- GemFireSession session = GemFireSession.create(120);
+ AbstractGemFireOperationsSessionRepository.GemFireSession session =
+ AbstractGemFireOperationsSessionRepository.GemFireSession.create(120);
assertThat(session).isNotNull();
assertThat(session.getId()).isNotNull();
@@ -736,15 +739,16 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
@Test
public void fromExistingSession() {
- final long expectedCreationTime = 1l;
- final long expectedLastAccessedTime = 2l;
+ final long expectedCreationTime = 1L;
+ final long expectedLastAccessedTime = 2L;
ExpiringSession mockSession = mockSession("4", expectedCreationTime, expectedLastAccessedTime,
MAX_INACTIVE_INTERVAL_IN_SECONDS);
- when(mockSession.getAttributeNames()).thenReturn(Collections.emptySet());
+ given(mockSession.getAttributeNames()).willReturn(Collections.emptySet());
- GemFireSession gemfireSession = GemFireSession.from(mockSession);
+ AbstractGemFireOperationsSessionRepository.GemFireSession gemfireSession =
+ AbstractGemFireOperationsSessionRepository.GemFireSession.from(mockSession);
assertThat(gemfireSession).isNotNull();
assertThat(gemfireSession.getId()).isEqualTo("4");
@@ -766,7 +770,8 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
@Test
public void setGetAndRemoveAttribute() {
- GemFireSession session = GemFireSession.create(60);
+ AbstractGemFireOperationsSessionRepository.GemFireSession session =
+ AbstractGemFireOperationsSessionRepository.GemFireSession.create(60);
assertThat(session).isNotNull();
assertThat(session.getMaxInactiveIntervalInSeconds()).isEqualTo(60);
@@ -801,7 +806,8 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
public void isExpiredIsFalseWhenMaxInactiveIntervalIsNegative() {
final int expectedMaxInactiveIntervalInSeconds = -1;
- GemFireSession session = GemFireSession.create(expectedMaxInactiveIntervalInSeconds);
+ AbstractGemFireOperationsSessionRepository.GemFireSession session =
+ AbstractGemFireOperationsSessionRepository.GemFireSession.create(expectedMaxInactiveIntervalInSeconds);
assertThat(session).isNotNull();
assertThat(session.getMaxInactiveIntervalInSeconds()).isEqualTo(expectedMaxInactiveIntervalInSeconds);
@@ -812,7 +818,8 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
public void isExpiredIsFalseWhenSessionIsActive() {
final int expectedMaxInactiveIntervalInSeconds = (int) TimeUnit.HOURS.toSeconds(2);
- GemFireSession session = GemFireSession.create(expectedMaxInactiveIntervalInSeconds);
+ AbstractGemFireOperationsSessionRepository.GemFireSession session =
+ AbstractGemFireOperationsSessionRepository.GemFireSession.create(expectedMaxInactiveIntervalInSeconds);
assertThat(session).isNotNull();
assertThat(session.getMaxInactiveIntervalInSeconds()).isEqualTo(expectedMaxInactiveIntervalInSeconds);
@@ -829,7 +836,8 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
public void isExpiredIsTrueWhenSessionIsInactive() {
final int expectedMaxInactiveIntervalInSeconds = 60;
- GemFireSession session = GemFireSession.create(expectedMaxInactiveIntervalInSeconds);
+ AbstractGemFireOperationsSessionRepository.GemFireSession session =
+ AbstractGemFireOperationsSessionRepository.GemFireSession.create(expectedMaxInactiveIntervalInSeconds);
assertThat(session).isNotNull();
assertThat(session.getMaxInactiveIntervalInSeconds()).isEqualTo(expectedMaxInactiveIntervalInSeconds);
@@ -844,7 +852,8 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
@Test
public void setAndGetPrincipalName() {
- GemFireSession session = GemFireSession.create(0);
+ AbstractGemFireOperationsSessionRepository.GemFireSession session =
+ AbstractGemFireOperationsSessionRepository.GemFireSession.create(0);
assertThat(session).isNotNull();
assertThat(session.getPrincipalName()).isNull();
@@ -869,14 +878,16 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
@Test
public void sessionToData() throws Exception {
@SuppressWarnings("serial")
- GemFireSession session = new GemFireSession("1") {
- @Override void writeObject(Object obj, DataOutput out) throws IOException {
- assertThat(obj).isInstanceOf(GemFireSessionAttributes.class);
- assertThat(out).isNotNull();
- }
- };
+ AbstractGemFireOperationsSessionRepository.GemFireSession session =
+ new AbstractGemFireOperationsSessionRepository.GemFireSession("1") {
+ @Override
+ void writeObject(Object obj, DataOutput out) throws IOException {
+ assertThat(obj).isInstanceOf(AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes.class);
+ assertThat(out).isNotNull();
+ }
+ };
- session.setLastAccessedTime(123l);
+ session.setLastAccessedTime(123L);
session.setMaxInactiveIntervalInSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS);
session.setPrincipalName("jblum");
@@ -894,8 +905,8 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
@Test
public void sessionFromData() throws Exception {
- final long expectedCreationTime = 1l;
- final long expectedLastAccessedTime = 2l;
+ final long expectedCreationTime = 1L;
+ final long expectedLastAccessedTime = 2L;
final int expectedMaxInactiveIntervalInSeconds = (int) TimeUnit.HOURS.toSeconds(6);
@@ -903,24 +914,27 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
DataInput mockDataInput = mock(DataInput.class);
- when(mockDataInput.readUTF()).thenReturn("2").thenReturn(expectedPrincipalName);
- when(mockDataInput.readLong()).thenReturn(expectedCreationTime).thenReturn(expectedLastAccessedTime);
- when(mockDataInput.readInt()).thenReturn(expectedMaxInactiveIntervalInSeconds);
+ given(mockDataInput.readUTF()).willReturn("2").willReturn(expectedPrincipalName);
+ given(mockDataInput.readLong()).willReturn(expectedCreationTime).willReturn(expectedLastAccessedTime);
+ given(mockDataInput.readInt()).willReturn(expectedMaxInactiveIntervalInSeconds);
@SuppressWarnings("serial")
- GemFireSession session = new GemFireSession("1") {
- @Override @SuppressWarnings("unchecked")
- T readObject(DataInput in) throws ClassNotFoundException, IOException {
- assertThat(in).isNotNull();
+ AbstractGemFireOperationsSessionRepository.GemFireSession session =
+ new AbstractGemFireOperationsSessionRepository.GemFireSession("1") {
+ @Override
+ @SuppressWarnings("unchecked")
+ T readObject(DataInput in) throws ClassNotFoundException, IOException {
+ assertThat(in).isNotNull();
- GemFireSessionAttributes sessionAttributes = new GemFireSessionAttributes();
+ AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes sessionAttributes =
+ new AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes();
- sessionAttributes.setAttribute("attrOne", "testOne");
- sessionAttributes.setAttribute("attrTwo", "testTwo");
+ sessionAttributes.setAttribute("attrOne", "testOne");
+ sessionAttributes.setAttribute("attrTwo", "testTwo");
- return (T) sessionAttributes;
- }
- };
+ return (T) sessionAttributes;
+ }
+ };
session.fromData(mockDataInput);
@@ -950,12 +964,14 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
final long beforeOrAtCreationTime = System.currentTimeMillis();
@SuppressWarnings("serial")
- GemFireSession expectedSession = new GemFireSession("123") {
- @Override void writeObject(Object obj, DataOutput out) throws IOException {
- assertThat(obj).isInstanceOf(GemFireSessionAttributes.class);
- assertThat(out).isNotNull();
- }
- };
+ AbstractGemFireOperationsSessionRepository.GemFireSession expectedSession =
+ new AbstractGemFireOperationsSessionRepository.GemFireSession("123") {
+ @Override
+ void writeObject(Object obj, DataOutput out) throws IOException {
+ assertThat(obj).isInstanceOf(AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes.class);
+ assertThat(out).isNotNull();
+ }
+ };
assertThat(expectedSession.getId()).isEqualTo("123");
assertThat(expectedSession.getCreationTime()).isGreaterThanOrEqualTo(beforeOrAtCreationTime);
@@ -968,12 +984,14 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
expectedSession.toData(new DataOutputStream(outBytes));
@SuppressWarnings("serial")
- GemFireSession deserializedSession = new GemFireSession("0") {
- @SuppressWarnings("unchecked")
- @Override T readObject(DataInput in) throws ClassNotFoundException, IOException {
- return (T) new GemFireSessionAttributes();
- }
- };
+ AbstractGemFireOperationsSessionRepository.GemFireSession deserializedSession =
+ new AbstractGemFireOperationsSessionRepository.GemFireSession("0") {
+ @Override
+ @SuppressWarnings("unchecked")
+ T readObject(DataInput in) throws ClassNotFoundException, IOException {
+ return (T) new AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes();
+ }
+ };
deserializedSession.fromData(new DataInputStream(new ByteArrayInputStream(outBytes.toByteArray())));
@@ -987,12 +1005,13 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
@Test
public void hasDeltaWhenNoSessionChangesIsFalse() {
- assertThat(new GemFireSession().hasDelta()).isFalse();
+ assertThat(new AbstractGemFireOperationsSessionRepository.GemFireSession().hasDelta()).isFalse();
}
@Test
public void hasDeltaWhenSessionAttributesChangeIsTrue() {
- GemFireSession session = new GemFireSession();
+ AbstractGemFireOperationsSessionRepository.GemFireSession session =
+ new AbstractGemFireOperationsSessionRepository.GemFireSession();
assertThat(session.hasDelta()).isFalse();
@@ -1003,9 +1022,10 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
@Test
public void hasDeltaWhenSessionLastAccessedTimeIsUpdatedIsTrue() {
- final long expectedLastAccessTime = 1l;
+ final long expectedLastAccessTime = 1L;
- GemFireSession session = new GemFireSession();
+ AbstractGemFireOperationsSessionRepository.GemFireSession session =
+ new AbstractGemFireOperationsSessionRepository.GemFireSession();
assertThat(session.getLastAccessedTime()).isNotEqualTo(expectedLastAccessTime);
assertThat(session.hasDelta()).isFalse();
@@ -1025,7 +1045,8 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
public void hasDeltaWhenSessionMaxInactiveIntervalInSecondsIsUpdatedIsTrue() {
final int expectedMaxInactiveIntervalInSeconds = 300;
- GemFireSession session = new GemFireSession();
+ AbstractGemFireOperationsSessionRepository.GemFireSession session =
+ new AbstractGemFireOperationsSessionRepository.GemFireSession();
assertThat(session.getMaxInactiveIntervalInSeconds()).isNotEqualTo(expectedMaxInactiveIntervalInSeconds);
assertThat(session.hasDelta()).isFalse();
@@ -1046,14 +1067,16 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
final DataOutput mockDataOutput = mock(DataOutput.class);
@SuppressWarnings("serial")
- GemFireSession session = new GemFireSession() {
- @Override void writeObject(Object obj, DataOutput out) throws IOException {
- assertThat(String.valueOf(obj)).isEqualTo("test");
- assertThat(out).isSameAs(mockDataOutput);
- }
- };
+ AbstractGemFireOperationsSessionRepository.GemFireSession session =
+ new AbstractGemFireOperationsSessionRepository.GemFireSession() {
+ @Override
+ void writeObject(Object obj, DataOutput out) throws IOException {
+ assertThat(String.valueOf(obj)).isEqualTo("test");
+ assertThat(out).isSameAs(mockDataOutput);
+ }
+ };
- session.setLastAccessedTime(1l);
+ session.setLastAccessedTime(1L);
session.setMaxInactiveIntervalInSeconds(300);
session.setAttribute("attrOne", "test");
@@ -1063,7 +1086,7 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
assertThat(session.hasDelta()).isFalse();
- verify(mockDataOutput, times(1)).writeLong(eq(1l));
+ verify(mockDataOutput, times(1)).writeLong(eq(1L));
verify(mockDataOutput, times(1)).writeInt(eq(300));
verify(mockDataOutput, times(1)).writeInt(eq(1));
verify(mockDataOutput, times(1)).writeUTF(eq("attrOne"));
@@ -1073,22 +1096,24 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
public void sessionFromDelta() throws Exception {
final DataInput mockDataInput = mock(DataInput.class);
- when(mockDataInput.readLong()).thenReturn(1l);
- when(mockDataInput.readInt()).thenReturn(600).thenReturn(0);
+ given(mockDataInput.readLong()).willReturn(1L);
+ given(mockDataInput.readInt()).willReturn(600).willReturn(0);
@SuppressWarnings("serial")
- GemFireSession session = new GemFireSession() {
- @Override @SuppressWarnings("unchecked")
- T readObject(DataInput in) throws ClassNotFoundException, IOException {
- assertThat(in).isSameAs(mockDataInput);
- return (T) "test";
- }
- };
+ AbstractGemFireOperationsSessionRepository.GemFireSession session =
+ new AbstractGemFireOperationsSessionRepository.GemFireSession() {
+ @Override
+ @SuppressWarnings("unchecked")
+ T readObject(DataInput in) throws ClassNotFoundException, IOException {
+ assertThat(in).isSameAs(mockDataInput);
+ return (T) "test";
+ }
+ };
session.fromDelta(mockDataInput);
assertThat(session.hasDelta()).isFalse();
- assertThat(session.getLastAccessedTime()).isEqualTo(1l);
+ assertThat(session.getLastAccessedTime()).isEqualTo(1L);
assertThat(session.getMaxInactiveIntervalInSeconds()).isEqualTo(600);
assertThat(session.getAttributeNames().isEmpty()).isTrue();
@@ -1101,8 +1126,10 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
public void sessionComparisons() {
final long twoHoursAgo = (System.currentTimeMillis() - TimeUnit.HOURS.toMillis(2));
- GemFireSession sessionOne = new GemFireSession(mockSession("1", twoHoursAgo, MAX_INACTIVE_INTERVAL_IN_SECONDS));
- GemFireSession sessionTwo = new GemFireSession("2");
+ AbstractGemFireOperationsSessionRepository.GemFireSession sessionOne =
+ new AbstractGemFireOperationsSessionRepository.GemFireSession(mockSession("1", twoHoursAgo, MAX_INACTIVE_INTERVAL_IN_SECONDS));
+ AbstractGemFireOperationsSessionRepository.GemFireSession sessionTwo =
+ new AbstractGemFireOperationsSessionRepository.GemFireSession("2");
assertThat(sessionOne.getCreationTime()).isEqualTo(twoHoursAgo);
assertThat(sessionTwo.getCreationTime()).isGreaterThan(twoHoursAgo);
@@ -1113,15 +1140,17 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
@Test
public void sessionEqualsDifferentSessionBasedOnId() {
- GemFireSession sessionOne = new GemFireSession("1");
+ AbstractGemFireOperationsSessionRepository.GemFireSession sessionOne =
+ new AbstractGemFireOperationsSessionRepository.GemFireSession("1");
- sessionOne.setLastAccessedTime(12345l);
+ sessionOne.setLastAccessedTime(12345L);
sessionOne.setMaxInactiveIntervalInSeconds(120);
sessionOne.setPrincipalName("jblum");
- GemFireSession sessionTwo = new GemFireSession("1");
+ AbstractGemFireOperationsSessionRepository.GemFireSession sessionTwo =
+ new AbstractGemFireOperationsSessionRepository.GemFireSession("1");
- sessionTwo.setLastAccessedTime(67890l);
+ sessionTwo.setLastAccessedTime(67890L);
sessionTwo.setMaxInactiveIntervalInSeconds(300);
sessionTwo.setPrincipalName("rwinch");
@@ -1134,7 +1163,8 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
@Test
public void sessionHashCodeIsNotEqualToStringIdHashCode() {
- GemFireSession session = new GemFireSession("1");
+ AbstractGemFireOperationsSessionRepository.GemFireSession session =
+ new AbstractGemFireOperationsSessionRepository.GemFireSession("1");
assertThat(session.getId()).isEqualTo("1");
assertThat(session.hashCode()).isNotEqualTo("1".hashCode());
@@ -1144,11 +1174,12 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
public void sessionAttributesFromSession() {
Session mockSession = mock(Session.class);
- when(mockSession.getAttributeNames()).thenReturn(asSet("attrOne", "attrTwo"));
- when(mockSession.getAttribute(eq("attrOne"))).thenReturn("testOne");
- when(mockSession.getAttribute(eq("attrTwo"))).thenReturn("testTwo");
+ given(mockSession.getAttributeNames()).willReturn(asSet("attrOne", "attrTwo"));
+ given(mockSession.getAttribute(eq("attrOne"))).willReturn("testOne");
+ given(mockSession.getAttribute(eq("attrTwo"))).willReturn("testTwo");
- GemFireSessionAttributes sessionAttributes = new GemFireSessionAttributes();
+ AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes sessionAttributes =
+ new AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes();
assertThat(sessionAttributes.getAttributeNames().isEmpty()).isTrue();
@@ -1166,12 +1197,14 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
@Test
public void sessionAttributesFromSessionAttributes() {
- GemFireSessionAttributes source = new GemFireSessionAttributes();
+ AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes source =
+ new AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes();
source.setAttribute("attrOne", "testOne");
source.setAttribute("attrTwo", "testTwo");
- GemFireSessionAttributes target = new GemFireSessionAttributes();
+ AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes target =
+ new AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes();
assertThat(target.getAttributeNames().isEmpty()).isTrue();
@@ -1188,13 +1221,15 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
final DataOutput mockDataOutput = mock(DataOutput.class);
@SuppressWarnings("serial")
- GemFireSessionAttributes sessionAttributes = new GemFireSessionAttributes() {
- private int count = 0;
- @Override void writeObject(Object obj, DataOutput out) throws IOException {
- assertThat(Arrays.asList("testOne", "testTwo").get(count++)).isEqualTo(String.valueOf(obj));
- assertThat(out).isSameAs(mockDataOutput);
- }
- };
+ AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes sessionAttributes =
+ new AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes() {
+ private int count = 0;
+ @Override
+ void writeObject(Object obj, DataOutput out) throws IOException {
+ assertThat(Arrays.asList("testOne", "testTwo").get(count++)).isEqualTo(String.valueOf(obj));
+ assertThat(out).isSameAs(mockDataOutput);
+ }
+ };
sessionAttributes.setAttribute("attrOne", "testOne");
sessionAttributes.setAttribute("attrTwo", "testTwo");
@@ -1210,18 +1245,20 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
public void sessionAttributesFromData() throws Exception {
final DataInput mockDataInput = mock(DataInput.class);
- when(mockDataInput.readInt()).thenReturn(2);
- when(mockDataInput.readUTF()).thenReturn("attrOne").thenReturn("attrTwo");
+ given(mockDataInput.readInt()).willReturn(2);
+ given(mockDataInput.readUTF()).willReturn("attrOne").willReturn("attrTwo");
@SuppressWarnings("serial")
- GemFireSessionAttributes sessionAttributes = new GemFireSessionAttributes() {
- private int count = 0;
- @Override @SuppressWarnings("unchecked")
- T readObject(DataInput in) throws ClassNotFoundException, IOException {
- assertThat(in).isSameAs(mockDataInput);
- return (T) Arrays.asList("testOne", "testTwo").get(count++);
- }
- };
+ AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes sessionAttributes =
+ new AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes() {
+ private int count = 0;
+ @Override
+ @SuppressWarnings("unchecked")
+ T readObject(DataInput in) throws ClassNotFoundException, IOException {
+ assertThat(in).isSameAs(mockDataInput);
+ return (T) Arrays.asList("testOne", "testTwo").get(count++);
+ }
+ };
assertThat(sessionAttributes.getAttributeNames().isEmpty()).isTrue();
@@ -1238,12 +1275,13 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
@Test
public void sessionAttributesHasDeltaIsFalse() {
- assertThat(new GemFireSessionAttributes().hasDelta()).isFalse();
+ assertThat(new AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes().hasDelta()).isFalse();
}
@Test
public void sessionAttributesHasDeltaIsTrue() {
- GemFireSessionAttributes sessionAttributes = new GemFireSessionAttributes();
+ AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes sessionAttributes =
+ new AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes();
assertThat(sessionAttributes.hasDelta()).isFalse();
@@ -1258,13 +1296,15 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
final DataOutput mockDataOutput = mock(DataOutput.class);
@SuppressWarnings("serial")
- GemFireSessionAttributes sessionAttributes = new GemFireSessionAttributes() {
- private int count = 0;
- @Override void writeObject(Object obj, DataOutput out) throws IOException {
- assertThat(Arrays.asList("testOne", "testTwo", "testThree").get(count++)).isEqualTo(String.valueOf(obj));
- assertThat(out).isSameAs(mockDataOutput);
- }
- };
+ AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes sessionAttributes =
+ new AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes() {
+ private int count = 0;
+ @Override
+ void writeObject(Object obj, DataOutput out) throws IOException {
+ assertThat(Arrays.asList("testOne", "testTwo", "testThree").get(count++)).isEqualTo(String.valueOf(obj));
+ assertThat(out).isSameAs(mockDataOutput);
+ }
+ };
sessionAttributes.setAttribute("attrOne", "testOne");
sessionAttributes.setAttribute("attrTwo", "testTwo");
@@ -1304,18 +1344,20 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
public void sessionAttributesFromDelta() throws Exception {
final DataInput mockDataInput = mock(DataInput.class);
- when(mockDataInput.readInt()).thenReturn(2);
- when(mockDataInput.readUTF()).thenReturn("attrOne").thenReturn("attrTwo");
+ given(mockDataInput.readInt()).willReturn(2);
+ given(mockDataInput.readUTF()).willReturn("attrOne").willReturn("attrTwo");
@SuppressWarnings("serial")
- GemFireSessionAttributes sessionAttributes = new GemFireSessionAttributes() {
- private int count = 0;
- @Override @SuppressWarnings("unchecked")
- T readObject(DataInput in) throws ClassNotFoundException, IOException {
- assertThat(in).isSameAs(mockDataInput);
- return (T) Arrays.asList("testOne", "testTwo", "testThree").get(count++);
- }
- };
+ AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes sessionAttributes =
+ new AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes() {
+ private int count = 0;
+ @Override
+ @SuppressWarnings("unchecked")
+ T readObject(DataInput in) throws ClassNotFoundException, IOException {
+ assertThat(in).isSameAs(mockDataInput);
+ return (T) Arrays.asList("testOne", "testTwo", "testThree").get(count++);
+ }
+ };
sessionAttributes.setAttribute("attrOne", "one");
sessionAttributes.setAttribute("attrTwo", "two");
@@ -1338,8 +1380,8 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
verify(mockDataInput, times(2)).readUTF();
reset(mockDataInput);
- when(mockDataInput.readInt()).thenReturn(1);
- when(mockDataInput.readUTF()).thenReturn("attrTwo");
+ given(mockDataInput.readInt()).willReturn(1);
+ given(mockDataInput.readUTF()).willReturn("attrTwo");
sessionAttributes.setAttribute("attrOne", "one");
sessionAttributes.setAttribute("attrTwo", "two");
@@ -1364,7 +1406,8 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
@Test
public void sessionAttributesEntrySetIteratesAttributeNameValues() {
- GemFireSessionAttributes sessionAttributes = new GemFireSessionAttributes();
+ AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes sessionAttributes =
+ new AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes();
sessionAttributes.setAttribute("keyOne", "valueOne");
sessionAttributes.setAttribute("keyTwo", "valueTwo");
@@ -1420,27 +1463,27 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
private final long beforeOrAtCreationTime = System.currentTimeMillis();
- private GemFireSession session;
+ private AbstractGemFireOperationsSessionRepository.GemFireSession session;
private volatile long expectedCreationTime;
@Override
public void initialize() {
- session = new GemFireSession("1");
+ this.session = new AbstractGemFireOperationsSessionRepository.GemFireSession("1");
- assertThat(session).isNotNull();
- assertThat(session.getId()).isEqualTo("1");
- assertThat(session.getCreationTime()).isGreaterThanOrEqualTo(beforeOrAtCreationTime);
- assertThat(session.getLastAccessedTime()).isEqualTo(session.getCreationTime());
- assertThat(session.getMaxInactiveIntervalInSeconds()).isEqualTo(0);
- assertThat(session.getPrincipalName()).isNull();
- assertThat(session.getAttributeNames().isEmpty()).isTrue();
+ assertThat(this.session).isNotNull();
+ assertThat(this.session.getId()).isEqualTo("1");
+ assertThat(this.session.getCreationTime()).isGreaterThanOrEqualTo(this.beforeOrAtCreationTime);
+ assertThat(this.session.getLastAccessedTime()).isEqualTo(this.session.getCreationTime());
+ assertThat(this.session.getMaxInactiveIntervalInSeconds()).isEqualTo(0);
+ assertThat(this.session.getPrincipalName()).isNull();
+ assertThat(this.session.getAttributeNames().isEmpty()).isTrue();
- expectedCreationTime = session.getCreationTime();
+ this.expectedCreationTime = this.session.getCreationTime();
- session.setLastAccessedTime(0l);
- session.setMaxInactiveIntervalInSeconds(60);
- session.setPrincipalName("jblum");
+ this.session.setLastAccessedTime(0L);
+ this.session.setMaxInactiveIntervalInSeconds(60);
+ this.session.setPrincipalName("jblum");
}
public void thread1() {
@@ -1448,35 +1491,35 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
Thread.currentThread().setName("HTTP Request Processing Thread 1");
- assertThat(session).isNotNull();
- assertThat(session.getId()).isEqualTo("1");
- assertThat(session.getCreationTime()).isEqualTo(expectedCreationTime);
- assertThat(session.getLastAccessedTime()).isEqualTo(0l);
- assertThat(session.getMaxInactiveIntervalInSeconds()).isEqualTo(60);
- assertThat(session.getPrincipalName()).isEqualTo("jblum");
- assertThat(session.getAttributeNames().size()).isEqualTo(1);
- assertThat(String.valueOf(session.getAttribute(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME))).isEqualTo("jblum");
+ assertThat(this.session).isNotNull();
+ assertThat(this.session.getId()).isEqualTo("1");
+ assertThat(this.session.getCreationTime()).isEqualTo(this.expectedCreationTime);
+ assertThat(this.session.getLastAccessedTime()).isEqualTo(0L);
+ assertThat(this.session.getMaxInactiveIntervalInSeconds()).isEqualTo(60);
+ assertThat(this.session.getPrincipalName()).isEqualTo("jblum");
+ assertThat(this.session.getAttributeNames().size()).isEqualTo(1);
+ assertThat(String.valueOf(this.session.getAttribute(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME))).isEqualTo("jblum");
- session.setAttribute("tennis", "ping");
- session.setAttribute("junk", "test");
- session.setLastAccessedTime(1l);
- session.setMaxInactiveIntervalInSeconds(120);
- session.setPrincipalName("rwinch");
+ this.session.setAttribute("tennis", "ping");
+ this.session.setAttribute("junk", "test");
+ this.session.setLastAccessedTime(1L);
+ this.session.setMaxInactiveIntervalInSeconds(120);
+ this.session.setPrincipalName("rwinch");
waitForTick(2);
- assertThat(session).isNotNull();
- assertThat(session.getId()).isEqualTo("1");
- assertThat(session.getCreationTime()).isEqualTo(expectedCreationTime);
- assertThat(session.getLastAccessedTime()).isEqualTo(2l);
- assertThat(session.getMaxInactiveIntervalInSeconds()).isEqualTo(180);
- assertThat(session.getPrincipalName()).isEqualTo("ogierke");
- assertThat(session.getAttributeNames().size()).isEqualTo(3);
- assertThat(session.getAttributeNames().containsAll(asSet("tennis", "greeting"))).isTrue();
- assertThat(session.getAttributeNames().contains("junk")).isFalse();
- assertThat(session.getAttribute("junk")).isNull();
- assertThat(String.valueOf(session.getAttribute("tennis"))).isEqualTo("pong");
- assertThat(String.valueOf(session.getAttribute("greeting"))).isEqualTo("hello");
+ assertThat(this.session).isNotNull();
+ assertThat(this.session.getId()).isEqualTo("1");
+ assertThat(this.session.getCreationTime()).isEqualTo(this.expectedCreationTime);
+ assertThat(this.session.getLastAccessedTime()).isEqualTo(2L);
+ assertThat(this.session.getMaxInactiveIntervalInSeconds()).isEqualTo(180);
+ assertThat(this.session.getPrincipalName()).isEqualTo("ogierke");
+ assertThat(this.session.getAttributeNames().size()).isEqualTo(3);
+ assertThat(this.session.getAttributeNames().containsAll(asSet("tennis", "greeting"))).isTrue();
+ assertThat(this.session.getAttributeNames().contains("junk")).isFalse();
+ assertThat(this.session.getAttribute("junk")).isNull();
+ assertThat(String.valueOf(this.session.getAttribute("tennis"))).isEqualTo("pong");
+ assertThat(String.valueOf(this.session.getAttribute("greeting"))).isEqualTo("hello");
}
public void thread2() {
@@ -1487,28 +1530,28 @@ public class AbstractGemFireOperationsSessionRepositoryTest {
waitForTick(1);
assertTick(1);
- assertThat(session).isNotNull();
- assertThat(session.getId()).isEqualTo("1");
- assertThat(session.getCreationTime()).isEqualTo(expectedCreationTime);
- assertThat(session.getLastAccessedTime()).isEqualTo(1l);
- assertThat(session.getMaxInactiveIntervalInSeconds()).isEqualTo(120);
- assertThat(session.getPrincipalName()).isEqualTo("rwinch");
- assertThat(session.getAttributeNames().size()).isEqualTo(3);
- assertThat(session.getAttributeNames().containsAll(asSet("tennis", "junk"))).isTrue();
- assertThat(String.valueOf(session.getAttribute("junk"))).isEqualTo("test");
- assertThat(String.valueOf(session.getAttribute("tennis"))).isEqualTo("ping");
+ assertThat(this.session).isNotNull();
+ assertThat(this.session.getId()).isEqualTo("1");
+ assertThat(this.session.getCreationTime()).isEqualTo(this.expectedCreationTime);
+ assertThat(this.session.getLastAccessedTime()).isEqualTo(1L);
+ assertThat(this.session.getMaxInactiveIntervalInSeconds()).isEqualTo(120);
+ assertThat(this.session.getPrincipalName()).isEqualTo("rwinch");
+ assertThat(this.session.getAttributeNames().size()).isEqualTo(3);
+ assertThat(this.session.getAttributeNames().containsAll(asSet("tennis", "junk"))).isTrue();
+ assertThat(String.valueOf(this.session.getAttribute("junk"))).isEqualTo("test");
+ assertThat(String.valueOf(this.session.getAttribute("tennis"))).isEqualTo("ping");
- session.setAttribute("tennis", "pong");
- session.setAttribute("greeting", "hello");
- session.removeAttribute("junk");
- session.setLastAccessedTime(2l);
- session.setMaxInactiveIntervalInSeconds(180);
- session.setPrincipalName("ogierke");
+ this.session.setAttribute("tennis", "pong");
+ this.session.setAttribute("greeting", "hello");
+ this.session.removeAttribute("junk");
+ this.session.setLastAccessedTime(2L);
+ this.session.setMaxInactiveIntervalInSeconds(180);
+ this.session.setPrincipalName("ogierke");
}
@Override
public void finish() {
- session = null;
+ this.session = null;
}
}
diff --git a/spring-session/src/test/java/org/springframework/session/data/gemfire/GemFireOperationsSessionRepositoryTest.java b/spring-session/src/test/java/org/springframework/session/data/gemfire/GemFireOperationsSessionRepositoryTest.java
index ee23dd0c..9a4c35aa 100644
--- a/spring-session/src/test/java/org/springframework/session/data/gemfire/GemFireOperationsSessionRepositoryTest.java
+++ b/spring-session/src/test/java/org/springframework/session/data/gemfire/GemFireOperationsSessionRepositoryTest.java
@@ -1,11 +1,11 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2014-2016 the original author or authors.
*
* 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
+ * 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,
@@ -16,27 +16,14 @@
package org.springframework.session.data.gemfire;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Matchers.isA;
-import static org.mockito.Matchers.same;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.springframework.session.FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME;
-import static org.springframework.session.data.gemfire.GemFireOperationsSessionRepository.FIND_SESSIONS_BY_INDEX_NAME_VALUE_QUERY;
-import static org.springframework.session.data.gemfire.GemFireOperationsSessionRepository.FIND_SESSIONS_BY_PRINCIPAL_NAME_QUERY;
-import static org.springframework.session.data.gemfire.GemFireOperationsSessionRepository.GemFireSession;
-
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.TimeUnit;
+import com.gemstone.gemfire.cache.AttributesMutator;
+import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.query.SelectResults;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -45,23 +32,34 @@ import org.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
+
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.gemfire.GemfireAccessor;
import org.springframework.data.gemfire.GemfireOperations;
import org.springframework.session.ExpiringSession;
+import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.events.AbstractSessionEvent;
import org.springframework.session.events.SessionDeletedEvent;
-import com.gemstone.gemfire.cache.AttributesMutator;
-import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.cache.query.SelectResults;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.BDDMockito.willAnswer;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.isA;
+import static org.mockito.Matchers.same;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
/**
* The GemFireOperationsSessionRepositoryTest class is a test suite of test cases testing the contract and functionality
* of the GemFireOperationsSessionRepository class.
*
* @author John Blum
+ * @since 1.1.0
* @see org.junit.Test
* @see org.junit.runner.RunWith
* @see org.mockito.Mock
@@ -69,7 +67,6 @@ import com.gemstone.gemfire.cache.query.SelectResults;
* @see org.mockito.runners.MockitoJUnitRunner
* @see org.springframework.session.data.gemfire.GemFireOperationsSessionRepository
* @see com.gemstone.gemfire.cache.Region
- * @since 1.1.0
*/
@RunWith(MockitoJUnitRunner.class)
public class GemFireOperationsSessionRepositoryTest {
@@ -92,25 +89,25 @@ public class GemFireOperationsSessionRepositoryTest {
@Before
public void setup() throws Exception {
- when(mockRegion.getAttributesMutator()).thenReturn(mockAttributesMutator);
- when(mockRegion.getFullPath()).thenReturn("/Example");
- when(mockTemplate.getRegion()).thenReturn(mockRegion);
+ given(this.mockRegion.getAttributesMutator()).willReturn(this.mockAttributesMutator);
+ given(this.mockRegion.getFullPath()).willReturn("/Example");
+ given(this.mockTemplate.