Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

adding the Date header for S3 download http request. #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ target
.classpath
bin
dependency-reduced-pom.xml

.idea/
*.iml
testfile.txt

30 changes: 29 additions & 1 deletion src/main/java/com/amazonaws/ant/s3/DownloadFileFromS3Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.text.SimpleDateFormat;
import java.util.*;

import com.amazonaws.Request;
import com.amazonaws.Response;
import com.amazonaws.handlers.RequestHandler2;
import com.amazonaws.services.s3.S3ClientOptions;
import org.apache.tools.ant.BuildException;

import com.amazonaws.ant.AWSAntTask;
Expand Down Expand Up @@ -148,6 +153,7 @@ private void downloadObjectToFile(AmazonS3Client client, File file, String key)

public void execute() {
AmazonS3Client client = getOrCreateClient(AmazonS3Client.class);
this.addRequestHeader(client);
if (key != null) {
File targetFile = file == null ? new File(key) : file;
downloadObjectToFile(client, targetFile, key);
Expand Down Expand Up @@ -175,4 +181,26 @@ public void execute() {
}
}
}

private void addRequestHeader(AmazonS3Client client) {

RequestHandler2 requestHandler2 = new RequestHandler2() {
@Override
public void beforeRequest(Request<?> request) {
request.addHeader("Date", Calendar.getInstance(TimeZone.getTimeZone("GMT")).getTime().toString());
}

@Override
public void afterResponse(Request<?> request, Response<?> response) {

}

@Override
public void afterError(Request<?> request, Response<?> response, Exception e) {

}
};

client.addRequestHandler(requestHandler2);
}
}