Removed AtomPub specifics from CMISHttpUploadRequest as discussed on dev mailing list.
git-svn-id: https://svn.apache.org/repos/asf/chemistry/objectivecmis/branches/browser-binding@1592730 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ObjectiveCMIS/Bindings/AtomPub/CMISAtomPubBaseService.m b/ObjectiveCMIS/Bindings/AtomPub/CMISAtomPubBaseService.m
index e6df482..9215151 100644
--- a/ObjectiveCMIS/Bindings/AtomPub/CMISAtomPubBaseService.m
+++ b/ObjectiveCMIS/Bindings/AtomPub/CMISAtomPubBaseService.m
@@ -408,6 +408,21 @@
return;
}
+ // generate start and end XML
+ CMISAtomEntryWriter *writer = [[CMISAtomEntryWriter alloc] init];
+ writer.cmisProperties = properties;
+ writer.mimeType = contentMimeType;
+
+ NSString *xmlStart = [writer xmlStartElement];
+ NSString *xmlContentStart = [writer xmlContentStartElement];
+ NSString *start = [NSString stringWithFormat:@"%@%@", xmlStart, xmlContentStart];
+ NSData *startData = [NSMutableData dataWithData:[start dataUsingEncoding:NSUTF8StringEncoding]];
+
+ NSString *xmlContentEnd = [writer xmlContentEndElement];
+ NSString *xmlProperties = [writer xmlPropertiesElements];
+ NSString *end = [NSString stringWithFormat:@"%@%@", xmlContentEnd, xmlProperties];
+ NSData *endData = [end dataUsingEncoding:NSUTF8StringEncoding];
+
// The underlying CMISHttpUploadRequest object generates the atom entry. The base64 encoded content is generated on
// the fly to support very large files.
[self.bindingSession.networkProvider invoke:[NSURL URLWithString:link]
@@ -417,8 +432,9 @@
headers:[NSDictionary dictionaryWithObject:kCMISMediaTypeEntry forKey:@"Content-type"]
bytesExpected:bytesExpected
cmisRequest:request
- cmisProperties:properties
- mimeType:contentMimeType
+ startData:startData
+ endData:endData
+ useBase64Encoding:YES
completionBlock:^(CMISHttpResponse *response, NSError *error) {
if (error) {
CMISLogError(@"HTTP error when sending atom entry: %@", error);
diff --git a/ObjectiveCMIS/Bindings/Browser/CMISBrowserObjectService.m b/ObjectiveCMIS/Bindings/Browser/CMISBrowserObjectService.m
index 3fb0cb1..2607d49 100644
--- a/ObjectiveCMIS/Bindings/Browser/CMISBrowserObjectService.m
+++ b/ObjectiveCMIS/Bindings/Browser/CMISBrowserObjectService.m
@@ -337,6 +337,7 @@
cmisRequest:cmisRequest
startData:formData.startData
endData:formData.endData
+ useBase64Encoding:NO
completionBlock:^(CMISHttpResponse *httpResponse, NSError *error) {
if ((httpResponse.statusCode == 200 || httpResponse.statusCode == 201) && httpResponse.data) {
CMISBrowserTypeCache *typeCache = [[CMISBrowserTypeCache alloc] initWithRepositoryId:self.bindingSession.repositoryId bindingService:self];
@@ -457,6 +458,7 @@
cmisRequest:cmisRequest
startData:formData.startData
endData:formData.endData
+ useBase64Encoding:NO
completionBlock:responseHandlingBlock
progressBlock:progressBlock];
} else {
diff --git a/ObjectiveCMIS/Bindings/Browser/CMISBrowserVersioningService.m b/ObjectiveCMIS/Bindings/Browser/CMISBrowserVersioningService.m
index 3efda98..fefeabb 100644
--- a/ObjectiveCMIS/Bindings/Browser/CMISBrowserVersioningService.m
+++ b/ObjectiveCMIS/Bindings/Browser/CMISBrowserVersioningService.m
@@ -309,6 +309,7 @@
cmisRequest:cmisRequest
startData:formData.startData
endData:formData.endData
+ useBase64Encoding:NO
completionBlock:^(CMISHttpResponse *httpResponse, NSError *error) {
if ((httpResponse.statusCode == 200 || httpResponse.statusCode == 201) && httpResponse.data) {
CMISBrowserTypeCache *typeCache = [[CMISBrowserTypeCache alloc] initWithRepositoryId:self.bindingSession.repositoryId bindingService:self];
diff --git a/ObjectiveCMIS/Common/CMISNetworkProvider.h b/ObjectiveCMIS/Common/CMISNetworkProvider.h
index fe4eeba..a9dfd68 100644
--- a/ObjectiveCMIS/Common/CMISNetworkProvider.h
+++ b/ObjectiveCMIS/Common/CMISNetworkProvider.h
@@ -96,34 +96,6 @@
/**
- * Invoke method used for uploads, i.e. POST/PUT requests. This method is used for encoding base64 data while streaming
- * @param url the RESTful API URL to be used
- * @param httpRequestMethod
- * @param session
- * @param inputStream the stream pointing to the source to be uploaded. Must be an instance or extension of NSInputStream
- * @param headers any additional headers to be used in the request (maybe nil)
- * @param bytesExpected the size of the content to be uploaded
- * @param cmisRequest will be used to set the cancellable request to the one created by the invoked method
- * @param cmisProperties
- * @param mimeType
- * @param completionBlock returns an instance of the HTTPResponse if successful or nil otherwise
- * @param progressBlock
- * @param requestObject a handle to the CMISRequest allowing this HTTP request to be cancelled
- */
-- (void)invoke:(NSURL *)url
- httpMethod:(CMISHttpRequestMethod)httpRequestMethod
- session:(CMISBindingSession *)session
- inputStream:(NSInputStream *)inputStream
- headers:(NSDictionary *)additionalHeaders
- bytesExpected:(unsigned long long)bytesExpected
- cmisRequest:(CMISRequest *)cmisRequest
-cmisProperties:(CMISProperties *)cmisProperties
- mimeType:(NSString *)mimeType
-completionBlock:(void (^)(CMISHttpResponse *httpResponse, NSError *error))completionBlock
- progressBlock:(void (^)(unsigned long long bytesDownloaded, unsigned long long bytesTotal))progressBlock;
-
-
-/**
* Invoke method used for uploads, i.e. POST/PUT requests. This method is used for putting the stream data between the start and end data
* @param url the RESTful API URL to be used
* @param httpRequestMethod
@@ -134,6 +106,7 @@
* @param cmisRequest will be used to set the cancellable request to the one created by the invoked method
* @param startData start payload e.g. containing the form data before the input stream is written
* @param endData end payload e.g. containing the form data after the input stream is written
+ * @param useBase64Encoding Determines whether the data sent via the inputStream is encoded as base64 as it's sent to the server
* @param completionBlock returns an instance of the HTTPResponse if successful or nil otherwise
* @param progressBlock
* @param requestObject a handle to the CMISRequest allowing this HTTP request to be cancelled
@@ -147,6 +120,7 @@
cmisRequest:(CMISRequest *)cmisRequest
startData:(NSData *)startData
endData:(NSData *)endData
+useBase64Encoding:(BOOL)useBase64Encoding
completionBlock:(void (^)(CMISHttpResponse *httpResponse, NSError *error))completionBlock
progressBlock:(void (^)(unsigned long long bytesDownloaded, unsigned long long bytesTotal))progressBlock;
diff --git a/ObjectiveCMIS/Utils/CMISDefaultNetworkProvider.m b/ObjectiveCMIS/Utils/CMISDefaultNetworkProvider.m
index f4cdbc0..a3494e7 100644
--- a/ObjectiveCMIS/Utils/CMISDefaultNetworkProvider.m
+++ b/ObjectiveCMIS/Utils/CMISDefaultNetworkProvider.m
@@ -134,46 +134,9 @@
headers:(NSDictionary *)additionalHeaders
bytesExpected:(unsigned long long)bytesExpected
cmisRequest:(CMISRequest *)cmisRequest
-cmisProperties:(CMISProperties *)cmisProperties
- mimeType:(NSString *)mimeType
-completionBlock:(void (^)(CMISHttpResponse *httpResponse, NSError *error))completionBlock
- progressBlock:(void (^)(unsigned long long bytesDownloaded, unsigned long long bytesTotal))progressBlock
-{
- if (!cmisRequest.isCancelled) {
- NSMutableURLRequest *urlRequest = [CMISDefaultNetworkProvider createRequestForUrl:url
- httpMethod:httpRequestMethod
- session:session];
-
- CMISHttpUploadRequest* request = [CMISHttpUploadRequest startRequest:urlRequest
- httpMethod:httpRequestMethod
- inputStream:inputStream
- headers:additionalHeaders
- bytesExpected:bytesExpected
- authenticationProvider:session.authenticationProvider
- cmisProperties:cmisProperties
- mimeType:mimeType
- completionBlock:completionBlock
- progressBlock:progressBlock];
- if (request){
- cmisRequest.httpRequest = request;
- }
- } else {
- if (completionBlock) {
- completionBlock(nil, [CMISErrors createCMISErrorWithCode:kCMISErrorCodeCancelled
- detailedDescription:@"Request was cancelled"]);
- }
- }
-}
-
-- (void)invoke:(NSURL *)url
- httpMethod:(CMISHttpRequestMethod)httpRequestMethod
- session:(CMISBindingSession *)session
- inputStream:(NSInputStream *)inputStream
- headers:(NSDictionary *)additionalHeaders
- bytesExpected:(unsigned long long)bytesExpected
- cmisRequest:(CMISRequest *)cmisRequest
startData:(NSData *)startData
endData:(NSData *)endData
+useBase64Encoding:(BOOL)useBase64Encoding
completionBlock:(void (^)(CMISHttpResponse *, NSError *))completionBlock
progressBlock:(void (^)(unsigned long long, unsigned long long))progressBlock
{
@@ -190,6 +153,7 @@
authenticationProvider:session.authenticationProvider
startData:startData
endData:endData
+ useBase64Encoding:useBase64Encoding
completionBlock:completionBlock
progressBlock:progressBlock];
if (request){
diff --git a/ObjectiveCMIS/Utils/CMISHttpUploadRequest.h b/ObjectiveCMIS/Utils/CMISHttpUploadRequest.h
index 378a08e..d3d1243 100644
--- a/ObjectiveCMIS/Utils/CMISHttpUploadRequest.h
+++ b/ObjectiveCMIS/Utils/CMISHttpUploadRequest.h
@@ -39,26 +39,8 @@
progressBlock:(void (^)(unsigned long long bytesUploaded, unsigned long long bytesTotal))progressBlock;
/**
- * starts a URL request with a provided input stream. The input stream has to point to the raw NON-encoded data set. This method will use the
- * provided CMIS properties and mimeType to create the appropriate XML data. The base 64 encoding will be done while the data are being read in
- * from the source input stream.
- * In order to achieve this, the pairing an OutputStream (where we will write the XML and base64 data to) with a resulting fully base64 encoded
- * input stream. This base64 encoded inputstream will be passed on to the NSMutableURLRequest via its HTTPBodyStream property/method.
- */
-+ (id)startRequest:(NSMutableURLRequest *)urlRequest
- httpMethod:(CMISHttpRequestMethod)httpRequestMethod
- inputStream:(NSInputStream*)sourceInputStream
- headers:(NSDictionary*)additionalHeaders
- bytesExpected:(unsigned long long)bytesExpected
-authenticationProvider:(id<CMISAuthenticationProvider>) authenticationProvider
- cmisProperties:(CMISProperties *)cmisProperties
- mimeType:(NSString *)mimeType
- completionBlock:(void (^)(CMISHttpResponse *httpResponse, NSError *error))completionBlock
- progressBlock:(void (^)(unsigned long long bytesUploaded, unsigned long long bytesTotal))progressBlock;
-
-/**
* starts a URL request with a provided input stream. The input stream has to point to the raw NON-encoded data set. This method will first write the
- * provided start data, afterwards the content of the input stream and then the provided end data.
+ * provided start data, afterwards the content of the input stream (optionally encoding it as base64) and then the provided end data.
*/
+ (id)startRequest:(NSMutableURLRequest *)urlRequest
httpMethod:(CMISHttpRequestMethod)httpRequestMethod
@@ -68,6 +50,7 @@
authenticationProvider:(id<CMISAuthenticationProvider>) authenticationProvider
startData:(NSData *)startData
endData:(NSData *)endData
+ useBase64Encoding:(BOOL)useBase64Encoding
completionBlock:(void (^)(CMISHttpResponse *httpResponse, NSError *error))completionBlock
progressBlock:(void (^)(unsigned long long bytesUploaded, unsigned long long bytesTotal))progressBlock;
diff --git a/ObjectiveCMIS/Utils/CMISHttpUploadRequest.m b/ObjectiveCMIS/Utils/CMISHttpUploadRequest.m
index d8ede35..284a434 100644
--- a/ObjectiveCMIS/Utils/CMISHttpUploadRequest.m
+++ b/ObjectiveCMIS/Utils/CMISHttpUploadRequest.m
@@ -96,15 +96,6 @@
@property (nonatomic, assign, readwrite) size_t bufferOffset;
@property (nonatomic, assign, readwrite) size_t bufferLimit;
-- (void)stopSendWithStatus:(NSString *)statusString;
-+ (unsigned long long)base64EncodedLength:(unsigned long long)contentSize;
-- (void)prepareXMLWithCMISProperties:(CMISProperties *)cmisProperties mimeType:(NSString *)mimeType;
-- (void)prepareStreams;
-
-- (id)initWithHttpMethod:(CMISHttpRequestMethod)httpRequestMethod
- completionBlock:(void (^)(CMISHttpResponse *httpResponse, NSError *error))completionBlock
- progressBlock:(void (^)(unsigned long long bytesUploaded, unsigned long long bytesTotal))progressBlock;
-
@end
@@ -139,43 +130,13 @@
+ (id)startRequest:(NSMutableURLRequest *)urlRequest
httpMethod:(CMISHttpRequestMethod)httpRequestMethod
- inputStream:(NSInputStream*)inputStream
- headers:(NSDictionary*)additionalHeaders
- bytesExpected:(unsigned long long)bytesExpected
-authenticationProvider:(id<CMISAuthenticationProvider>) authenticationProvider
- cmisProperties:(CMISProperties *)cmisProperties
- mimeType:(NSString *)mimeType
- completionBlock:(void (^)(CMISHttpResponse *httpResponse, NSError *error))completionBlock
- progressBlock:(void (^)(unsigned long long bytesUploaded, unsigned long long bytesTotal))progressBlock
-{
- CMISHttpUploadRequest *httpRequest = [[self alloc] initWithHttpMethod:httpRequestMethod
- completionBlock:completionBlock
- progressBlock:progressBlock];
-
- httpRequest.inputStream = inputStream;
- httpRequest.additionalHeaders = additionalHeaders;
- httpRequest.bytesExpected = bytesExpected;
- httpRequest.useCombinedInputStream = YES;
- httpRequest.base64Encoding = YES;
- httpRequest.authenticationProvider = authenticationProvider;
-
- [httpRequest prepareStreams];
- [httpRequest prepareXMLWithCMISProperties:cmisProperties mimeType:mimeType];
- if (![httpRequest startRequest:urlRequest]) {
- httpRequest = nil;
- }
-
- return httpRequest;
-}
-
-+ (id)startRequest:(NSMutableURLRequest *)urlRequest
- httpMethod:(CMISHttpRequestMethod)httpRequestMethod
inputStream:(NSInputStream *)inputStream
headers:(NSDictionary *)additionalHeaders
bytesExpected:(unsigned long long)bytesExpected
authenticationProvider:(id<CMISAuthenticationProvider>)authenticationProvider
startData:(NSData *)startData
endData:(NSData *)endData
+ useBase64Encoding:(BOOL)useBase64Encoding
completionBlock:(void (^)(CMISHttpResponse *, NSError *))completionBlock
progressBlock:(void (^)(unsigned long long, unsigned long long))progressBlock
{
@@ -184,14 +145,15 @@
progressBlock:progressBlock];
httpRequest.inputStream = inputStream;
+ httpRequest.streamStartData = startData;
+ httpRequest.streamEndData = endData;
httpRequest.additionalHeaders = additionalHeaders;
httpRequest.bytesExpected = bytesExpected;
httpRequest.useCombinedInputStream = YES;
- httpRequest.base64Encoding = NO;
+ httpRequest.base64Encoding = useBase64Encoding;
httpRequest.authenticationProvider = authenticationProvider;
[httpRequest prepareStreams];
- [httpRequest setStartData:startData endData:endData];
if (![httpRequest startRequest:urlRequest]) {
httpRequest = nil;
}
@@ -455,43 +417,19 @@
#pragma private methods
-// TODO this method could be moved down to the respective atom class
-- (void)prepareXMLWithCMISProperties:(CMISProperties *)cmisProperties mimeType:(NSString *)mimeType
-{
- CMISAtomEntryWriter *writer = [[CMISAtomEntryWriter alloc] init];
- writer.cmisProperties = cmisProperties;
- writer.mimeType = mimeType;
-
- NSString *xmlStart = [writer xmlStartElement];
- NSString *xmlContentStart = [writer xmlContentStartElement];
-
- NSString *start = [NSString stringWithFormat:@"%@%@", xmlStart, xmlContentStart];
- NSData *startData = [NSMutableData dataWithData:[start dataUsingEncoding:NSUTF8StringEncoding]];
-
- NSString *xmlContentEnd = [writer xmlContentEndElement];
- NSString *xmlProperties = [writer xmlPropertiesElements];
- NSString *end = [NSString stringWithFormat:@"%@%@", xmlContentEnd, xmlProperties];
- NSData *endData = [end dataUsingEncoding:NSUTF8StringEncoding];
-
- [self setStartData:startData endData:endData bytesExpected:[CMISHttpUploadRequest base64EncodedLength:self.bytesExpected]];
-
- self.encodedLength = self.bytesExpected;
-}
-
-- (void)setStartData:(NSData *)startData endData:(NSData *)endData
-{
- [self setStartData:startData endData:endData bytesExpected:self.bytesExpected];
-}
-
-- (void)setStartData:(NSData *)startData endData:(NSData *)endData bytesExpected:(unsigned long long)bytesExpected
+- (void)prepareStreams
{
self.bufferOffset = 0;
- self.streamStartData = startData;
- self.bufferLimit = startData.length;
- self.dataBuffer = [NSData dataWithData:startData];
+ self.bufferLimit = self.streamStartData.length;
+ self.dataBuffer = [NSData dataWithData:self.streamStartData];
- self.streamEndData = endData;
+ unsigned long long bytesExpected = self.bytesExpected;
+
+ if (self.base64Encoding) {
+ // if base64 encoding is being used we need to adjust the bytesExpected
+ bytesExpected = [CMISHttpUploadRequest base64EncodedLength:self.bytesExpected];
+ }
unsigned long long encodedLength = bytesExpected;
encodedLength += self.streamStartData.length;
@@ -499,10 +437,8 @@
// update the originally provided expected bytes with encoded length
self.bytesExpected = encodedLength;
-}
-
-- (void)prepareStreams
-{
+ self.encodedLength = self.bytesExpected;
+
if (self.inputStream.streamStatus != NSStreamStatusOpen) {
[self.inputStream open];
}