spring-cloud / spring-cloud/spring-cloud-gateway
Support for Multipart POST Requests in Integration Tests with Mock MVC in Spring Cloud Gateway MVC
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.9k
- Forks
- 3.5k
- Avg merge
- 20h 57m
- Merged PRs (30d)
- 8
Description
Hi,
In our Spring Cloud Gateway MVC project, we support routing of multipart POST requests.
Currently, this functionality does not work in our integration tests using MockMvc. Specifically, MockMvc produces a MockMultipartHttpServletRequest, which does not appear to be properly routed by Spring Cloud Gateway MVC. When using WireMock, we see the following error:
"The request was rejected because no multipart boundary was found."
I have a few questions regarding this:
- Will support for multipart POST requests in integration tests using MockMvc be added in a future release?
- Is there a recommended workaround for this limitation in the meantime?
- Is there a more idiomatic or elegant approach to writing integration tests for multipart routing in Spring Cloud Gateway MVC?
Thank you in advance for your help!
@Test
void testMultiPartPostRoutingOk() throws Exception {
var requestBody = new TestRequest();
requestBody.setNumber("P1");
var requestBodyAsJson = mapObjectToJSON(requestBody);
var jsonPart =
new MockMultipartFile(
"data", "", MediaType.APPLICATION_JSON_VALUE, requestBodyAsJson.getBytes());
var filePart =
new MockMultipartFile(
"files", "test-file.txt", MediaType.TEXT_PLAIN_VALUE, "File content 1".getBytes());
var filePart2 =
new MockMultipartFile(
"files", "test-file2.txt", MediaType.TEXT_PLAIN_VALUE, "File content 2".getBytes());
stubFor(
post(urlPathEqualTo("/test-url"))
.willReturn(aResponse().withStatus(OK.value())));
mvc.perform(
MockMvcRequestBuilders.multipart("/test-url")
.file(jsonPart)
.file(filePart)
.file(filePart2)
.contentType(MULTIPART_FORM_DATA_VALUE)
.with(oidcLogin().oidcUser(getDefaultUser()))
.with(csrf()))
.andExpect(status().isOk());
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the testMultiPartPostRoutingOk method and its MockMvc multipart request, then trace how Spring Cloud Gateway MVC handles that request before it reaches WireMock. Use the reported “no multipart boundary was found” failure as the reproduction signal; done should mean the multipart POST is routed successfully in this integration-test setup, or the limitation and workaround are documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring, spring-boot
- Domain
- api, backend, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100