Skip to content

Commit

Permalink
Revert "Revert "Make HTTP post requests repeatable by wrapping entiti…
Browse files Browse the repository at this point in the history
…es into a repeatable entity (getodk#856)""

This reverts commit 8c18a1a.
  • Loading branch information
Marinolino committed May 29, 2020
1 parent 076788e commit 7733176
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 7733176

Please sign in to comment.