You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by ga...@apache.org on 2014/05/06 14:04:32 UTC

svn commit: r1592730 - in /chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS: Bindings/AtomPub/ Bindings/Browser/ Common/ Utils/

Author: gavincornwell
Date: Tue May  6 12:04:31 2014
New Revision: 1592730

URL: http://svn.apache.org/r1592730
Log:
Removed AtomPub specifics from CMISHttpUploadRequest as discussed on dev mailing list.

Modified:
    chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Bindings/AtomPub/CMISAtomPubBaseService.m
    chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Bindings/Browser/CMISBrowserObjectService.m
    chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Bindings/Browser/CMISBrowserVersioningService.m
    chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISNetworkProvider.h
    chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Utils/CMISDefaultNetworkProvider.m
    chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Utils/CMISHttpUploadRequest.h
    chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Utils/CMISHttpUploadRequest.m

Modified: chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Bindings/AtomPub/CMISAtomPubBaseService.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Bindings/AtomPub/CMISAtomPubBaseService.m?rev=1592730&r1=1592729&r2=1592730&view=diff
==============================================================================
--- chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Bindings/AtomPub/CMISAtomPubBaseService.m (original)
+++ chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Bindings/AtomPub/CMISAtomPubBaseService.m Tue May  6 12:04:31 2014
@@ -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);

Modified: chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Bindings/Browser/CMISBrowserObjectService.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Bindings/Browser/CMISBrowserObjectService.m?rev=1592730&r1=1592729&r2=1592730&view=diff
==============================================================================
--- chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Bindings/Browser/CMISBrowserObjectService.m (original)
+++ chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Bindings/Browser/CMISBrowserObjectService.m Tue May  6 12:04:31 2014
@@ -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 {

Modified: chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Bindings/Browser/CMISBrowserVersioningService.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Bindings/Browser/CMISBrowserVersioningService.m?rev=1592730&r1=1592729&r2=1592730&view=diff
==============================================================================
--- chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Bindings/Browser/CMISBrowserVersioningService.m (original)
+++ chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Bindings/Browser/CMISBrowserVersioningService.m Tue May  6 12:04:31 2014
@@ -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];

Modified: chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISNetworkProvider.h
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISNetworkProvider.h?rev=1592730&r1=1592729&r2=1592730&view=diff
==============================================================================
--- chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISNetworkProvider.h (original)
+++ chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISNetworkProvider.h Tue May  6 12:04:31 2014
@@ -96,34 +96,6 @@ completionBlock:(void (^)(CMISHttpRespon
 
 
 /**
- * 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 @@ completionBlock:(void (^)(CMISHttpRespon
  * @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 @@ completionBlock:(void (^)(CMISHttpRespon
    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;
 

Modified: chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Utils/CMISDefaultNetworkProvider.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Utils/CMISDefaultNetworkProvider.m?rev=1592730&r1=1592729&r2=1592730&view=diff
==============================================================================
--- chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Utils/CMISDefaultNetworkProvider.m (original)
+++ chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Utils/CMISDefaultNetworkProvider.m Tue May  6 12:04:31 2014
@@ -134,46 +134,9 @@ completionBlock:(void (^)(CMISHttpRespon
        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 @@ completionBlock:(void (^)(CMISHttpRespon
                                                       authenticationProvider:session.authenticationProvider
                                                               startData:startData
                                                                     endData:endData
+                                                           useBase64Encoding:useBase64Encoding
                                                              completionBlock:completionBlock
                                                                progressBlock:progressBlock];
         if (request){

Modified: chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Utils/CMISHttpUploadRequest.h
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Utils/CMISHttpUploadRequest.h?rev=1592730&r1=1592729&r2=1592730&view=diff
==============================================================================
--- chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Utils/CMISHttpUploadRequest.h (original)
+++ chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Utils/CMISHttpUploadRequest.h Tue May  6 12:04:31 2014
@@ -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<CMISAuthentic
 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;
 

Modified: chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Utils/CMISHttpUploadRequest.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Utils/CMISHttpUploadRequest.m?rev=1592730&r1=1592729&r2=1592730&view=diff
==============================================================================
--- chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Utils/CMISHttpUploadRequest.m (original)
+++ chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Utils/CMISHttpUploadRequest.m Tue May  6 12:04:31 2014
@@ -96,15 +96,6 @@ const NSUInteger kRawBufferSize = 24576;
 @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 @@ const NSUInteger kRawBufferSize = 24576;
 
 + (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 @@ authenticationProvider:(id<CMISAuthentic
                                                             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 @@ totalBytesExpectedToWrite:(NSInteger)tot
 
 #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 @@ totalBytesExpectedToWrite:(NSInteger)tot
     
     // 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];
     }