Multipart InputStream leads to SocketException: Broken pipe / NonRepeatableRequestException

1,093 views
Skip to first unread message

Laurent Marchal

unread,
Apr 5, 2016, 2:21:38 AM4/5/16
to REST assured
Hi,

This test library is great, but i'm having some issue when trying to upload multipart streams: 

This code works :

@Test
public void testSimpleFileUpload() throws IOException {
final File indexFile = getClassPathResource("file.bin");
RestAssured.given().multiPart(indexFile).when().post("file.bin");
}

This code doesn't :

@Test
public void testMultipleStreamUpload() throws IOException {
int MB = 1024 * 1024;
byte[] buffer = new byte[16 * MB];
ByteStreams.readFully(new RandomInputStream(), buffer);
InputStream randomStream = new ByteArrayInputStream(buffer);

RestAssured.given().multiPart("file", "streamTest1", randomStream).when().post("file.bin");
}

I tried multi part upload with the okHttp and it works fine for the same URL. I can debug on the http server side, and what is weird is that the request is never made on the server for testMultipleStreamUpload(), it just fails with (error at the bottom).

Any ideas ? I also tried to find unit tests in the library so I could create a reproducible example but could not find any..

Thanks.

Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity.  The cause lists the reason the original request failed.
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:659)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:487)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:882)
... 87 more
Caused by: java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
at org.apache.http.impl.io.AbstractSessionOutputBuffer.flushBuffer(AbstractSessionOutputBuffer.java:159)
at org.apache.http.impl.io.AbstractSessionOutputBuffer.write(AbstractSessionOutputBuffer.java:179)
at org.apache.http.impl.io.ChunkedOutputStream.flushCacheWithAppend(ChunkedOutputStream.java:124)
at org.apache.http.impl.io.ChunkedOutputStream.write(ChunkedOutputStream.java:181)
at org.apache.http.entity.mime.content.InputStreamBody.writeTo(InputStreamBody.java:93)
at org.apache.http.entity.mime.AbstractMultipartForm.doWriteTo(AbstractMultipartForm.java:134)
at org.apache.http.entity.mime.AbstractMultipartForm.writeTo(AbstractMultipartForm.java:157)
at org.apache.http.entity.mime.MultipartFormEntity.writeTo(MultipartFormEntity.java:103)
at org.apache.http.HttpEntity$writeTo$4.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at com.jayway.restassured.internal.multipart.RestAssuredMultiPartEntity.writeTo(RestAssuredMultiPartEntity.groovy:110)
at org.apache.http.entity.HttpEntityWrapper.writeTo(HttpEntityWrapper.java:96)
at org.apache.http.impl.client.EntityEnclosingRequestWrapper$EntityWrapper.writeTo(EntityEnclosingRequestWrapper.java:112)
at org.apache.http.impl.entity.EntitySerializer.serialize(EntitySerializer.java:117)
at org.apache.http.impl.AbstractHttpClientConnection.sendRequestEntity(AbstractHttpClientConnection.java:265)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.sendRequestEntity(ManagedClientConnectionImpl.java:203)
at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:237)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:122)
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:685)

Johan Haleby

unread,
Apr 5, 2016, 3:15:20 AM4/5/16
to rest-a...@googlegroups.com
Sorry I don't know what could be causing this. I would suggest googling for it and if you find the reason and/or a workaround please let us know.

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Laurent Marchal

unread,
Apr 5, 2016, 10:31:55 AM4/5/16
to REST assured
It seems the buffer size matters when uploading files. When trying to send less than 4Kb of data it works but then it fails if I try to upload more than that..

I'll keep looking and debugging,

Laurent Marchal

unread,
Apr 8, 2016, 11:07:43 AM4/8/16
to REST assured
After some time debugging, it seems the issue comes from the server not answering properly to the HTTP specs and having buffer/streaming issues. Nothing to do with this very good library.

Thanks,
Laurent.

Johan Haleby

unread,
Apr 10, 2016, 2:06:13 AM4/10/16
to rest-a...@googlegroups.com
Thanks for sharing Laurent. Glad that you got it working.
Reply all
Reply to author
Forward
0 new messages