Add Servlet 3.1 methods to mock request
Issue: SPR-11492
This commit is contained in:
@@ -348,6 +348,10 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
return (this.content != null ? this.content.length : -1);
|
||||
}
|
||||
|
||||
public long getContentLengthLong() {
|
||||
return getContentLength();
|
||||
}
|
||||
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
if (contentType != null) {
|
||||
@@ -999,6 +1003,20 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
return getSession(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* The implementation of this (Servlet 3.1+) method calls
|
||||
* {@link MockHttpSession#changeSessionId()} if the session is a mock session.
|
||||
* Otherwise it simply returns the current session id.
|
||||
* @since 4.0.3
|
||||
*/
|
||||
public String changeSessionId() {
|
||||
Assert.isTrue(this.session != null, "The request does not have a session");
|
||||
if (this.session instanceof MockHttpSession) {
|
||||
return ((MockHttpSession) session).changeSessionId();
|
||||
}
|
||||
return this.session.getId();
|
||||
}
|
||||
|
||||
public void setRequestedSessionIdValid(boolean requestedSessionIdValid) {
|
||||
this.requestedSessionIdValid = requestedSessionIdValid;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class MockHttpSession implements HttpSession {
|
||||
|
||||
private static int nextId = 1;
|
||||
|
||||
private final String id;
|
||||
private String id;
|
||||
|
||||
private final long creationTime = System.currentTimeMillis();
|
||||
|
||||
@@ -110,6 +110,16 @@ public class MockHttpSession implements HttpSession {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* As of Servlet 3.1 the id of a session can be changed.
|
||||
* @return the new session id.
|
||||
* @since 4.0.3
|
||||
*/
|
||||
public String changeSessionId() {
|
||||
this.id = Integer.toString(nextId++);
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void access() {
|
||||
this.lastAccessedTime = System.currentTimeMillis();
|
||||
this.isNew = false;
|
||||
|
||||
Reference in New Issue
Block a user