Remove deprecations
This commit removes `SessionMessageListener` and `CookieHttpSessionStrategy#setCookieName` which both were deprecated since `1.1.0`, and `SessionEntryListener` which was deprecated since `1.3.0`. Fixes gh-675
This commit is contained in:
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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.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;
|
||||
import org.springframework.data.redis.connection.MessageListener;
|
||||
import org.springframework.session.events.SessionDeletedEvent;
|
||||
import org.springframework.session.events.SessionExpiredEvent;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Listen for Redis {@link Message} notifications. If it is a "del" translate into a
|
||||
* {@link SessionDeletedEvent}. If it is an "expired" translate into a
|
||||
* {@link SessionExpiredEvent}.
|
||||
*
|
||||
* @author Rob Winch
|
||||
* @author Mark Anderson
|
||||
* @since 1.0
|
||||
* @deprecated Use {@link RedisOperationsSessionRepository} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public class SessionMessageListener implements MessageListener {
|
||||
private static final Log logger = LogFactory.getLog(SessionMessageListener.class);
|
||||
|
||||
private final ApplicationEventPublisher eventPublisher;
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*
|
||||
* @param eventPublisher the {@link ApplicationEventPublisher} to use. Cannot be null.
|
||||
*/
|
||||
public SessionMessageListener(ApplicationEventPublisher eventPublisher) {
|
||||
Assert.notNull(eventPublisher, "eventPublisher cannot be null");
|
||||
this.eventPublisher = eventPublisher;
|
||||
}
|
||||
|
||||
public void onMessage(Message message, byte[] pattern) {
|
||||
byte[] messageChannel = message.getChannel();
|
||||
byte[] messageBody = message.getBody();
|
||||
if (messageChannel == null || messageBody == null) {
|
||||
return;
|
||||
}
|
||||
String channel = new String(messageChannel);
|
||||
if (!(channel.endsWith(":del") || channel.endsWith(":expired"))) {
|
||||
return;
|
||||
}
|
||||
String body = new String(messageBody);
|
||||
if (!body.startsWith("spring:session:sessions:")) {
|
||||
return;
|
||||
}
|
||||
|
||||
int beginIndex = body.lastIndexOf(":") + 1;
|
||||
int endIndex = body.length();
|
||||
String sessionId = body.substring(beginIndex, endIndex);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Publishing SessionDestroyedEvent for session " + sessionId);
|
||||
}
|
||||
|
||||
if (channel.endsWith(":del")) {
|
||||
publishEvent(new SessionDeletedEvent(this, sessionId));
|
||||
}
|
||||
else {
|
||||
publishEvent(new SessionExpiredEvent(this, sessionId));
|
||||
}
|
||||
}
|
||||
|
||||
private void publishEvent(ApplicationEvent event) {
|
||||
try {
|
||||
this.eventPublisher.publishEvent(event);
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
logger.error("Error publishing " + event + ".", ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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.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;
|
||||
import org.springframework.session.events.SessionDeletedEvent;
|
||||
import org.springframework.session.events.SessionExpiredEvent;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Listen for events on the Hazelcast-backed SessionRepository and translate those events
|
||||
* into the corresponding Spring Session events. Publish the Spring Session events with
|
||||
* the given {@link ApplicationEventPublisher}.
|
||||
* <ul>
|
||||
* <li>entryAdded - {@link SessionCreatedEvent}</li>
|
||||
* <li>entryEvicted - {@link SessionExpiredEvent}</li>
|
||||
* <li>entryRemoved - {@link SessionDeletedEvent}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Tommy Ludwig
|
||||
* @author Mark Anderson
|
||||
* @since 1.1
|
||||
* @deprecated Use {@link HazelcastSessionRepository} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public class SessionEntryListener implements EntryAddedListener<String, ExpiringSession>,
|
||||
EntryEvictedListener<String, ExpiringSession>,
|
||||
EntryRemovedListener<String, ExpiringSession> {
|
||||
private static final Log logger = LogFactory.getLog(SessionEntryListener.class);
|
||||
|
||||
private ApplicationEventPublisher eventPublisher;
|
||||
|
||||
public SessionEntryListener(ApplicationEventPublisher eventPublisher) {
|
||||
Assert.notNull(eventPublisher, "eventPublisher cannot be null");
|
||||
this.eventPublisher = eventPublisher;
|
||||
}
|
||||
|
||||
public void entryAdded(EntryEvent<String, ExpiringSession> event) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Session created with id: " + event.getValue().getId());
|
||||
}
|
||||
this.eventPublisher.publishEvent(new SessionCreatedEvent(this, event.getValue()));
|
||||
}
|
||||
|
||||
public void entryEvicted(EntryEvent<String, ExpiringSession> event) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Session expired with id: " + event.getOldValue().getId());
|
||||
}
|
||||
this.eventPublisher
|
||||
.publishEvent(new SessionExpiredEvent(this, event.getOldValue()));
|
||||
}
|
||||
|
||||
public void entryRemoved(EntryEvent<String, ExpiringSession> event) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Session deleted with id: " + event.getOldValue().getId());
|
||||
}
|
||||
this.eventPublisher
|
||||
.publishEvent(new SessionDeletedEvent(this, event.getOldValue()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2017 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.
|
||||
@@ -37,8 +37,9 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A {@link HttpSessionStrategy} that uses a cookie to obtain the session from.
|
||||
* Specifically, this implementation will allow specifying a cookie name using
|
||||
* {@link CookieHttpSessionStrategy#setCookieName(String)}. The default is "SESSION".
|
||||
* Specifically, this implementation will allow specifying a cookie serialization strategy
|
||||
* using {@link CookieHttpSessionStrategy#setCookieSerializer(CookieSerializer)}. The
|
||||
* default is cookie name is "SESSION".
|
||||
*
|
||||
* When a session is created, the HTTP response will have a cookie with the specified
|
||||
* cookie name and the value of the session id. The cookie will be marked as a session
|
||||
@@ -296,18 +297,6 @@ public final class CookieHttpSessionStrategy
|
||||
this.cookieSerializer = cookieSerializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the cookie to be used.
|
||||
* @param cookieName the name of the cookie to be used
|
||||
* @deprecated use {@link #setCookieSerializer(CookieSerializer)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setCookieName(String cookieName) {
|
||||
DefaultCookieSerializer serializer = new DefaultCookieSerializer();
|
||||
serializer.setCookieName(cookieName);
|
||||
this.cookieSerializer = serializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the delimiter between a session alias and a session id when deserializing a
|
||||
* cookie. The default is " " This is useful when using
|
||||
|
||||
@@ -1,171 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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.data.redis;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.data.redis.connection.Message;
|
||||
import org.springframework.session.events.SessionDestroyedEvent;
|
||||
import org.springframework.session.events.SessionExpiredEvent;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.willThrow;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rob Winch
|
||||
* @author Mark Anderson
|
||||
*
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@SuppressWarnings("deprecation")
|
||||
public class SessionMessageListenerTests {
|
||||
@Mock
|
||||
ApplicationEventPublisher eventPublisher;
|
||||
|
||||
@Mock
|
||||
Message message;
|
||||
|
||||
@Captor
|
||||
ArgumentCaptor<SessionDestroyedEvent> deletedEvent;
|
||||
|
||||
@Captor
|
||||
ArgumentCaptor<SessionExpiredEvent> expiredEvent;
|
||||
|
||||
byte[] pattern;
|
||||
|
||||
SessionMessageListener listener;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.listener = new SessionMessageListener(this.eventPublisher);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void constructorNullEventPublisher() {
|
||||
new SessionMessageListener(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onMessageNullBody() throws Exception {
|
||||
this.listener.onMessage(this.message, this.pattern);
|
||||
|
||||
verifyZeroInteractions(this.eventPublisher);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onMessageDel() throws Exception {
|
||||
mockMessage("__keyevent@0__:del", "spring:session:sessions:123");
|
||||
|
||||
this.listener.onMessage(this.message, this.pattern);
|
||||
|
||||
verify(this.eventPublisher).publishEvent(this.deletedEvent.capture());
|
||||
assertThat(this.deletedEvent.getValue().getSessionId()).isEqualTo("123");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onMessageDelSource() throws Exception {
|
||||
mockMessage("__keyevent@0__:del", "spring:session:sessions:123");
|
||||
|
||||
this.listener.onMessage(this.message, this.pattern);
|
||||
|
||||
verify(this.eventPublisher).publishEvent(this.deletedEvent.capture());
|
||||
assertThat(this.deletedEvent.getValue().getSource()).isEqualTo(this.listener);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onMessageExpiredSource() throws Exception {
|
||||
mockMessage("__keyevent@0__:expired", "spring:session:sessions:123");
|
||||
|
||||
this.listener.onMessage(this.message, this.pattern);
|
||||
|
||||
verify(this.eventPublisher).publishEvent(this.expiredEvent.capture());
|
||||
assertThat(this.expiredEvent.getValue().getSource()).isEqualTo(this.listener);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onMessageExpired() throws Exception {
|
||||
mockMessage("__keyevent@0__:expired", "spring:session:sessions:543");
|
||||
|
||||
this.listener.onMessage(this.message, this.pattern);
|
||||
|
||||
verify(this.eventPublisher).publishEvent(this.expiredEvent.capture());
|
||||
assertThat(this.expiredEvent.getValue().getSessionId()).isEqualTo("543");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onMessageHset() throws Exception {
|
||||
mockMessage("__keyevent@0__:hset", "spring:session:sessions:123");
|
||||
|
||||
this.listener.onMessage(this.message, this.pattern);
|
||||
|
||||
verifyZeroInteractions(this.eventPublisher);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onMessageWrongKeyPrefix() throws Exception {
|
||||
mockMessage("__keyevent@0__:del", "spring:session:sessionsNo:123");
|
||||
|
||||
this.listener.onMessage(this.message, this.pattern);
|
||||
|
||||
verifyZeroInteractions(this.eventPublisher);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onMessageRename() throws Exception {
|
||||
mockMessage("__keyevent@0__:rename", "spring:session:sessions:123");
|
||||
|
||||
this.listener.onMessage(this.message, this.pattern);
|
||||
|
||||
verifyZeroInteractions(this.eventPublisher);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onMessageEventPublisherErrorCaught() throws Exception {
|
||||
mockMessage("__keyevent@0__:del", "spring:session:sessions:123");
|
||||
willThrow(new IllegalStateException("Test Exceptions are caught"))
|
||||
.given(this.eventPublisher).publishEvent(any(ApplicationEvent.class));
|
||||
|
||||
this.listener.onMessage(this.message, this.pattern);
|
||||
|
||||
verify(this.eventPublisher).publishEvent(any(ApplicationEvent.class));
|
||||
}
|
||||
|
||||
private void mockMessage(String channel, String body)
|
||||
throws UnsupportedEncodingException {
|
||||
given(this.message.getBody()).willReturn(bytes(body));
|
||||
given(this.message.getChannel()).willReturn(bytes(channel));
|
||||
}
|
||||
|
||||
private static byte[] bytes(String s) throws UnsupportedEncodingException {
|
||||
return s.getBytes("UTF-8");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2017 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.
|
||||
@@ -196,12 +196,6 @@ public class CookieHttpSessionStrategyTests {
|
||||
assertThat(getSessionId()).isEqualTo(existing.getId());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void setCookieNameNull() throws Exception {
|
||||
this.strategy.setCookieName(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encodeURLNoExistingQuery() {
|
||||
assertThat(this.strategy.encodeURL("/url", "2")).isEqualTo("/url?_s=2");
|
||||
@@ -725,9 +719,10 @@ public class CookieHttpSessionStrategyTests {
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void setCookieName(String cookieName) {
|
||||
this.strategy.setCookieName(cookieName);
|
||||
DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
|
||||
cookieSerializer.setCookieName(cookieName);
|
||||
this.strategy.setCookieSerializer(cookieSerializer);
|
||||
this.cookieName = cookieName;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user