Skip to content
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

Description of spring-boot-starter-websocket does not make it clear that it's Servlet-specific #32493

Closed
jimjaeger opened this issue Sep 24, 2022 · 4 comments
Assignees
Labels
type: documentation A documentation update
Milestone

Comments

@jimjaeger
Copy link

jimjaeger commented Sep 24, 2022

Simple multipart/form-data file upload rejects with Content type 'application/octet-stream' not supported for a file part with application/octet-stream when websocket dependency is configured.

I tried the example described here https://vinsguru.medium.com/spring-webflux-file-upload-f6e3f3d3f5e1
with the latest spring 2.7.4 from spring boot starter. It worked. After I added the following dependency it breaks:

	<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-websocket</artifactId>
		</dependency>

Sample Upload Controller method:

    @PostMapping(path = "file/single", consumes = {"multipart/form-data"})
    public Mono<Void> upload(@RequestPart("user-name") String name, @RequestPart("fileToUpload") Mono<FilePart> filePartMono) {
        System.out.println("user : " + name);
        return filePartMono
                .doOnNext(fp -> System.out.println("Received File : " + fp.filename()))
                .flatMap(fp -> fp.transferTo(basePath.resolve(fp.filename())))
                .then();
    }

Sample Upload form:

   <form class="mt-3" action="upload/file/single" method="post" enctype="multipart/form-data">
           <div class="form-group">
               <label>User</label>
               <input type="text" name="user-name"> <br /><br />
               <label>Single</label>
               <input type="file" name="fileToUpload" id="fileToUpload1">
           </div>
           <div class="form-group mt-3">
               <button type="submit" class="btn btn-primary">Submit</button>
           </div>
       </form>
There was an unexpected error (type=Unsupported Media Type, status=415).
Content type 'application/octet-stream' not supported
org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/octet-stream' not supported
	at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:211)
	at org.springframework.web.servlet.mvc.method.annotation.RequestPartMethodArgumentResolver.resolveArgument(RequestPartMethodArgumentResolver.java:140)
	at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:122)
	at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:179)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:146)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1071)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:964)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 24, 2022
@jimjaeger jimjaeger changed the title Simple multipart/form-data file upload ends in 415 Content type 'application/octet-stream' not supported multipart/form-data file upload ends in 415 Content type 'application/octet-stream' not supported with starter-websocket dependency Sep 24, 2022
@bclozel
Copy link
Member

bclozel commented Sep 24, 2022

Thanks for getting in touch, but it feels like this is a question that would be better suited to StackOverflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

In this case I think you're conflating Spring MVC and Spring WebFlux. Adding the websocket dependency is only required for MVC and actually brings in MVC, turning your entire application as a Spring MVC app. You don't need the websocket starter to have websocket with WebFlux.

@bclozel bclozel added for: stackoverflow A question that's better suited to stackoverflow.com status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 24, 2022
@bclozel bclozel closed this as not planned Won't fix, can't repro, duplicate, stale Sep 24, 2022
@jimjaeger
Copy link
Author

Thanks for explanation. I have to admin that I used https://start.spring.io/ to create the project config. The starter page allows to select Spring Reactive Web together with WebSocket. Any chance that the start page gray out give a hint that it should not be used together?

@bclozel
Copy link
Member

bclozel commented Sep 25, 2022

It's not an invalid combination in itself. One could work on a Servlet based application using websocket and still need WebFlux for the WebClient.

If anything the starter name should be changed in Spring Boot but it's too late for that.
You could also suggest a better dependency description on start.spring.io for the websocket starter as it doesn't mention MVC at all for now. See https:/spring-io/start.spring.io/issues

@wilkinsona
Copy link
Member

wilkinsona commented Sep 26, 2022

I agree that it's probably too late to rename the starter. We could still improve its description in the reference documentation though.

@wilkinsona wilkinsona reopened this Sep 26, 2022
@wilkinsona wilkinsona added type: documentation A documentation update and removed status: invalid An issue that we don't feel is valid for: stackoverflow A question that's better suited to stackoverflow.com labels Sep 26, 2022
@wilkinsona wilkinsona added this to the 2.6.x milestone Sep 26, 2022
@wilkinsona wilkinsona changed the title multipart/form-data file upload ends in 415 Content type 'application/octet-stream' not supported with starter-websocket dependency Description of spring-boot-starter-websocket does not make it clear that it's Servlet-specific Sep 26, 2022
@wilkinsona wilkinsona modified the milestones: 2.6.x, 2.7.x Nov 24, 2022
@mhalbritter mhalbritter self-assigned this Jan 16, 2023
@mhalbritter mhalbritter modified the milestones: 2.7.x, 2.7.8 Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

5 participants