I am trying to use soap MTOM protocol with WireMock, attaching one file to SOAP request directed to mocked service, but it gives me some problems...
@Test
public void AfpToPdf() throws Exception {
stubWireMock(FOLDER_PATH, "convertAfpToPdf", 200, RECUPERA_DOCUMENTO_FOLDER_RESPONSE_OK);
ConvertAfpToPdfType request = createDocumentoAFPRequest();
Testata testata = new Testata();
ConvertAfpToPdfResponseType response = getPortNew().convertAfpToPdf(request, testata, new Holder<>());
assertNotNull(response);
}
private ConvertAfpToPdfType createDocumentoAFPRequest() {
ConvertAfpToPdfType request = new ConvertAfpToPdfType();
ListaFileAfpType listaFileAfpType = new ListaFileAfpType();
DataHandler dataHandlerAFP = new DataHandler(new FileDataSource("FOLD14.R00407A.NT01.D130606.AFP"));
listaFileAfpType.setDocumentFileAfp(dataHandlerAFP);
request.setListaFileAfp(listaFileAfpType);
return request;
}
protected void stubWireMock(String urlPath, String requestContained, int httpStatus, String bodyFileName) {
wireMockRule.stubFor(post(urlPathEqualTo((BASE_URL_CONVERSIONE)))
.withRequestBody(containing("conversioneAfp"))
.willReturn(
aResponse()
.withStatus(200)
.withHeader("Content-Type", "multipart/form-data")
.withBody("prova")));
}
The error
java.io.IOException: Buffer size exceeded: no line terminator
at org.eclipse.jetty.util.ReadLineInputStream.readLine(ReadLineInputStream.java:68)
at org.eclipse.jetty.util.MultiPartInputStreamParser.parse(MultiPartInputStreamParser.java:619)
at org.eclipse.jetty.util.MultiPartInputStreamParser.getParts(MultiPartInputStreamParser.java:491)
at org.eclipse.jetty.server.Request.getParts(Request.java:2374)
at org.eclipse.jetty.server.Request.getParts(Request.java:2326)
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:44)
at com.github.tomakehurst.wiremock.servlet.WireMockHandlerDispatchingServlet.service(WireMockHandlerDispatchingServlet.java:108)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:841)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:543)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:481)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1155)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:666)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.Server.handle(Server.java:531)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:352)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)
at java.lang.Thread.run(Thread.java:750)
At first glance it can be something jetty-related, but I haven't found anything online about it. It also seems strange to me, becauese I am only mocking a service. Can you find some useful solution/workaround?
I have solved adding this header
Map<String, List<String>> headers = new HashMap<>();
headers.put("Content-type", Collections.singletonList("undefined;"));
bindingProvider.getRequestContext().put(MessageContext
.HTTP_REQUEST_HEADERS, headers);