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

Make HTTP POST requests repeatable #856

Merged
merged 1 commit into from
Mar 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -126,10 +128,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 @@ -147,6 +148,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