The WireMock server responds with an 500 error instead of the stub mapping for a multi-part request with binary data after the upgrade from Spring Boot 1 to Spring Boot 2.
java.lang.IllegalStateException: No multipart config for servlet
at org.eclipse.jetty.server.Request.getParts(Request.java:2331)
at org.eclipse.jetty.server.Request.getParts(Request.java:2319)
at com.github.tomakehurst.wiremock.servlet.WireMockHttpServletRequestAdapter.safelyGetRequestParts(WireMockHttpServletRequestAdapter.java:295)
at com.github.tomakehurst.wiremock.servlet.WireMockHttpServletRequestAdapter.getParts(WireMockHttpServletRequestAdapter.java:279)
at com.github.tomakehurst.wiremock.verification.LoggedRequest.createFrom(LoggedRequest.java:70)
at com.github.tomakehurst.wiremock.stubbing.InMemoryStubMappings.serveFor(InMemoryStubMappings.java:76)
at com.github.tomakehurst.wiremock.core.WireMockApp.serveStubFor(WireMockApp.java:164)
at com.github.tomakehurst.wiremock.http.StubRequestHandler.handleRequest(StubRequestHandler.java:50)
at com.github.tomakehurst.wiremock.http.AbstractRequestHandler.handle(AbstractRequestHandler.java:47)
at com.github.tomakehurst.wiremock.servlet.WireMockHandlerDispatchingServlet.service(WireMockHandlerDispatchingServlet.java:108)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
I have created a repository which demonstrates the minimal version of this problem here:
https://github.com/jmewes/wiremock-issue-1007
With this patch the described scenario would work for us:
diff --git a/src/main/java/com/github/tomakehurst/wiremock/servlet/WireMockHttpServletRequestAdapter.java b/src/main/java/com/github/tomakehurst/wiremock/servlet/WireMockHttpServletRequestAdapter.java
index bd0e5f3..808c6c9 100644
--- a/src/main/java/com/github/tomakehurst/wiremock/servlet/WireMockHttpServletRequestAdapter.java
+++ b/src/main/java/com/github/tomakehurst/wiremock/servlet/WireMockHttpServletRequestAdapter.java
@@ -36,6 +36,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.*;
+import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.Part;
@@ -275,6 +276,8 @@ public class WireMockHttpServletRequestAdapter implements Request {
String contentTypeHeaderValue = from(contentTypeHeader().values()).join(Joiner.on(" "));
InputStream inputStream = new ByteArrayInputStream(getBody());
MultiPartInputStreamParser inputStreamParser = new MultiPartInputStreamParser(inputStream, contentTypeHeaderValue, null, null);
+ MultipartConfigElement multipartConfigElement = new MultipartConfigElement((String)null);
+ request.setAttribute("org.eclipse.jetty.multipartConfig", multipartConfigElement);
request.setAttribute(org.eclipse.jetty.server.Request.__MULTIPART_INPUT_STREAM, inputStreamParser);
cachedMultiparts = from(safelyGetRequestParts()).transform(new Function<javax.servlet.http.Part, Part>() {
@Override
Is this an acceptable solution?
Thanks for posting this. I'll try and find time to take a look this week. At face value your solution looks good, but I'd like to consider it a little more before committing to it.
We've stumbled into the same problem updating our embedded jetty engine to 9.4.10 (.v20180503). Running internal tests using wiremock to stub external systems resulted in the same issue. Can confirm that the patch above will fix our problem.
Thanks @tomakehurst
Most helpful comment
Thanks for posting this. I'll try and find time to take a look this week. At face value your solution looks good, but I'd like to consider it a little more before committing to it.