Browse files

AWS SDK for iOS 1.4.1

  • Loading branch information...
1 parent d1480b6 commit 38e89549cc995d763ec7759f8da1423b59699860 @glenndierkes glenndierkes committed Sep 12, 2012
View
75 src/Amazon.DynamoDB/DynamoDBWebServiceClient.m
@@ -75,41 +75,62 @@ -(AmazonServiceResponse *)invoke:(AmazonServiceRequest *)generatedRequest rawReq
AMZLogDebug(@" %@: %@", [hKey description], [[urlRequest allHTTPHeaderFields] valueForKey:hKey]);
}
- NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest
- delegate:response
- startImmediately:NO];
+
+
+ if ([generatedRequest delegate] != nil) {
+
+ NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest
+ delegate:response
+ startImmediately:NO];
+ originalRequest.urlConnection = urlConnection;
+ [urlConnection start];
+
+ [NSTimer scheduledTimerWithTimeInterval:self.timeout
+ target:response
+ selector:@selector(timeout)
+ userInfo:nil
+ repeats:NO];
+
+ return nil;
+ }
+
+ generatedRequest.delegate = [[[AmazonRequestDelegate alloc] init] autorelease];
+
+ NSURLConnection *urlConnection = [[[NSURLConnection alloc] initWithRequest:urlRequest
+ delegate:response
+ startImmediately:NO] autorelease];
+ [urlConnection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:AWSDefaultRunLoopMode];
originalRequest.urlConnection = urlConnection;
[urlConnection start];
- if ([generatedRequest delegate] == nil) {
- NSTimer *timeoutTimer = [NSTimer scheduledTimerWithTimeInterval:self.timeout target:response selector:@selector(timeout) userInfo:nil repeats:NO];
- generatedRequest.delegate = [[[AmazonRequestDelegate alloc] init] autorelease];
-
- while (![(AmazonRequestDelegate *)(generatedRequest.delegate)isFinishedOrFailed]) {
- [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
- }
+ NSTimer *timeoutTimer = [NSTimer timerWithTimeInterval:self.timeout
+ target:response
+ selector:@selector(timeout)
+ userInfo:nil
+ repeats:NO];
+ [[NSRunLoop currentRunLoop] addTimer:timeoutTimer forMode:AWSDefaultRunLoopMode];
+
+ while (![(AmazonRequestDelegate *)(generatedRequest.delegate)isFinishedOrFailed]) {
+ [[NSRunLoop currentRunLoop] runMode:AWSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
+ }
- if (response.didTimeout) {
- [urlConnection cancel];
- }
- else {
- [timeoutTimer invalidate]; // invalidate also releases the object.
- }
+ if (response.didTimeout) {
+ [urlConnection cancel];
+ }
+ else {
+ [timeoutTimer invalidate]; // invalidate also releases the object.
+ }
- AMZLogDebug(@"Response Status Code : %d", response.httpStatusCode);
- if ( [self shouldRetry:response exception:((AmazonRequestDelegate *)generatedRequest.delegate).exception]) {
- AMZLog(@"Retring Request: %d", retries);
- generatedRequest.delegate = nil;
+ AMZLogDebug(@"Response Status Code : %d", response.httpStatusCode);
+ if ( [self shouldRetry:response exception:((AmazonRequestDelegate *)generatedRequest.delegate).exception]) {
+ AMZLog(@"Retring Request: %d", retries);
+ generatedRequest.delegate = nil;
- [self pauseExponentially:retries];
- retries++;
- }
- else {
- break;
- }
+ [self pauseExponentially:retries];
+ retries++;
}
else {
- return nil;
+ break;
}
}
View
2 src/Amazon.DynamoDB/Model/DynamoDBBatchGetItemRequestMarshaller.m
@@ -185,7 +185,7 @@ +(AmazonServiceRequest *)createRequest:(DynamoDBBatchGetItemRequest *)batchGetIt
request.content = [AmazonJSON JSONRepresentation:json];
- [request addValue:[NSString stringWithFormat:@"%d", [request.content length]] forHeader:@"Content-Length"];
+ [request addValue:[NSString stringWithFormat:@"%d", [[request.content dataUsingEncoding:NSUTF8StringEncoding] length]] forHeader:@"Content-Length"];
return [request autorelease];
}
View
2 src/Amazon.DynamoDB/Model/DynamoDBBatchWriteItemRequestMarshaller.m
@@ -248,7 +248,7 @@ +(AmazonServiceRequest *)createRequest:(DynamoDBBatchWriteItemRequest *)batchWri
request.content = [AmazonJSON JSONRepresentation:json];
- [request addValue:[NSString stringWithFormat:@"%d", [request.content length]] forHeader:@"Content-Length"];
+ [request addValue:[NSString stringWithFormat:@"%d", [[request.content dataUsingEncoding:NSUTF8StringEncoding] length]] forHeader:@"Content-Length"];
return [request autorelease];
}
View
2 src/Amazon.DynamoDB/Model/DynamoDBCreateTableRequestMarshaller.m
@@ -99,7 +99,7 @@ +(AmazonServiceRequest *)createRequest:(DynamoDBCreateTableRequest *)createTable
request.content = [AmazonJSON JSONRepresentation:json];
- [request addValue:[NSString stringWithFormat:@"%d", [request.content length]] forHeader:@"Content-Length"];
+ [request addValue:[NSString stringWithFormat:@"%d", [[request.content dataUsingEncoding:NSUTF8StringEncoding] length]] forHeader:@"Content-Length"];
return [request autorelease];
}
View
2 src/Amazon.DynamoDB/Model/DynamoDBDeleteItemRequestMarshaller.m
@@ -236,7 +236,7 @@ +(AmazonServiceRequest *)createRequest:(DynamoDBDeleteItemRequest *)deleteItemRe
request.content = [AmazonJSON JSONRepresentation:json];
- [request addValue:[NSString stringWithFormat:@"%d", [request.content length]] forHeader:@"Content-Length"];
+ [request addValue:[NSString stringWithFormat:@"%d", [[request.content dataUsingEncoding:NSUTF8StringEncoding] length]] forHeader:@"Content-Length"];
return [request autorelease];
}
View
2 src/Amazon.DynamoDB/Model/DynamoDBDeleteTableRequestMarshaller.m
@@ -43,7 +43,7 @@ +(AmazonServiceRequest *)createRequest:(DynamoDBDeleteTableRequest *)deleteTable
request.content = [AmazonJSON JSONRepresentation:json];
- [request addValue:[NSString stringWithFormat:@"%d", [request.content length]] forHeader:@"Content-Length"];
+ [request addValue:[NSString stringWithFormat:@"%d", [[request.content dataUsingEncoding:NSUTF8StringEncoding] length]] forHeader:@"Content-Length"];
return [request autorelease];
}
View
2 src/Amazon.DynamoDB/Model/DynamoDBDescribeTableRequestMarshaller.m
@@ -43,7 +43,7 @@ +(AmazonServiceRequest *)createRequest:(DynamoDBDescribeTableRequest *)describeT
request.content = [AmazonJSON JSONRepresentation:json];
- [request addValue:[NSString stringWithFormat:@"%d", [request.content length]] forHeader:@"Content-Length"];
+ [request addValue:[NSString stringWithFormat:@"%d", [[request.content dataUsingEncoding:NSUTF8StringEncoding] length]] forHeader:@"Content-Length"];
return [request autorelease];
}
View
2 src/Amazon.DynamoDB/Model/DynamoDBGetItemRequestMarshaller.m
@@ -179,7 +179,7 @@ +(AmazonServiceRequest *)createRequest:(DynamoDBGetItemRequest *)getItemRequest
request.content = [AmazonJSON JSONRepresentation:json];
- [request addValue:[NSString stringWithFormat:@"%d", [request.content length]] forHeader:@"Content-Length"];
+ [request addValue:[NSString stringWithFormat:@"%d", [[request.content dataUsingEncoding:NSUTF8StringEncoding] length]] forHeader:@"Content-Length"];
return [request autorelease];
}
View
2 src/Amazon.DynamoDB/Model/DynamoDBListTablesRequestMarshaller.m
@@ -47,7 +47,7 @@ +(AmazonServiceRequest *)createRequest:(DynamoDBListTablesRequest *)listTablesRe
request.content = [AmazonJSON JSONRepresentation:json];
- [request addValue:[NSString stringWithFormat:@"%d", [request.content length]] forHeader:@"Content-Length"];
+ [request addValue:[NSString stringWithFormat:@"%d", [[request.content dataUsingEncoding:NSUTF8StringEncoding] length]] forHeader:@"Content-Length"];
return [request autorelease];
}
View
2 src/Amazon.DynamoDB/Model/DynamoDBPutItemRequestMarshaller.m
@@ -173,7 +173,7 @@ +(AmazonServiceRequest *)createRequest:(DynamoDBPutItemRequest *)putItemRequest
request.content = [AmazonJSON JSONRepresentation:json];
- [request addValue:[NSString stringWithFormat:@"%d", [request.content length]] forHeader:@"Content-Length"];
+ [request addValue:[NSString stringWithFormat:@"%d", [[request.content dataUsingEncoding:NSUTF8StringEncoding] length]] forHeader:@"Content-Length"];
return [request autorelease];
}
View
2 src/Amazon.DynamoDB/Model/DynamoDBQueryRequestMarshaller.m
@@ -320,7 +320,7 @@ +(AmazonServiceRequest *)createRequest:(DynamoDBQueryRequest *)queryRequest
request.content = [AmazonJSON JSONRepresentation:json];
- [request addValue:[NSString stringWithFormat:@"%d", [request.content length]] forHeader:@"Content-Length"];
+ [request addValue:[NSString stringWithFormat:@"%d", [[request.content dataUsingEncoding:NSUTF8StringEncoding] length]] forHeader:@"Content-Length"];
return [request autorelease];
}
View
2 src/Amazon.DynamoDB/Model/DynamoDBScanRequestMarshaller.m
@@ -257,7 +257,7 @@ +(AmazonServiceRequest *)createRequest:(DynamoDBScanRequest *)scanRequest
request.content = [AmazonJSON JSONRepresentation:json];
- [request addValue:[NSString stringWithFormat:@"%d", [request.content length]] forHeader:@"Content-Length"];
+ [request addValue:[NSString stringWithFormat:@"%d", [[request.content dataUsingEncoding:NSUTF8StringEncoding] length]] forHeader:@"Content-Length"];
return [request autorelease];
}
View
2 src/Amazon.DynamoDB/Model/DynamoDBUpdateItemRequestMarshaller.m
@@ -305,7 +305,7 @@ +(AmazonServiceRequest *)createRequest:(DynamoDBUpdateItemRequest *)updateItemRe
request.content = [AmazonJSON JSONRepresentation:json];
- [request addValue:[NSString stringWithFormat:@"%d", [request.content length]] forHeader:@"Content-Length"];
+ [request addValue:[NSString stringWithFormat:@"%d", [[request.content dataUsingEncoding:NSUTF8StringEncoding] length]] forHeader:@"Content-Length"];
return [request autorelease];
}
View
2 src/Amazon.DynamoDB/Model/DynamoDBUpdateTableRequestMarshaller.m
@@ -59,7 +59,7 @@ +(AmazonServiceRequest *)createRequest:(DynamoDBUpdateTableRequest *)updateTable
request.content = [AmazonJSON JSONRepresentation:json];
- [request addValue:[NSString stringWithFormat:@"%d", [request.content length]] forHeader:@"Content-Length"];
+ [request addValue:[NSString stringWithFormat:@"%d", [[request.content dataUsingEncoding:NSUTF8StringEncoding] length]] forHeader:@"Content-Length"];
return [request autorelease];
}
View
68 src/Amazon.Runtime/AmazonAbstractWebServiceClient.m
@@ -18,6 +18,7 @@
#import "DynamoDBRequest.h"
#import "DynamoDBResponse.h"
+NSString *const AWSDefaultRunLoopMode = @"com.amazonaws.DefaultRunLoopMode";
@implementation AmazonAbstractWebServiceClient
@@ -99,41 +100,56 @@ -(AmazonServiceResponse *)invoke:(AmazonServiceRequest *)generatedRequest rawReq
// Setting this here and not the AmazonServiceRequest because S3 extends that class and sets its own Content-Type Header.
[urlRequest addValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
- NSURLConnection *urlConnection = [[[NSURLConnection alloc] initWithRequest:urlRequest
- delegate:response
- startImmediately:NO] autorelease];
+ if ([generatedRequest delegate] != nil) {
+
+ NSURLConnection *urlConnection = [[[NSURLConnection alloc] initWithRequest:urlRequest
+ delegate:response
+ startImmediately:NO] autorelease];
+ originalRequest.urlConnection = urlConnection;
+ [urlConnection start];
+
+ [NSTimer scheduledTimerWithTimeInterval:self.timeout target:response selector:@selector(timeout) userInfo:nil repeats:NO];
+
+ return nil;
+ }
+
+ generatedRequest.delegate = [[[AmazonRequestDelegate alloc] init] autorelease];
+
+ NSURLConnection *urlConnection = [[[NSURLConnection alloc] initWithRequest:urlRequest
+ delegate:response
+ startImmediately:NO] autorelease];
+ [urlConnection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:AWSDefaultRunLoopMode];
originalRequest.urlConnection = urlConnection;
[urlConnection start];
- if ([generatedRequest delegate] == nil) {
- NSTimer *timeoutTimer = [NSTimer scheduledTimerWithTimeInterval:self.timeout target:response selector:@selector(timeout) userInfo:nil repeats:NO];
- generatedRequest.delegate = [[[AmazonRequestDelegate alloc] init] autorelease];
+ NSTimer *timeoutTimer = [NSTimer timerWithTimeInterval:self.timeout
+ target:response
+ selector:@selector(timeout)
+ userInfo:nil
+ repeats:NO];
+ [[NSRunLoop currentRunLoop] addTimer:timeoutTimer forMode:AWSDefaultRunLoopMode];
- while (![(AmazonRequestDelegate *)(generatedRequest.delegate)isFinishedOrFailed]) {
- [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
- }
+ while (![(AmazonRequestDelegate *)(generatedRequest.delegate)isFinishedOrFailed]) {
+ [[NSRunLoop currentRunLoop] runMode:AWSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
+ }
- if (response.didTimeout) {
- [urlConnection cancel];
- }
- else {
- [timeoutTimer invalidate]; // invalidate also releases the object.
- }
+ if (response.didTimeout) {
+ [urlConnection cancel];
+ }
+ else {
+ [timeoutTimer invalidate]; // invalidate also releases the object.
+ }
- AMZLogDebug(@"Response Status Code : %d", response.httpStatusCode);
- if ( [self shouldRetry:response]) {
- AMZLog(@"Retring Request: %d", retries);
- generatedRequest.delegate = nil;
+ AMZLogDebug(@"Response Status Code : %d", response.httpStatusCode);
+ if ( [self shouldRetry:response]) {
+ AMZLog(@"Retring Request: %d", retries);
+ generatedRequest.delegate = nil;
- [self pauseExponentially:retries];
- retries++;
- }
- else {
- break;
- }
+ [self pauseExponentially:retries];
+ retries++;
}
else {
- return nil;
+ break;
}
}
View
102 src/Amazon.S3/AmazonS3Client.m
@@ -412,63 +412,79 @@ -(S3Response *)invoke:(S3Request *)request
if (retries > 0) {
request.date = [NSDate date];
}
-
+
NSURLRequest *urlRequest = [self signS3Request:request];
-
+
AMZLogDebug(@"%@ %@", [urlRequest HTTPMethod], [urlRequest URL]);
AMZLogDebug(@"Request headers: ");
for (id hKey in [[urlRequest allHTTPHeaderFields] allKeys])
{
AMZLogDebug(@" %@: %@", [hKey description], [[urlRequest allHTTPHeaderFields] valueForKey:hKey]);
}
-
+
response = [AmazonS3Client constructResponseFromRequest:request];
[response setRequest:request];
-
- NSURLConnection *urlConnection = [NSURLConnection connectionWithRequest:urlRequest delegate:response];
- NSTimer *timeoutTimer = [NSTimer scheduledTimerWithTimeInterval:self.timeout target:response selector:@selector(timeout) userInfo:nil repeats:NO];
-
+
+ if ([request delegate] != nil) {
+ NSURLConnection *urlConnection = [[[NSURLConnection alloc] initWithRequest:urlRequest
+ delegate:response
+ startImmediately:NO] autorelease];
+ request.urlConnection = urlConnection;
+ [urlConnection start];
+
+ [NSTimer scheduledTimerWithTimeInterval:self.timeout target:response selector:@selector(timeout) userInfo:nil repeats:NO];
+
+ return nil;
+ }
+
+ NSURLConnection *urlConnection = [[[NSURLConnection alloc] initWithRequest:urlRequest
+ delegate:response
+ startImmediately:NO] autorelease];
+ [urlConnection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:AWSDefaultRunLoopMode];
request.urlConnection = urlConnection;
-
- if ([request delegate] == nil) {
- while (!response.isFinishedLoading && !response.exception && !response.didTimeout) {
- [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
- }
-
- if (response.didTimeout) {
- [urlConnection cancel];
- }
- else {
- [timeoutTimer invalidate]; // invalidate also releases the object.
- }
-
- AMZLogDebug(@"Response Status Code : %d", response.httpStatusCode);
- if ( [self shouldRetry:response]) {
- AMZLogDebug(@"Retring Request: %d", retries);
-
- [self pauseExponentially:retries];
- retries++;
- }
- else {
- if (response.exception) {
- AMZLogDebug(@"Request threw exception: %@", [response.exception description]);
- if ([response.exception isMemberOfClass:[AmazonServiceException class]]) {
- AMZLogDebug(@"HTTP: %d, S3 Error Code: %@", ((AmazonServiceException *)response.exception).statusCode, ((AmazonServiceException *)response.exception).errorCode);
- }
- AMZLogDebug(@"Reason: %@", [response.exception reason]);
-
- response.error = [AmazonErrorHandler errorFromExceptionWithThrowsExceptionOption:response.exception];
- return response;
- }
-
- break;
- }
+ [urlConnection start];
+
+ NSTimer *timeoutTimer = [NSTimer timerWithTimeInterval:self.timeout
+ target:response
+ selector:@selector(timeout)
+ userInfo:nil
+ repeats:NO];
+ [[NSRunLoop currentRunLoop] addTimer:timeoutTimer forMode:AWSDefaultRunLoopMode];
+
+ while (!response.isFinishedLoading && !response.exception && !response.didTimeout) {
+ [[NSRunLoop currentRunLoop] runMode:AWSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
+ }
+
+ if (response.didTimeout) {
+ [urlConnection cancel];
}
else {
- return nil;
+ [timeoutTimer invalidate]; // invalidate also releases the object.
+ }
+
+ AMZLogDebug(@"Response Status Code : %d", response.httpStatusCode);
+ if ( [self shouldRetry:response]) {
+ AMZLogDebug(@"Retring Request: %d", retries);
+
+ [self pauseExponentially:retries];
+ retries++;
+ }
+ else {
+ if (response.exception) {
+ AMZLogDebug(@"Request threw exception: %@", [response.exception description]);
+ if ([response.exception isMemberOfClass:[AmazonServiceException class]]) {
+ AMZLogDebug(@"HTTP: %d, S3 Error Code: %@", ((AmazonServiceException *)response.exception).statusCode, ((AmazonServiceException *)response.exception).errorCode);
+ }
+ AMZLogDebug(@"Reason: %@", [response.exception reason]);
+
+ response.error = [AmazonErrorHandler errorFromExceptionWithThrowsExceptionOption:response.exception];
+ return response;
+ }
+
+ break;
}
}
-
+
if (response.exception) {
AMZLogDebug(@"Request threw exception: %@", [response.exception description]);
if ([response.exception isMemberOfClass:[AmazonServiceException class]]) {
View
4 src/Amazon.S3/Model/S3Grantee.m
@@ -50,7 +50,7 @@ +(id)allUsers
static S3Grantee *allUsers = nil;
if (allUsers == nil) {
- @synchronized(allUsers) {
+ @synchronized([self class]) {
if (allUsers == nil) {
allUsers = [[S3Grantee granteeWithURI:kS3GroupURIAllUsers] retain];
}
@@ -64,7 +64,7 @@ +(id)authenticatedUsers
static S3Grantee *authUsers = nil;
if (authUsers == nil) {
- @synchronized(authUsers) {
+ @synchronized([self class]) {
if (authUsers == nil) {
authUsers = [[S3Grantee granteeWithURI:kS3GroupURIAuthUsers] retain];
}
View
2 src/include/AmazonAbstractWebServiceClient.h
@@ -29,6 +29,8 @@
#import "AmazonRequestDelegate.h"
#import "AmazonErrorHandler.h"
+extern NSString *const AWSDefaultRunLoopMode;
+
@interface AmazonAbstractWebServiceClient:NSObject
{
AmazonCredentials *credentials;
View
2 src/include/AmazonSDKUtil.h
@@ -17,7 +17,7 @@
#import <UIKit/UIKit.h>
#import "AmazonClientException.h"
-#define AWS_SDK_VERSION @"1.4.0"
+#define AWS_SDK_VERSION @"1.4.1"
#define AWS_SDK_USER_AGENT_FORMAT @"aws-sdk-iOS/%@ %@/%@ %@"
#define kISO8061DateFormat @"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
#define kISO8601DateFormat @"yyyy-MM-dd'T'HH:mm:ss'Z'"

0 comments on commit 38e8954

Please sign in to comment.