I'm prototyping the migration to the functional variant of Spring WebFlux (and Spring Boot) using the "Router Kotlin DSL". Now I need some hint for file upload with MIME type multipart/form-data
instead of e.g. PUT
ing some data with application/json
.
When I define a simple router function and a handler like this I get the stacktrace below:
fun routes(handler: MultimediaHandler) = router {
(accept(MediaType.MULTIPART_FORM_DATA) and "/multimedia").nest {
PUT("/{id}", handler::upload)
}
}
class MultimediaHandler {
fun upload(request: ServerRequest): Mono<ServerResponse> {
val id = request.pathVariable("id")
return noContent().build()
}
}
The stacktrace:
13:43:29.713 ERROR [i.u.request] [XNIO-1 I/O-3] UT005071: Undertow request failed HttpServerExchange{ PUT /multimedia/00000000-0000-0000-0000-000000000
001 request {Connection=[Keep-Alive], Accept-Encoding=[gzip,deflate], Content-Length=[1672], Content-Type=[multipart/form-data; boundary=-mJAzUqZoGk2nc
N1Rch4O4-KGbTExkAmQ7A], User-Agent=[Apache-HttpClient/4.5.2 (Java/1.8.0_144)], Host=[localhost:8444]} response {}}
java.lang.IllegalStateException: No multipart HttpMessageReader.
at org.springframework.web.server.adapter.DefaultServerWebExchange.lambda$initMultipartData$3(DefaultServerWebExchange.java:144) ~[spring-web-5.0.0.RC3.jar:5.0.0.RC3]
at java.util.Optional.orElseThrow(Optional.java:290) ~[?:1.8.0_144]
at org.springframework.web.server.adapter.DefaultServerWebExchange.initMultipartData(DefaultServerWebExchange.java:144) ~[spring-web-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.web.server.adapter.DefaultServerWebExchange.<init>(DefaultServerWebExchange.java:109) ~[spring-web-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.web.server.adapter.HttpWebHandlerAdapter.createExchange(HttpWebHandlerAdapter.java:167) ~[spring-web-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.web.server.adapter.HttpWebHandlerAdapter.handle(HttpWebHandlerAdapter.java:156) ~[spring-web-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.http.server.reactive.UndertowHttpHandlerAdapter.handleRequest(UndertowHttpHandlerAdapter.java:71) ~[spring-web-5.0.0.RC3.jar:5.0.0.RC3]
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:332) [undertow-core-1.4.19.Final.jar:1.4.19.Final]
at io.undertow.server.protocol.http.HttpReadListener.handleEventWithNoRunningRequest(HttpReadListener.java:254) [undertow-core-1.4.19.Final.jar:1.4.19.Final]
at io.undertow.server.protocol.http.HttpReadListener.handleEvent(HttpReadListener.java:136) [undertow-core-1.4.19.Final.jar:1.4.19.Final]
at io.undertow.server.protocol.http.HttpOpenListener.handleEvent(HttpOpenListener.java:148) [undertow-core-1.4.19.Final.jar:1.4.19.Final]
at io.undertow.server.protocol.http.AlpnOpenListener$AlpnConnectionListener.handleEvent(AlpnOpenListener.java:357) [undertow-core-1.4.19.Final.jar:1.4.19.Final]
at io.undertow.server.protocol.http.AlpnOpenListener$AlpnConnectionListener.handleEvent(AlpnOpenListener.java:308) [undertow-core-1.4.19.Final.jar:1.4.19.Final]
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92) [xnio-api-3.5.1.Final.jar:3.5.1.Final]
at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66) [xnio-api-3.5.1.Final.jar:3.5.1.Final]
at io.undertow.protocols.ssl.SslConduit$SslReadReadyHandler.readReady(SslConduit.java:1140) [undertow-core-1.4.19.Final.jar:1.4.19.Final]
at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:89) [xnio-nio-3.5.1.Final.jar:3.5.1.Final]
at org.xnio.nio.WorkerThread.run(WorkerThread.java:571) [xnio-nio-3.5.1.Final.jar:3.5.1.Final]
Do you have the following dependency on your classpath? Spring Framework requires this for parsing multipart requests.