Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To offer a chance to get response headers from once-off Download/Upload API call #129

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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.javaswift.joss.client.core;

import org.apache.http.Header;
import org.javaswift.joss.command.shared.factory.StoredObjectCommandFactory;
import org.javaswift.joss.exception.CommandException;
import org.javaswift.joss.headers.Metadata;
Expand All @@ -26,6 +27,8 @@ public abstract class AbstractStoredObject extends AbstractObjectStoreEntity<Obj
private Container container;

private final StoredObjectCommandFactory commandFactory;

private Header[] responseHeaders;

public AbstractStoredObject(Container container, String name, boolean allowCaching) {
super(allowCaching);
Expand Down Expand Up @@ -291,6 +294,14 @@ public boolean verifyTempUrl(String method, String signature, long expiry) {
.setFixedExpiry(expiry)
.verify(signature, expiry);
}

public Header[] getResponseHeaders() {
return responseHeaders;
}

public void setResponseHeaders(Header[] responseHeaders) {
this.responseHeaders = responseHeaders;
}

public boolean isObject() { return true; }
public boolean isDirectory() { return false; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected N getReturnObject(HttpResponse response) throws IOException {
String expectedMd5 = response.getHeaders(ETAG)[0].getValue().replaceAll("\"", "");
boolean isManifest = Header.headerNotEmpty(response, X_OBJECT_MANIFEST);
handleEntity(response.getEntity());
populateResponseHeaders(response);
if ( !isManifest && // Manifest files may not be checked
HttpStatus.SC_PARTIAL_CONTENT != response.getStatusLine().getStatusCode()) {
// etag match on partial content makes no sense)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.javaswift.joss.command.impl.object;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpRequestBase;
import org.javaswift.joss.command.impl.core.AbstractSecureCommand;
Expand All @@ -9,8 +12,24 @@

public abstract class AbstractObjectCommand<M extends HttpRequestBase, N> extends AbstractSecureCommand<M, N> {

private StoredObject object;

public AbstractObjectCommand(Account account, HttpClient httpClient, Access access, StoredObject object) {
super(account, httpClient, getURL(access, object), access.getToken());
this.object = object;
}

public StoredObject getStoredObject() {
return object;
}

public void populateResponseHeaders(HttpResponse response) {
object.setResponseHeaders(response.getAllHeaders());
}

protected N getReturnObject(HttpResponse response) throws IOException {
populateResponseHeaders(response);
return null; // returns null by default
}

}
4 changes: 3 additions & 1 deletion src/main/java/org/javaswift/joss/model/StoredObject.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.javaswift.joss.model;

import org.apache.http.Header;
import org.javaswift.joss.instructions.DownloadInstructions;
import org.javaswift.joss.instructions.UploadInstructions;

Expand Down Expand Up @@ -266,5 +267,6 @@ public interface StoredObject extends ObjectStoreEntity, Comparable<DirectoryOrO
void setEtag(String etag);
void setContentLength(long contentLength);
void setContentTypeWithoutSaving(String contentType);

void setResponseHeaders(Header[] headers);
Header[] getResponseHeaders();
}