Skip to content

Commit

Permalink
Merge pull request #29 from rpmoore/master
Browse files Browse the repository at this point in the history
Fixing a 307 retry bug
  • Loading branch information
hansdude committed Aug 11, 2014
2 parents 38f3c7b + 0f16e9c commit c673cc4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ apply plugin: 'maven'
sourceCompatibility = JavaVersion.VERSION_1_7

jar.archiveName = 'ds3_java_sdk'
version = '0.7.0-SNAPSHOT'
version = '0.7.1-SNAPSHOT'
group = 'com.spectralogic'

install.dependsOn test //make sure that the tests get ran before attempting to install
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/spectralogic/ds3client/Ds3InputStreamEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.spectralogic.ds3client;


import org.apache.commons.io.IOUtils;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.InputStreamEntity;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Ds3InputStreamEntity extends InputStreamEntity{

public Ds3InputStreamEntity(final InputStream inStream, final long length, final ContentType contentType) {
super(inStream, length, contentType);
}

@Override
public void writeTo(final OutputStream outStream) throws IOException {
IOUtils.copy(this.getContent(), outStream);
}
}
11 changes: 5 additions & 6 deletions src/main/java/com/spectralogic/ds3client/NetworkClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,16 @@ public ConnectionDetails getConnectionDetails() {
@Override
public WebResponse getResponse(final Ds3Request request) throws IOException, SignatureException {
try (final RequestExecutor requestExecutor = new RequestExecutor(request)) {
boolean redirect = false;
int redirectCount = 0;
do {
final CloseableHttpResponse response = requestExecutor.execute();
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_TEMPORARY_REDIRECT) {
redirect = true;
redirectCount++;
continue;
}
return new WebResponseImpl(response);
} while (redirect && redirectCount < this.connectionDetails.getRetries());
else {
return new WebResponseImpl(response);
}
} while (redirectCount < this.connectionDetails.getRetries());

throw new TooManyRedirectsException(redirectCount);
}
Expand Down Expand Up @@ -126,7 +125,7 @@ private HttpRequest buildHttpRequest() throws IOException {
final String path = this.buildPath();
if (this.content != null) {
final BasicHttpEntityEnclosingRequest httpRequest = new BasicHttpEntityEnclosingRequest(verb, path);
httpRequest.setEntity(new InputStreamEntity(this.content, this.ds3Request.getSize(), this.ds3Request.getContentType()));
httpRequest.setEntity(new Ds3InputStreamEntity(this.content, this.ds3Request.getSize(), this.ds3Request.getContentType()));
return httpRequest;
} else {
return new BasicHttpRequest(verb, path);
Expand Down

0 comments on commit c673cc4

Please sign in to comment.