Skip to content

Commit

Permalink
Fixed errors highlighted during the checkCode scan.
Browse files Browse the repository at this point in the history
Modified uploadSubmissionFile in OkHttpConnection to use the contentLength parameter instead of the hard coded value: 10000000L
  • Loading branch information
steelej-arm committed Feb 4, 2019
1 parent 2595a58 commit d992631
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.odk.collect.android.R;
import org.odk.collect.android.application.Collect;
import org.odk.collect.android.utilities.FileUtils;
import org.odk.collect.android.utilities.ResponseMessageParser;
import org.opendatakit.httpclientandroidlib.Header;
import org.opendatakit.httpclientandroidlib.HttpEntity;
import org.opendatakit.httpclientandroidlib.HttpHost;
Expand Down Expand Up @@ -383,7 +382,7 @@ HttpGetResult executeGetRequest(@NonNull URI uri, @Nullable final String content
HttpEntity httpEntity = response.getEntity();
Timber.i("Response code:%d", responseCode);

postResult = new HttpPostResult(EntityUtils.toString(httpEntity),responseCode,response.getStatusLine().getReasonPhrase());
postResult = new HttpPostResult(EntityUtils.toString(httpEntity), responseCode, response.getStatusLine().getReasonPhrase());

discardEntityBytes(response);

Expand Down Expand Up @@ -419,14 +418,13 @@ HttpGetResult executeGetRequest(@NonNull URI uri, @Nullable final String content
* HttpPostResult - This is just stubbed out for now, implemented when we move to OkHttpConnection
* @param uri of which to post
* @param credentials to use on this post request
* @return
* @throws Exception
* @return null
* @throws Exception not used
*/
public HttpPostResult executePostRequest(@NonNull URI uri, @Nullable HttpCredentialsInterface credentials) throws Exception {
return null;
return new HttpPostResult("", 0, "");
}


private void addCredentialsForHost(@NonNull URI uri, @Nullable HttpCredentialsInterface credentials) {
if (credentials != null) {
addCredentials(credentials.getUsername(), credentials.getPassword(), uri.getHost());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public boolean equals(Object obj) {
return true;
}

return (((HttpCredentials)obj).getUsername().equals(getUsername()) &&
((HttpCredentials)obj).getPassword().equals(getPassword()));
return ((HttpCredentials) obj).getUsername().equals(getUsername()) &&
((HttpCredentials) obj).getPassword().equals(getPassword());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public HttpPostResult uploadSubmissionFile(@NonNull List<File> fileList, @NonNul
// we've added at least one attachment to the request...
if (fileIndex + 1 < fileList.size()) {
if ((fileIndex - lastFileIndex + 1 > 100) || (byteCount + fileList.get(fileIndex + 1).length()
> 10000000L)) {
> contentLength)) {
// the next file would exceed the 10MB threshold...
Timber.i("Extremely long post is being split into multiple posts");
multipartBuilder.addPart(MultipartBody.Part.createFormData("*isIncomplete*", "yes"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import org.odk.collect.android.utilities.ResponseMessageParser;

import java.io.File;
import java.io.IOException;
import java.net.URI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ public String uploadOneSubmission(Instance instance, String urlString) throws Up
postResult = httpInterface.uploadSubmissionFile(files, submissionFile, uri,
webCredentialsUtils.getCredentials(uri), contentLength);


int responseCode = postResult.getResponseCode();
messageParser.setMessageResponse(postResult.getHttpResponse());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.odk.collect.android.http.HttpHeadResult;
import org.odk.collect.android.http.HttpPostResult;
import org.odk.collect.android.http.OpenRosaHttpInterface;
import org.odk.collect.android.utilities.ResponseMessageParser;

import java.io.ByteArrayInputStream;
import java.io.File;
Expand Down Expand Up @@ -52,7 +51,7 @@ public HttpHeadResult executeHeadRequest(@NonNull URI uri, @Nullable HttpCredent
@NonNull
@Override
public HttpPostResult uploadSubmissionFile(@NonNull List<File> fileList, @NonNull File submissionFile, @NonNull URI uri, @Nullable HttpCredentialsInterface credentials, @NonNull long contentLength) throws IOException {
return null;
return new HttpPostResult("", 0, "");
}

@NonNull
Expand All @@ -61,7 +60,4 @@ public HttpPostResult executePostRequest(@NonNull URI uri, @Nullable HttpCredent
return new HttpPostResult("", 0, "");

}



}

0 comments on commit d992631

Please sign in to comment.