mirror of https://github.com/apache/jclouds.git
Build S3 multi-delete request with an XML library
This commit addresses test failures in AWSS3BlobIntegrationLiveTest.deleteMultipleObjects.
This commit is contained in:
parent
c14141dec3
commit
2553b09bb4
|
@ -21,7 +21,16 @@ import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.hash.Hashing.md5;
|
import static com.google.common.hash.Hashing.md5;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.transform.OutputKeys;
|
||||||
|
import javax.xml.transform.TransformerException;
|
||||||
|
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.jamesmurty.utils.XMLBuilder;
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.io.Payload;
|
import org.jclouds.io.Payload;
|
||||||
|
@ -38,17 +47,26 @@ public class BindIterableAsPayloadToDeleteRequest implements Binder {
|
||||||
checkNotNull(request, "request is null");
|
checkNotNull(request, "request is null");
|
||||||
|
|
||||||
Iterable<String> keys = (Iterable<String>) input;
|
Iterable<String> keys = (Iterable<String>) input;
|
||||||
StringBuilder builder = new StringBuilder();
|
checkArgument(!Iterables.isEmpty(keys), "The list of keys should not be empty.");
|
||||||
for (String key : keys) {
|
|
||||||
builder.append(String.format("<Object><Key>%s</Key></Object>", key));
|
String content;
|
||||||
|
try {
|
||||||
|
XMLBuilder rootBuilder = XMLBuilder.create("Delete");
|
||||||
|
for (String key : keys) {
|
||||||
|
XMLBuilder ownerBuilder = rootBuilder.elem("Object");
|
||||||
|
XMLBuilder keyBuilder = ownerBuilder.elem("Key").text(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
Properties outputProperties = new Properties();
|
||||||
|
outputProperties.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||||
|
content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||||
|
rootBuilder.asString(outputProperties);
|
||||||
|
} catch (ParserConfigurationException pce) {
|
||||||
|
throw Throwables.propagate(pce);
|
||||||
|
} catch (TransformerException te) {
|
||||||
|
throw Throwables.propagate(te);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String objects = builder.toString();
|
|
||||||
checkArgument(!objects.isEmpty(), "The list of keys should not be empty.");
|
|
||||||
|
|
||||||
final String content = String.format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
|
||||||
"<Delete>%s</Delete>", objects);
|
|
||||||
|
|
||||||
Payload payload = Payloads.newStringPayload(content);
|
Payload payload = Payloads.newStringPayload(content);
|
||||||
payload.getContentMetadata().setContentType(MediaType.TEXT_XML);
|
payload.getContentMetadata().setContentType(MediaType.TEXT_XML);
|
||||||
byte[] md5 = md5().hashString(content, UTF_8).asBytes();
|
byte[] md5 = md5().hashString(content, UTF_8).asBytes();
|
||||||
|
|
Loading…
Reference in New Issue