Skip to content

Commit 2d43c31

Browse files
Polish Contribution
Issue gh-2285
1 parent 7360723 commit 2d43c31

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 the original author or authors.
2+
* Copyright 2014-2023 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.
@@ -30,7 +30,6 @@
3030
import jakarta.servlet.http.HttpServletRequestWrapper;
3131
import jakarta.servlet.http.HttpServletResponse;
3232
import jakarta.servlet.http.HttpSession;
33-
3433
import org.apache.commons.logging.Log;
3534
import org.apache.commons.logging.LogFactory;
3635

@@ -205,7 +204,7 @@ private final class SessionRepositoryRequestWrapper extends HttpServletRequestWr
205204

206205
private boolean requestedSessionInvalidated;
207206

208-
private boolean hasCommitedInInclude;
207+
private boolean hasCommittedInInclude;
209208

210209
private SessionRepositoryRequestWrapper(HttpServletRequest request, HttpServletResponse response) {
211210
super(request);
@@ -340,7 +339,7 @@ public String getRequestedSessionId() {
340339
@Override
341340
public RequestDispatcher getRequestDispatcher(String path) {
342341
RequestDispatcher requestDispatcher = super.getRequestDispatcher(path);
343-
return new SessionCommittingRequestDispatcher(requestDispatcher, this);
342+
return new SessionCommittingRequestDispatcher(requestDispatcher);
344343
}
345344

346345
private S getRequestedSession() {
@@ -399,11 +398,8 @@ private final class SessionCommittingRequestDispatcher implements RequestDispatc
399398

400399
private final RequestDispatcher delegate;
401400

402-
private final SessionRepositoryRequestWrapper wrapper;
403-
404-
SessionCommittingRequestDispatcher(RequestDispatcher delegate, SessionRepositoryRequestWrapper wrapper) {
401+
SessionCommittingRequestDispatcher(RequestDispatcher delegate) {
405402
this.delegate = delegate;
406-
this.wrapper = wrapper;
407403
}
408404

409405
@Override
@@ -413,9 +409,9 @@ public void forward(ServletRequest request, ServletResponse response) throws Ser
413409

414410
@Override
415411
public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException {
416-
if (!this.wrapper.hasCommitedInInclude) {
412+
if (!SessionRepositoryRequestWrapper.this.hasCommittedInInclude) {
417413
SessionRepositoryRequestWrapper.this.commitSession();
418-
this.wrapper.hasCommitedInInclude = true;
414+
SessionRepositoryRequestWrapper.this.hasCommittedInInclude = true;
419415
}
420416
this.delegate.include(request, response);
421417
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 the original author or authors.
2+
* Copyright 2014-2023 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.
@@ -1326,11 +1326,11 @@ void doFilterIncludeCommitSessionOnce() throws Exception {
13261326
this.sessionRepository.save(session);
13271327
SessionRepository<MapSession> sessionRepository = spy(this.sessionRepository);
13281328
setSessionCookie(session.getId());
1329-
1329+
13301330
given(sessionRepository.findById(session.getId())).willReturn(session);
13311331

13321332
this.filter = new SessionRepositoryFilter<>(sessionRepository);
1333-
1333+
13341334
doFilter(new DoInFilter() {
13351335
@Override
13361336
public void doFilter(HttpServletRequest wrappedRequest, HttpServletResponse wrappedResponse)
@@ -1339,8 +1339,8 @@ public void doFilter(HttpServletRequest wrappedRequest, HttpServletResponse wrap
13391339
wrappedRequest.getRequestDispatcher("/").include(wrappedRequest, wrappedResponse);
13401340
assertThat(SessionRepositoryFilterTests.this.sessionRepository.findById(id)).isNotNull();
13411341
wrappedRequest.getRequestDispatcher("/").include(wrappedRequest, wrappedResponse);
1342-
verify(sessionRepository).findById(session.getId());
1343-
verify(sessionRepository).save(session);
1342+
verify(sessionRepository, times(1)).findById(session.getId());
1343+
verify(sessionRepository, times(1)).save(session);
13441344
verifyNoMoreInteractions(sessionRepository);
13451345
}
13461346
});

0 commit comments

Comments
 (0)