-
Notifications
You must be signed in to change notification settings - Fork 40.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Content type multipart/mixed not supported / 415 UNSUPPORTED_MEDIA_TYPE (after Spring + Spring Boot upgrade) #30971
Comments
Thanks for the report but Spring Boot 2.2 has been out of OSS support since 16 October 2020. If you can reproduce the problem with Spring Boot 2.5.x or 2.6.x and you would like us to take a look, please provide a complete yet minimal sample that reproduces the problem using one of those versions. You can share the sample with us by zipping it up and attaching it to this issue or by pushing it to a separate repository on GitHub. |
I have tried this again with the latest versions (sorry I do not have a minimal reproducible sample yet):
This is what I found: When I send a PUT request to my endpoint described above, using the latest Spring versions, the AbstractMessageConverterMethodArgumentResolver is called: It loops through a list of message converters, and checks if any of the converters
The This is the list of message converters the loop is iterating through: This is the value of So, what is happening is that each of these converters is returning
This results in
I tried to step through the same code using the older Spring versions listed in my original post (in order to see, for example, if the earlier Spring versions had more message converters):
but what I found was that this code that loops through the message converters is not executed using these older Spring versions I am not sure what has changed between these Spring versions that this code is now being executed (and throwing an exception), where it was not before? |
Thanks for the additional details, but I am afraid there are still too many unknowns. I cannot reproduce the problem with a minimal Spring Boot 2.6.7 application that uses spring-boot-starter-web and looks like this: package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@SpringBootApplication
public class Gh30971Application {
public static void main(String[] args) {
SpringApplication.run(Gh30971Application.class, args);
}
@Controller
static class ExampleController {
@RequestMapping(value = "/batches/{batchId}", consumes = { "multipart/mixed" }, method = RequestMethod.PUT)
public ResponseEntity<String> createOrReplaceBatch(@PathVariable("batchId") String batchId, Object body) {
return ResponseEntity.ok().build();
}
}
} Sending a multipart/mixed request using curl produces the expected 200 OK response:
As I said above, if you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue. |
Thanks @wilkinsona I see in your example though you are missing the I have added a minimal sample application that reproduces the problem here: https://github.com/rorytorneymf/staging-service-min2 You can switch Spring versions in the pom.xml and see how the older versions are returning a 200 response whereas the new Spring versions are returning a 415 response. Let me know if there is anything else I can provide, thanks! |
Debugging the sample I think the problem is related to this Spring Framework issue that was fixed in 5.1. With the earlier version, the @rorytorneymf What's the |
I think I've figured this out. In addition to finding You should switch to using MVC's built-in multipart support. There are a few different ways to do that, for example: package com.github.cafdataprocessing.services.staging;
import java.io.IOException;
import java.util.Collection;
import javax.servlet.ServletException;
import javax.servlet.http.Part;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartHttpServletRequest;
@RestController
public class StagingController implements StagingApi
{
private static final Logger LOGGER = LoggerFactory.getLogger(StagingController.class);
public ResponseEntity<Void> createOrReplaceBatch(@PathVariable("batchId") String batchId, MultipartHttpServletRequest request)
{
try {
Collection<Part> parts = request.getParts();
// Make sure we have read the staging-service-payload.txt properly
if (parts.size() != 1) {
throw new RuntimeException("Expected request to contain 1 item but it contains " + parts.size());
}
return new ResponseEntity<>(HttpStatus.OK);
} catch (final ServletException | IOException ex) {
LOGGER.error("Error getting request parts", ex);
throw new RuntimeException(ex);
}
}
} |
Thanks so much for your help here @philwebb and @wilkinsona, it's much appreciated! |
Affects: 2.2.6.RELEASE
I was previously using the following versions of Spring + Spring Boot:
And the following classes, which handled a multipart/mixed upload. This is all working fine using the Spring versions above:
StagingApi.java
StagingController.java
Log of successfully handled request:
However, when I try to update the versions of Spring and Spring Boot to:
the same request fails with a 415 UNSUPPORTED_MEDIA_TYPE response.
Log of failed request:
Any help is much appreciated!
The text was updated successfully, but these errors were encountered: