Skip to content

StringHttpMessageConverter closes output stream causes problem with FormHttpMessageConverter [SPR-10236] #14869

@spring-projects-issues

Description

@spring-projects-issues

Carlus Henry opened SPR-10236 and commented

We have the need to accept an HttpRequest with the content-type of multipart/form-data. We then have to turn around and respond with the same content-type of multipart/form-data. We are using the FormHttpMessageConverter in order to accomplish this.

However, during testing, we noticed that we were only receiving one form-data parameter part. After debugging the code, we realized that this was due to the fact that the StringHttpMessageConverter is used to convert the String type elements. After writing the first string to the output, it closes the outputstream. Then when it tries to write the next form-data part, it throws an exception since the output stream has already been closed.

Here are the order of operations:

FormHttpMessageConverter(FHMC)
StringHttpMessageConverter(SHMC)

FHMC.writePart() -> SHMC.write() -> SHMC.writeInternal() -> FileUtils.copy()...The FileUtilsCopy will close the outputstream.


Affects: 3.2.1

Issue Links:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issue

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions