Skip to content

Commit

Permalink
Issue 301: refactored http payload data from blob -> core, added cont…
Browse files Browse the repository at this point in the history
…ent length, type, md5; fixed length bug in ec2 and added more tests to ensure this doesn't happen again
  • Loading branch information
Adrian Cole committed Jul 8, 2010
1 parent c948e49 commit da3baf5
Show file tree
Hide file tree
Showing 137 changed files with 3,291 additions and 1,860 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;

import org.jclouds.atmosonline.saas.binders.BindAtmosObjectToPayloadAndMetadataToHeaders;
import org.jclouds.atmosonline.saas.binders.BindMetadataToHeaders;
import org.jclouds.atmosonline.saas.domain.AtmosObject;
import org.jclouds.atmosonline.saas.domain.BoundedSet;
import org.jclouds.atmosonline.saas.domain.DirectoryEntry;
Expand Down Expand Up @@ -113,7 +113,7 @@ ListenableFuture<? extends BoundedSet<? extends DirectoryEntry>> listDirectory(
@Consumes(MediaType.WILDCARD)
ListenableFuture<URI> createFile(
@PathParam("parent") String parent,
@PathParam("name") @ParamParser(AtmosObjectName.class) @BinderParam(BindAtmosObjectToPayloadAndMetadataToHeaders.class) AtmosObject object);
@PathParam("name") @ParamParser(AtmosObjectName.class) @BinderParam(BindMetadataToHeaders.class) AtmosObject object);

/**
* @see AtmosStorageClient#updateFile
Expand All @@ -124,7 +124,7 @@ ListenableFuture<URI> createFile(
@Consumes(MediaType.WILDCARD)
ListenableFuture<Void> updateFile(
@PathParam("parent") String parent,
@PathParam("name") @ParamParser(AtmosObjectName.class) @BinderParam(BindAtmosObjectToPayloadAndMetadataToHeaders.class) AtmosObject object);
@PathParam("name") @ParamParser(AtmosObjectName.class) @BinderParam(BindMetadataToHeaders.class) AtmosObject object);

/**
* @see AtmosStorageClient#readFile
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,28 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.mezeo.pcs2.binders;
package org.jclouds.atmosonline.saas.binders;

import static com.google.common.base.Preconditions.checkNotNull;

import javax.ws.rs.core.HttpHeaders;
import javax.inject.Inject;
import javax.inject.Singleton;

import org.jclouds.atmosonline.saas.domain.AtmosObject;
import org.jclouds.encryption.EncryptionService;
import org.jclouds.http.HttpRequest;
import org.jclouds.mezeo.pcs2.domain.PCSFile;
import org.jclouds.rest.Binder;

public class BindDataToPayload implements Binder {
@Singleton
public class BindMetadataToHeaders implements Binder {
private final BindUserMetadataToHeaders metaBinder;

@Inject
protected BindMetadataToHeaders(BindUserMetadataToHeaders metaBinder,
EncryptionService encryptionService) {
this.metaBinder = metaBinder;
}

public void bindToRequest(HttpRequest request, Object payload) {
PCSFile object = (PCSFile) payload;
request.setPayload(checkNotNull(object.getPayload().getInput(), "object.getContent()"));
request.getHeaders().put(HttpHeaders.CONTENT_LENGTH, object.getContentLength() + "");
AtmosObject object = (AtmosObject) payload;
metaBinder.bindToRequest(request, object.getUserMetadata());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,51 +20,34 @@

import static com.google.common.base.Preconditions.checkNotNull;

import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import javax.inject.Singleton;

import org.jclouds.atmosonline.saas.domain.UserMetadata;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder;

import com.google.common.base.Joiner;

@Singleton
public class BindUserMetadataToHeaders implements Binder {

public void bindToRequest(HttpRequest request, Object payload) {
UserMetadata md = (UserMetadata) checkNotNull(payload, "payload");
if (md.getMetadata().size() > 0) {
String header = join(md.getMetadata());
String header = Joiner.on(',').withKeyValueSeparator("=").join(md.getMetadata());
request.getHeaders().put("x-emc-meta", header);
}
if (md.getListableMetadata().size() > 0) {
String header = join(md.getListableMetadata());
String header = Joiner.on(',').withKeyValueSeparator("=").join(md.getListableMetadata());
request.getHeaders().put("x-emc-listable-meta", header);
}
if (md.getTags().size() > 0) {
String header = join(md.getTags());
String header = Joiner.on(',').join(md.getTags());
request.getHeaders().put("x-emc-tags", header);
}
if (md.getListableTags().size() > 0) {
String header = join(md.getListableTags());
String header = Joiner.on(',').join(md.getListableTags());
request.getHeaders().put("x-emc-listable-tags", header);
}
}

private String join(Set<String> set) {
StringBuffer header = new StringBuffer();
for (String entry : set) {
header.append(entry).append(",");
}
header.deleteCharAt(header.length() - 1);
return header.toString();
}

private String join(Map<String, String> map) {
StringBuffer header = new StringBuffer();
for (Entry<String, String> entry : map.entrySet()) {
header.append(entry.getKey()).append("=").append(entry.getValue()).append(",");
}
header.deleteCharAt(header.length() - 1);
return header.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public AtmosObject apply(Blob from) {
if (from == null)
return null;
AtmosObject object = blobMd2Object.apply(from.getMetadata());
if (from.getContentLength() != null)
object.setContentLength(from.getContentLength());
object.setPayload(checkNotNull(from.getPayload(), "payload: " + from));
object.setAllHeaders(from.getAllHeaders());
return object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public Blob apply(AtmosObject from) {
if (from == null)
return null;
Blob blob = blobFactory.create(object2BlobMd.apply(from));
blob.setPayload(checkNotNull(from.getPayload(), "payload: " + from));
if (from.getContentMetadata().getContentLength() != null)
blob.setContentLength(from.getContentMetadata().getContentLength());
blob.getMetadata().setSize(from.getContentMetadata().getContentLength());
blob.getMetadata().setContentMD5(from.getSystemMetadata().getContentMD5());
blob.setPayload(checkNotNull(from.getPayload(), "payload: " + from));
blob.setAllHeaders(from.getAllHeaders());
return blob;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Long getContentLength() {
/**
* @see #getContentLength
*/
public void setContentLength(long contentLength) {
public void setContentLength(Long contentLength) {
this.contentLength = contentLength;
}

Expand Down
Loading

0 comments on commit da3baf5

Please sign in to comment.