Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

Commit

Permalink
Make HTTP post requests repeatable by wrapping entities into a repeat…
Browse files Browse the repository at this point in the history
…able entity (#856)
  • Loading branch information
ggalmazor authored Mar 13, 2020
1 parent 80f662d commit 9bffa68
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/org/opendatakit/briefcase/reused/http/CommonsHttp.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.opendatakit.briefcase.reused.http.RequestMethod.POST;

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.SocketTimeoutException;
import java.net.URL;
Expand All @@ -30,6 +31,7 @@
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.entity.BufferedHttpEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.InputStreamBody;
Expand Down Expand Up @@ -128,10 +130,9 @@ private <T> Response<T> uncheckedExecute(Request<T> request, Executor executor)
part.getName(),
new InputStreamBody(part.getBody(), ContentType.create(part.getContentType()), part.getAttachmentName())
);
body = bodyBuilder.build();
body = makeRepeatable(bodyBuilder.build());
} else {
body = new BasicHttpEntity();
((BasicHttpEntity) body).setContent(request.getBody());
body = makeRepeatable(buildBasicEntity(request.getBody()));
}
commonsRequest.body(body);
}
Expand All @@ -149,6 +150,20 @@ private <T> Response<T> uncheckedExecute(Request<T> request, Executor executor)
}
}

private BasicHttpEntity buildBasicEntity(InputStream contents) {
BasicHttpEntity entity = new BasicHttpEntity();
entity.setContent(contents);
return entity;
}

private BufferedHttpEntity makeRepeatable(HttpEntity entity) {
try {
return new BufferedHttpEntity(entity);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

private static org.apache.http.client.fluent.Request getCommonsRequest(Request<?> request) {
switch (request.getMethod()) {
case GET:
Expand Down

0 comments on commit 9bffa68

Please sign in to comment.