mirror of https://github.com/apache/jclouds.git
switch sqs to use HashCode for md5
This commit is contained in:
parent
2efd9a76ca
commit
c5fe0a77a4
|
@ -27,6 +27,8 @@ import org.jclouds.javax.annotation.Nullable;
|
|||
import org.jclouds.sqs.options.CreateQueueOptions;
|
||||
import org.jclouds.sqs.options.ListQueuesOptions;
|
||||
|
||||
import com.google.common.hash.HashCode;
|
||||
|
||||
/**
|
||||
* Provides access to SQS via their REST API.
|
||||
* <p/>
|
||||
|
@ -123,5 +125,5 @@ public interface SQSApi {
|
|||
* characters, see the preceding important note
|
||||
* @return md5 of the content sent
|
||||
*/
|
||||
byte[] sendMessage(URI queue, String message);
|
||||
HashCode sendMessage(URI queue, String message);
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ import org.jclouds.sqs.xml.RegexListQueuesResponseHandler;
|
|||
import org.jclouds.sqs.xml.RegexMD5Handler;
|
||||
import org.jclouds.sqs.xml.RegexQueueHandler;
|
||||
|
||||
import com.google.common.hash.HashCode;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
|
@ -93,6 +94,6 @@ public interface SQSAsyncApi {
|
|||
@Path("/")
|
||||
@FormParams(keys = ACTION, values = "SendMessage")
|
||||
@ResponseParser(RegexMD5Handler.class)
|
||||
ListenableFuture<byte[]> sendMessage(@EndpointParam URI queue, @FormParam("MessageBody") String message);
|
||||
ListenableFuture<HashCode> sendMessage(@EndpointParam URI queue, @FormParam("MessageBody") String message);
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ import org.jclouds.http.HttpResponse;
|
|||
import org.jclouds.http.functions.ReturnStringIf2xx;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.hash.HashCode;
|
||||
import com.google.common.hash.HashCodes;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
/**
|
||||
|
@ -37,7 +39,7 @@ import com.google.inject.Singleton;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class RegexMD5Handler implements Function<HttpResponse, byte[]> {
|
||||
public class RegexMD5Handler implements Function<HttpResponse, HashCode> {
|
||||
Pattern pattern = Pattern.compile("<MD5OfMessageBody>([\\S&&[^<]]+)</MD5OfMessageBody>");
|
||||
private final ReturnStringIf2xx returnStringIf200;
|
||||
|
||||
|
@ -47,13 +49,13 @@ public class RegexMD5Handler implements Function<HttpResponse, byte[]> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public byte[] apply(HttpResponse response) {
|
||||
byte[] value = null;
|
||||
public HashCode apply(HttpResponse response) {
|
||||
HashCode value = null;
|
||||
String content = returnStringIf200.apply(response);
|
||||
if (content != null) {
|
||||
Matcher matcher = pattern.matcher(content);
|
||||
if (matcher.find()) {
|
||||
value = CryptoStreams.hex(matcher.group(1));
|
||||
value = HashCodes.fromBytes(CryptoStreams.hex(matcher.group(1)));
|
||||
}
|
||||
}
|
||||
return value;
|
||||
|
|
|
@ -29,12 +29,14 @@ import java.util.Set;
|
|||
import java.util.SortedSet;
|
||||
|
||||
import org.jclouds.aws.AWSResponseException;
|
||||
import org.jclouds.crypto.CryptoStreams;
|
||||
import org.jclouds.sqs.internal.BaseSQSApiLiveTest;
|
||||
import org.testng.annotations.AfterTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.hash.HashCode;
|
||||
import com.google.common.hash.Hashing;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code SQSApi}
|
||||
|
@ -100,7 +102,7 @@ public class SQSApiLiveTest extends BaseSQSApiLiveTest {
|
|||
@Test(dependsOnMethods = "testCreateQueue")
|
||||
protected void testSendMessage() throws InterruptedException, IOException {
|
||||
String message = "hardyharhar";
|
||||
byte[] md5 = CryptoStreams.md5(message.getBytes());
|
||||
HashCode md5 = Hashing.md5().hashString(message, Charsets.UTF_8);
|
||||
for (URI queue : queues) {
|
||||
assertEquals(context.getApi().sendMessage(queue, message), md5);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue