Add Servlet 3.1 methods to mock request
Issue: SPR-11492
This commit is contained in:
@@ -351,6 +351,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) {
|
||||
@@ -1001,6 +1005,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;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -54,7 +54,7 @@ public class MockHttpSession implements HttpSession {
|
||||
|
||||
private static int nextId = 1;
|
||||
|
||||
private final String id;
|
||||
private String id;
|
||||
|
||||
private final long creationTime = System.currentTimeMillis();
|
||||
|
||||
@@ -111,6 +111,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