Skip to content

Commit 019d551

Browse files
author
Laurent SCHOELENS
committed
[GH-2284] fix commitSession() called multiple times in requestDispatcher.include
1 parent 9f7a969 commit 019d551

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ private final class SessionRepositoryRequestWrapper extends HttpServletRequestWr
204204

205205
private boolean requestedSessionInvalidated;
206206

207+
private boolean hasCommitedInInclude;
208+
207209
private SessionRepositoryRequestWrapper(HttpServletRequest request, HttpServletResponse response) {
208210
super(request);
209211
this.response = response;
@@ -343,7 +345,7 @@ public String getRequestedSessionId() {
343345
@Override
344346
public RequestDispatcher getRequestDispatcher(String path) {
345347
RequestDispatcher requestDispatcher = super.getRequestDispatcher(path);
346-
return new SessionCommittingRequestDispatcher(requestDispatcher);
348+
return new SessionCommittingRequestDispatcher(requestDispatcher, this);
347349
}
348350

349351
private S getRequestedSession() {
@@ -403,8 +405,11 @@ private final class SessionCommittingRequestDispatcher implements RequestDispatc
403405

404406
private final RequestDispatcher delegate;
405407

406-
SessionCommittingRequestDispatcher(RequestDispatcher delegate) {
408+
private final SessionRepositoryRequestWrapper wrapper;
409+
410+
SessionCommittingRequestDispatcher(RequestDispatcher delegate, SessionRepositoryRequestWrapper wrapper) {
407411
this.delegate = delegate;
412+
this.wrapper = wrapper;
408413
}
409414

410415
@Override
@@ -414,7 +419,10 @@ public void forward(ServletRequest request, ServletResponse response) throws Ser
414419

415420
@Override
416421
public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException {
417-
SessionRepositoryRequestWrapper.this.commitSession();
422+
if (!this.wrapper.hasCommitedInInclude) {
423+
SessionRepositoryRequestWrapper.this.commitSession();
424+
this.wrapper.hasCommitedInInclude = true;
425+
}
418426
this.delegate.include(request, response);
419427
}
420428

0 commit comments

Comments
 (0)