Skip to content

Commit ee4df64

Browse files
wilkinsonarwinch
authored andcommitted
Align wth Servlet 6.0 API
1 parent d850762 commit ee4df64

File tree

3 files changed

+2
-212
lines changed

3 files changed

+2
-212
lines changed

gradle/dependency-management.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ dependencyManagement {
2222
dependency 'com.zaxxer:HikariCP:5.0.1'
2323
dependency 'edu.umd.cs.mtc:multithreadedtc:1.01'
2424
dependency 'io.lettuce:lettuce-core:6.2.1.RELEASE'
25-
dependency 'jakarta.servlet:jakarta.servlet-api:5.0.0'
25+
dependency 'jakarta.servlet:jakarta.servlet-api:6.0.0'
2626
dependency 'mysql:mysql-connector-java:8.0.30'
2727
dependencySet(group: 'org.apache.derby', version: '10.16.1.1') {
2828
entry 'derby'

spring-session-core/src/main/java/org/springframework/session/web/http/HttpSessionAdapter.java

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,14 +19,11 @@
1919
import java.time.Duration;
2020
import java.util.Collections;
2121
import java.util.Enumeration;
22-
import java.util.NoSuchElementException;
23-
import java.util.Set;
2422

2523
import jakarta.servlet.ServletContext;
2624
import jakarta.servlet.http.HttpSession;
2725
import jakarta.servlet.http.HttpSessionBindingEvent;
2826
import jakarta.servlet.http.HttpSessionBindingListener;
29-
import jakarta.servlet.http.HttpSessionContext;
3027

3128
import org.apache.commons.logging.Log;
3229
import org.apache.commons.logging.LogFactory;
@@ -41,7 +38,6 @@
4138
* @author Vedran Pavic
4239
* @since 1.1
4340
*/
44-
@SuppressWarnings("deprecation")
4541
class HttpSessionAdapter<S extends Session> implements HttpSession {
4642

4743
private static final Log logger = LogFactory.getLog(HttpSessionAdapter.class);
@@ -101,35 +97,18 @@ public int getMaxInactiveInterval() {
10197
return (int) this.session.getMaxInactiveInterval().getSeconds();
10298
}
10399

104-
@Override
105-
public HttpSessionContext getSessionContext() {
106-
return NOOP_SESSION_CONTEXT;
107-
}
108-
109100
@Override
110101
public Object getAttribute(String name) {
111102
checkState();
112103
return this.session.getAttribute(name);
113104
}
114105

115-
@Override
116-
public Object getValue(String name) {
117-
return getAttribute(name);
118-
}
119-
120106
@Override
121107
public Enumeration<String> getAttributeNames() {
122108
checkState();
123109
return Collections.enumeration(this.session.getAttributeNames());
124110
}
125111

126-
@Override
127-
public String[] getValueNames() {
128-
checkState();
129-
Set<String> attrs = this.session.getAttributeNames();
130-
return attrs.toArray(new String[0]);
131-
}
132-
133112
@Override
134113
public void setAttribute(String name, Object value) {
135114
checkState();
@@ -156,11 +135,6 @@ public void setAttribute(String name, Object value) {
156135
}
157136
}
158137

159-
@Override
160-
public void putValue(String name, Object value) {
161-
setAttribute(name, value);
162-
}
163-
164138
@Override
165139
public void removeAttribute(String name) {
166140
checkState();
@@ -176,11 +150,6 @@ public void removeAttribute(String name) {
176150
}
177151
}
178152

179-
@Override
180-
public void removeValue(String name) {
181-
removeAttribute(name);
182-
}
183-
184153
@Override
185154
public void invalidate() {
186155
checkState();
@@ -203,32 +172,4 @@ private void checkState() {
203172
}
204173
}
205174

206-
private static final HttpSessionContext NOOP_SESSION_CONTEXT = new HttpSessionContext() {
207-
208-
@Override
209-
public HttpSession getSession(String sessionId) {
210-
return null;
211-
}
212-
213-
@Override
214-
public Enumeration<String> getIds() {
215-
return EMPTY_ENUMERATION;
216-
}
217-
218-
};
219-
220-
private static final Enumeration<String> EMPTY_ENUMERATION = new Enumeration<String>() {
221-
222-
@Override
223-
public boolean hasMoreElements() {
224-
return false;
225-
}
226-
227-
@Override
228-
public String nextElement() {
229-
throw new NoSuchElementException("a");
230-
}
231-
232-
};
233-
234175
}

spring-session-core/src/test/java/org/springframework/session/web/http/SessionRepositoryFilterTests.java

Lines changed: 0 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.Collections;
2525
import java.util.HashMap;
2626
import java.util.Map;
27-
import java.util.NoSuchElementException;
2827
import java.util.concurrent.ConcurrentHashMap;
2928
import java.util.concurrent.TimeUnit;
3029
import java.util.concurrent.atomic.AtomicBoolean;
@@ -40,7 +39,6 @@
4039
import jakarta.servlet.http.HttpSession;
4140
import jakarta.servlet.http.HttpSessionBindingEvent;
4241
import jakarta.servlet.http.HttpSessionBindingListener;
43-
import jakarta.servlet.http.HttpSessionContext;
4442

4543
import org.assertj.core.data.Offset;
4644
import org.junit.jupiter.api.BeforeEach;
@@ -316,52 +314,6 @@ public void doFilter(HttpServletRequest wrappedRequest) {
316314
});
317315
}
318316

319-
@Test
320-
void doFilterValue() throws Exception {
321-
final String ATTR = "ATTR";
322-
final String VALUE = "VALUE";
323-
doFilter(new DoInFilter() {
324-
@Override
325-
public void doFilter(HttpServletRequest wrappedRequest) {
326-
wrappedRequest.getSession().putValue(ATTR, VALUE);
327-
assertThat(wrappedRequest.getSession().getValue(ATTR)).isEqualTo(VALUE);
328-
assertThat(Arrays.asList(wrappedRequest.getSession().getValueNames())).containsOnly(ATTR);
329-
}
330-
});
331-
332-
nextRequest();
333-
334-
doFilter(new DoInFilter() {
335-
@Override
336-
public void doFilter(HttpServletRequest wrappedRequest) {
337-
assertThat(wrappedRequest.getSession().getValue(ATTR)).isEqualTo(VALUE);
338-
assertThat(Arrays.asList(wrappedRequest.getSession().getValueNames())).containsOnly(ATTR);
339-
}
340-
});
341-
342-
nextRequest();
343-
344-
doFilter(new DoInFilter() {
345-
@Override
346-
public void doFilter(HttpServletRequest wrappedRequest) {
347-
assertThat(wrappedRequest.getSession().getValue(ATTR)).isEqualTo(VALUE);
348-
349-
wrappedRequest.getSession().removeValue(ATTR);
350-
351-
assertThat(wrappedRequest.getSession().getValue(ATTR)).isNull();
352-
}
353-
});
354-
355-
nextRequest();
356-
357-
doFilter(new DoInFilter() {
358-
@Override
359-
public void doFilter(HttpServletRequest wrappedRequest) {
360-
assertThat(wrappedRequest.getSession().getValue(ATTR)).isNull();
361-
}
362-
});
363-
}
364-
365317
@Test
366318
void doFilterIsNewTrue() throws Exception {
367319
doFilter(new DoInFilter() {
@@ -637,27 +589,6 @@ public void doFilter(HttpServletRequest wrappedRequest) {
637589
assertThat(session.getSecure()).describedAs("Session Cookie should be marked as Secure").isTrue();
638590
}
639591

640-
@Test
641-
void doFilterSessionContext() throws Exception {
642-
doFilter(new DoInFilter() {
643-
@Override
644-
public void doFilter(HttpServletRequest wrappedRequest) {
645-
HttpSessionContext sessionContext = wrappedRequest.getSession().getSessionContext();
646-
assertThat(sessionContext).isNotNull();
647-
assertThat(sessionContext.getSession("a")).isNull();
648-
assertThat(sessionContext.getIds()).isNotNull();
649-
assertThat(sessionContext.getIds().hasMoreElements()).isFalse();
650-
651-
try {
652-
sessionContext.getIds().nextElement();
653-
fail("Expected Exception");
654-
}
655-
catch (NoSuchElementException ignored) {
656-
}
657-
}
658-
});
659-
}
660-
661592
// --- saving
662593

663594
@Test
@@ -741,23 +672,6 @@ public void doFilter(HttpServletRequest wrappedRequest) {
741672
});
742673
}
743674

744-
@Test
745-
void doFilterInvalidateValueIllegalState() throws Exception {
746-
doFilter(new DoInFilter() {
747-
@Override
748-
public void doFilter(HttpServletRequest wrappedRequest) {
749-
HttpSession session = wrappedRequest.getSession();
750-
session.invalidate();
751-
try {
752-
session.getValue("attr");
753-
fail("Expected Exception");
754-
}
755-
catch (IllegalStateException ignored) {
756-
}
757-
}
758-
});
759-
}
760-
761675
@Test
762676
void doFilterInvalidateAttributeNamesIllegalState() throws Exception {
763677
doFilter(new DoInFilter() {
@@ -775,23 +689,6 @@ public void doFilter(HttpServletRequest wrappedRequest) {
775689
});
776690
}
777691

778-
@Test
779-
void doFilterInvalidateValueNamesIllegalState() throws Exception {
780-
doFilter(new DoInFilter() {
781-
@Override
782-
public void doFilter(HttpServletRequest wrappedRequest) {
783-
HttpSession session = wrappedRequest.getSession();
784-
session.invalidate();
785-
try {
786-
session.getValueNames();
787-
fail("Expected Exception");
788-
}
789-
catch (IllegalStateException ignored) {
790-
}
791-
}
792-
});
793-
}
794-
795692
@Test
796693
void doFilterInvalidateSetAttributeIllegalState() throws Exception {
797694
doFilter(new DoInFilter() {
@@ -809,23 +706,6 @@ public void doFilter(HttpServletRequest wrappedRequest) {
809706
});
810707
}
811708

812-
@Test
813-
void doFilterInvalidatePutValueIllegalState() throws Exception {
814-
doFilter(new DoInFilter() {
815-
@Override
816-
public void doFilter(HttpServletRequest wrappedRequest) {
817-
HttpSession session = wrappedRequest.getSession();
818-
session.invalidate();
819-
try {
820-
session.putValue("a", "b");
821-
fail("Expected Exception");
822-
}
823-
catch (IllegalStateException ignored) {
824-
}
825-
}
826-
});
827-
}
828-
829709
@Test
830710
void doFilterInvalidateRemoveAttributeIllegalState() throws Exception {
831711
doFilter(new DoInFilter() {
@@ -843,23 +723,6 @@ public void doFilter(HttpServletRequest wrappedRequest) {
843723
});
844724
}
845725

846-
@Test
847-
void doFilterInvalidateRemoveValueIllegalState() throws Exception {
848-
doFilter(new DoInFilter() {
849-
@Override
850-
public void doFilter(HttpServletRequest wrappedRequest) {
851-
HttpSession session = wrappedRequest.getSession();
852-
session.invalidate();
853-
try {
854-
session.removeValue("name");
855-
fail("Expected Exception");
856-
}
857-
catch (IllegalStateException ignored) {
858-
}
859-
}
860-
});
861-
}
862-
863726
@Test
864727
void doFilterInvalidateNewIllegalState() throws Exception {
865728
doFilter(new DoInFilter() {
@@ -921,20 +784,6 @@ public void doFilter(HttpServletRequest wrappedRequest) {
921784
});
922785
}
923786

924-
@Test
925-
void doFilterInvalidateSessionContext() throws Exception {
926-
doFilter(new DoInFilter() {
927-
@Override
928-
public void doFilter(HttpServletRequest wrappedRequest) {
929-
HttpSession session = wrappedRequest.getSession();
930-
session.invalidate();
931-
932-
// no exception
933-
session.getSessionContext();
934-
}
935-
});
936-
}
937-
938787
@Test
939788
void doFilterInvalidateMaxInteractiveInterval() throws Exception {
940789
doFilter(new DoInFilter() {

0 commit comments

Comments
 (0)