Tolerate changes to request body reading in Framework 5.1

Previously, MockHttpServletRequest allowed its body to be ready
multiple times using its InputStream. As of recent Spring Framework
5.1 snapshots, this is no longer the case.

This commit moves to directly accessing the request's content as a
byte array using getContentAsByteArray() which was introduced in
Framework 5.0.

Closes gh-515
This commit is contained in:
Andy Wilkinson
2018-06-15 16:00:25 +01:00
parent 026af2de2a
commit a60b87990b
4 changed files with 24 additions and 3 deletions

View File

@@ -61,4 +61,11 @@ artifacts {
test {
jvmArgs "-javaagent:${configurations.jacoco.asPath}=destfile=${buildDir}/jacoco.exec,includes=org.springframework.restdocs.*,excludes=org.springframework.restdocs.mustache.*"
}
matrixTest {
springFramework {
group = 'org.springframework'
versions = ['5.1.0.BUILD-SNAPSHOT']
}
}

View File

@@ -16,4 +16,11 @@ dependencies {
test {
jvmArgs "-javaagent:${configurations.jacoco.asPath}=destfile=${buildDir}/jacoco.exec,includes=org.springframework.restdocs.*"
}
matrixTest {
springFramework {
group = 'org.springframework'
versions = ['5.1.0.BUILD-SNAPSHOT']
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 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.
@@ -81,8 +81,8 @@ class MockMvcRequestConverter implements RequestConverter<MockHttpServletRequest
getRequestUri(mockRequest) + (StringUtils.hasText(queryString)
? "?" + queryString : "")),
HttpMethod.valueOf(mockRequest.getMethod()),
FileCopyUtils.copyToByteArray(mockRequest.getInputStream()), headers,
parameters, parts, cookies);
mockRequest.getContentAsByteArray(), headers, parameters, parts,
cookies);
}
catch (Exception ex) {
throw new ConversionException(ex);

View File

@@ -14,4 +14,11 @@ dependencies {
test {
jvmArgs "-javaagent:${configurations.jacoco.asPath}=destfile=${buildDir}/jacoco.exec,includes=org.springframework.restdocs.*"
}
matrixTest {
springFramework {
group = 'org.springframework'
versions = ['5.1.0.BUILD-SNAPSHOT']
}
}