spring-cloud / spring-cloud/spring-cloud-gateway

Support for Multipart POST Requests in Integration Tests with Mock MVC in Spring Cloud Gateway MVC

Open
#3,766 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

waiting-for-triage
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.