You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2011/03/16 13:31:28 UTC

svn commit: r1082138 - in /chemistry/dotcmis/trunk/DotCMIS: Properties/AssemblyInfo.cs binding/binding-intf.cs binding/converter.cs binding/webservices/webservices.cs client/client-impl.cs client/client-intf.cs const.cs

Author: fmui
Date: Wed Mar 16 12:31:27 2011
New Revision: 1082138

URL: http://svn.apache.org/viewvc?rev=1082138&view=rev
Log:
- improved Web Services compatibility
- fixed a few Web Services bugs
- added additional GetObject(string) method

Modified:
    chemistry/dotcmis/trunk/DotCMIS/Properties/AssemblyInfo.cs
    chemistry/dotcmis/trunk/DotCMIS/binding/binding-intf.cs
    chemistry/dotcmis/trunk/DotCMIS/binding/converter.cs
    chemistry/dotcmis/trunk/DotCMIS/binding/webservices/webservices.cs
    chemistry/dotcmis/trunk/DotCMIS/client/client-impl.cs
    chemistry/dotcmis/trunk/DotCMIS/client/client-intf.cs
    chemistry/dotcmis/trunk/DotCMIS/const.cs

Modified: chemistry/dotcmis/trunk/DotCMIS/Properties/AssemblyInfo.cs
URL: http://svn.apache.org/viewvc/chemistry/dotcmis/trunk/DotCMIS/Properties/AssemblyInfo.cs?rev=1082138&r1=1082137&r2=1082138&view=diff
==============================================================================
--- chemistry/dotcmis/trunk/DotCMIS/Properties/AssemblyInfo.cs (original)
+++ chemistry/dotcmis/trunk/DotCMIS/Properties/AssemblyInfo.cs Wed Mar 16 12:31:27 2011
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
 // You can specify all the values or you can default the Build and Revision Numbers 
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("0.1.0.0")]
+[assembly: AssemblyVersion("0.1.1.0")]
 [assembly: AssemblyFileVersion("1.0.0.0")]

Modified: chemistry/dotcmis/trunk/DotCMIS/binding/binding-intf.cs
URL: http://svn.apache.org/viewvc/chemistry/dotcmis/trunk/DotCMIS/binding/binding-intf.cs?rev=1082138&r1=1082137&r2=1082138&view=diff
==============================================================================
--- chemistry/dotcmis/trunk/DotCMIS/binding/binding-intf.cs (original)
+++ chemistry/dotcmis/trunk/DotCMIS/binding/binding-intf.cs Wed Mar 16 12:31:27 2011
@@ -22,6 +22,8 @@ using System.Net;
 using DotCMIS.Binding.Impl;
 using DotCMIS.Binding.Services;
 using DotCMIS.CMISWebServicesReference;
+using System.ServiceModel.Description;
+using System.ServiceModel.Channels;
 
 namespace DotCMIS.Binding
 {
@@ -70,59 +72,98 @@ namespace DotCMIS.Binding
         {
             string user = GetUser();
             string password = GetPassword();
-            if (user == null || password == null)
+
+            // AtomPub authentictaion
+            WebRequest request = connection as WebRequest;
+            if (request != null)
+            {
+                if (user != null || password != null)
+                {
+                    request.Credentials = new NetworkCredential(user ?? "", password ?? "");
+                }
+                return;
+            }
+
+            // Web Services authentication
+            RepositoryServicePortClient repositoryServicePortClient = connection as RepositoryServicePortClient;
+            if (repositoryServicePortClient != null)
             {
+                AddUsernameCredentials(repositoryServicePortClient.Endpoint, repositoryServicePortClient.ClientCredentials, user, password);
                 return;
             }
 
-            if (connection is RepositoryServicePortClient)
+            NavigationServicePortClient navigationServicePortClient = connection as NavigationServicePortClient;
+            if (navigationServicePortClient != null)
             {
-                ((RepositoryServicePortClient)connection).ClientCredentials.UserName.UserName = user;
-                ((RepositoryServicePortClient)connection).ClientCredentials.UserName.Password = password;
+                AddUsernameCredentials(navigationServicePortClient.Endpoint, navigationServicePortClient.ClientCredentials, user, password);
+                return;
             }
-            else if (connection is NavigationServicePortClient)
+
+            ObjectServicePortClient objectServicePortClient = connection as ObjectServicePortClient;
+            if (objectServicePortClient != null)
             {
-                ((NavigationServicePortClient)connection).ClientCredentials.UserName.UserName = user;
-                ((NavigationServicePortClient)connection).ClientCredentials.UserName.Password = password;
+                AddUsernameCredentials(objectServicePortClient.Endpoint, objectServicePortClient.ClientCredentials, user, password);
+                return;
             }
-            else if (connection is ObjectServicePortClient)
+
+            VersioningServicePortClient versioningServicePortClient = connection as VersioningServicePortClient;
+            if (versioningServicePortClient != null)
             {
-                ((ObjectServicePortClient)connection).ClientCredentials.UserName.UserName = user;
-                ((ObjectServicePortClient)connection).ClientCredentials.UserName.Password = password;
+                AddUsernameCredentials(versioningServicePortClient.Endpoint, versioningServicePortClient.ClientCredentials, user, password);
+                return;
             }
-            else if (connection is VersioningServicePortClient)
+
+            DiscoveryServicePortClient discoveryServicePortClient = connection as DiscoveryServicePortClient;
+            if (discoveryServicePortClient != null)
             {
-                ((VersioningServicePortClient)connection).ClientCredentials.UserName.UserName = user;
-                ((VersioningServicePortClient)connection).ClientCredentials.UserName.Password = password;
+                AddUsernameCredentials(discoveryServicePortClient.Endpoint, discoveryServicePortClient.ClientCredentials, user, password);
+                return;
             }
-            else if (connection is DiscoveryServicePortClient)
+
+            RelationshipServicePortClient relationshipServicePortClient = connection as RelationshipServicePortClient;
+            if (relationshipServicePortClient != null)
             {
-                ((DiscoveryServicePortClient)connection).ClientCredentials.UserName.UserName = user;
-                ((DiscoveryServicePortClient)connection).ClientCredentials.UserName.Password = password;
+                AddUsernameCredentials(relationshipServicePortClient.Endpoint, relationshipServicePortClient.ClientCredentials, user, password);
+                return;
             }
-            else if (connection is RelationshipServicePortClient)
+
+            MultiFilingServicePortClient multiFilingServicePortClient = connection as MultiFilingServicePortClient;
+            if (multiFilingServicePortClient != null)
             {
-                ((RelationshipServicePortClient)connection).ClientCredentials.UserName.UserName = user;
-                ((RelationshipServicePortClient)connection).ClientCredentials.UserName.Password = password;
+                AddUsernameCredentials(multiFilingServicePortClient.Endpoint, multiFilingServicePortClient.ClientCredentials, user, password);
+                return;
             }
-            else if (connection is MultiFilingServicePortClient)
+
+            PolicyServicePortClient policyServicePortClient = connection as PolicyServicePortClient;
+            if (policyServicePortClient != null)
             {
-                ((MultiFilingServicePortClient)connection).ClientCredentials.UserName.UserName = user;
-                ((MultiFilingServicePortClient)connection).ClientCredentials.UserName.Password = password;
+                AddUsernameCredentials(multiFilingServicePortClient.Endpoint, multiFilingServicePortClient.ClientCredentials, user, password);
+                return;
             }
-            else if (connection is PolicyServicePortClient)
+
+            ACLServicePortClient aclServicePortClient = connection as ACLServicePortClient;
+            if (aclServicePortClient != null)
             {
-                ((PolicyServicePortClient)connection).ClientCredentials.UserName.UserName = user;
-                ((PolicyServicePortClient)connection).ClientCredentials.UserName.Password = password;
+                AddUsernameCredentials(aclServicePortClient.Endpoint, aclServicePortClient.ClientCredentials, user, password);
+                return;
             }
-            else if (connection is ACLServicePortClient)
+        }
+
+        protected void AddUsernameCredentials(ServiceEndpoint endpoint, ClientCredentials clientCredentials, string user, string password)
+        {
+            if (user != null || password != null)
             {
-                ((ACLServicePortClient)connection).ClientCredentials.UserName.UserName = user;
-                ((ACLServicePortClient)connection).ClientCredentials.UserName.Password = password;
+                clientCredentials.UserName.UserName = user ?? "";
+                clientCredentials.UserName.Password = password ?? "";
             }
-            else if (connection is WebRequest)
+            else
             {
-                ((WebRequest)connection).Credentials = new NetworkCredential(user, password);
+                CustomBinding binding = endpoint.Binding as CustomBinding;
+                if (binding != null)
+                {
+                    // remove SecurityBindingElement is neither a username nor a password have been set
+                    binding.Elements.RemoveAll<SecurityBindingElement>();
+                }
             }
         }
     }

Modified: chemistry/dotcmis/trunk/DotCMIS/binding/converter.cs
URL: http://svn.apache.org/viewvc/chemistry/dotcmis/trunk/DotCMIS/binding/converter.cs?rev=1082138&r1=1082137&r2=1082138&view=diff
==============================================================================
--- chemistry/dotcmis/trunk/DotCMIS/binding/converter.cs (original)
+++ chemistry/dotcmis/trunk/DotCMIS/binding/converter.cs Wed Mar 16 12:31:27 2011
@@ -1204,11 +1204,11 @@ namespace DotCMIS.Binding
             RenditionData result = new RenditionData();
             result.StreamId = rendition.streamId;
             result.MimeType = rendition.mimetype;
-            result.Length = Int64.Parse(rendition.length);
+            result.Length = rendition.length == null ? null : (long?)Int64.Parse(rendition.length);
             result.Kind = rendition.kind;
             result.Title = rendition.title;
-            result.Height = Int64.Parse(rendition.height);
-            result.Width = Int64.Parse(rendition.width);
+            result.Height = rendition.height == null ? null : (long?)Int64.Parse(rendition.height);
+            result.Width = rendition.width == null ? null : (long?)Int64.Parse(rendition.width);
             result.RenditionDocumentId = rendition.renditionDocumentId;
 
             ConvertExtension(rendition, result);

Modified: chemistry/dotcmis/trunk/DotCMIS/binding/webservices/webservices.cs
URL: http://svn.apache.org/viewvc/chemistry/dotcmis/trunk/DotCMIS/binding/webservices/webservices.cs?rev=1082138&r1=1082137&r2=1082138&view=diff
==============================================================================
--- chemistry/dotcmis/trunk/DotCMIS/binding/webservices/webservices.cs (original)
+++ chemistry/dotcmis/trunk/DotCMIS/binding/webservices/webservices.cs Wed Mar 16 12:31:27 2011
@@ -26,6 +26,7 @@ using DotCMIS.Data;
 using DotCMIS.Data.Extensions;
 using DotCMIS.Exceptions;
 using DotCMIS.Enums;
+using System.ServiceModel.Channels;
 
 namespace DotCMIS.Binding.WebServices
 {
@@ -214,14 +215,37 @@ namespace DotCMIS.Binding.WebServices
         {
             object portObject = null;
 
-            BasicHttpBinding binding = new BasicHttpBinding();
-            binding.MessageEncoding = WSMessageEncoding.Mtom;
-            binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;
-            binding.TransferMode = TransferMode.Streamed;
-
-            long messageSize = session.GetValue(SessionParameter.MessageSize, 4 * 1024 * 1024);
-            binding.MaxReceivedMessageSize = messageSize;
-            binding.MaxBufferSize = (messageSize > Int32.MaxValue ? Int32.MaxValue : (int)messageSize);
+            CustomBinding binding;
+
+            string wcfBinding = session.GetValue(SessionParameter.WebServicesWCFBinding) as string;
+
+            if (wcfBinding != null)
+            {
+                binding = new CustomBinding(wcfBinding);
+            }
+            else
+            {
+                long messageSize = session.GetValue(SessionParameter.MessageSize, 4 * 1024 * 1024);
+
+                List<BindingElement> elements = new List<BindingElement>();
+
+                SecurityBindingElement securityElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
+                securityElement.SecurityHeaderLayout = SecurityHeaderLayout.LaxTimestampFirst;
+                //securityElement.IncludeTimestamp = false;
+                elements.Add(securityElement);
+
+                MtomMessageEncodingBindingElement mtomElement = new MtomMessageEncodingBindingElement();
+                mtomElement.MessageVersion = MessageVersion.Soap11;
+                mtomElement.MaxBufferSize = (messageSize > Int32.MaxValue ? Int32.MaxValue : (int)messageSize);
+                elements.Add(mtomElement);
+
+                HttpsTransportBindingElement transportElement = new HttpsTransportBindingElement();
+                transportElement.MaxReceivedMessageSize = messageSize;
+                transportElement.TransferMode = TransferMode.Streamed;
+                elements.Add(transportElement);
+
+                binding = new CustomBinding(elements);
+            }
 
             if (serviceKey == SessionParameter.WebServicesRepositoryService)
             {
@@ -509,7 +533,7 @@ namespace DotCMIS.Binding.WebServices
 
             try
             {
-                cmisObjectInFolderContainerType[] descendants = port.getDescendants(repositoryId, folderId, filter, depth.ToString(),
+                cmisObjectInFolderContainerType[] descendants = port.getDescendants(repositoryId, folderId, depth.ToString(), filter,
                     includeAllowableActions, (enumIncludeRelationships?)CmisValue.CmisToSerializerEnum(includeRelationships),
                     renditionFilter, includePathSegment, Converter.ConvertExtension(extension));
 
@@ -544,7 +568,7 @@ namespace DotCMIS.Binding.WebServices
 
             try
             {
-                cmisObjectInFolderContainerType[] descendants = port.getFolderTree(repositoryId, folderId, filter, depth.ToString(),
+                cmisObjectInFolderContainerType[] descendants = port.getFolderTree(repositoryId, folderId, depth.ToString(), filter,
                     includeAllowableActions, (enumIncludeRelationships?)CmisValue.CmisToSerializerEnum(includeRelationships),
                     renditionFilter, includePathSegment, Converter.ConvertExtension(extension));
 

Modified: chemistry/dotcmis/trunk/DotCMIS/client/client-impl.cs
URL: http://svn.apache.org/viewvc/chemistry/dotcmis/trunk/DotCMIS/client/client-impl.cs?rev=1082138&r1=1082137&r2=1082138&view=diff
==============================================================================
--- chemistry/dotcmis/trunk/DotCMIS/client/client-impl.cs (original)
+++ chemistry/dotcmis/trunk/DotCMIS/client/client-impl.cs Wed Mar 16 12:31:27 2011
@@ -473,6 +473,21 @@ namespace DotCMIS.Client.Impl
             {
                 throw new ArgumentException("Object Id must be set!");
             }
+
+            return GetObject(objectId.Id, context);
+        }
+
+        public ICmisObject GetObject(string objectId)
+        {
+            return GetObject(objectId, DefaultContext);
+        }
+
+        public ICmisObject GetObject(string objectId, IOperationContext context)
+        {
+            if (objectId == null)
+            {
+                throw new ArgumentException("Object Id must be set!");
+            }
             if (context == null)
             {
                 throw new ArgumentException("Operation context must be set!");
@@ -483,7 +498,7 @@ namespace DotCMIS.Client.Impl
             // ask the cache first
             if (context.CacheEnabled)
             {
-                result = Cache.GetById(objectId.Id, context.CacheKey);
+                result = Cache.GetById(objectId, context.CacheKey);
                 if (result != null)
                 {
                     return result;
@@ -491,7 +506,7 @@ namespace DotCMIS.Client.Impl
             }
 
             // get the object
-            IObjectData objectData = Binding.GetObjectService().GetObject(RepositoryId, objectId.Id, context.FilterString,
+            IObjectData objectData = Binding.GetObjectService().GetObject(RepositoryId, objectId, context.FilterString,
                 context.IncludeAllowableActions, context.IncludeRelationships, context.RenditionFilterString, context.IncludePolicies,
                 context.IncludeAcls, null);
 

Modified: chemistry/dotcmis/trunk/DotCMIS/client/client-intf.cs
URL: http://svn.apache.org/viewvc/chemistry/dotcmis/trunk/DotCMIS/client/client-intf.cs?rev=1082138&r1=1082137&r2=1082138&view=diff
==============================================================================
--- chemistry/dotcmis/trunk/DotCMIS/client/client-intf.cs (original)
+++ chemistry/dotcmis/trunk/DotCMIS/client/client-intf.cs Wed Mar 16 12:31:27 2011
@@ -173,8 +173,31 @@ namespace DotCMIS.Client
         IFolder GetRootFolder(IOperationContext context);
         IItemEnumerable<IDocument> GetCheckedOutDocs();
         IItemEnumerable<IDocument> GetCheckedOutDocs(IOperationContext context);
+
+        /// <summary>
+        /// Gets a CMIS object from the session cache. If the object is not in the cache or the cache is 
+        /// turned off per default <see cref="DotCMIS.Client.IOperationContext"/>, it will load the object 
+        /// from the repository and puts it into the cache.
+        /// </summary>
+        /// <param name="objectId">the object id</param>
         ICmisObject GetObject(IObjectId objectId);
         ICmisObject GetObject(IObjectId objectId, IOperationContext context);
+
+        /// <summary>
+        /// Gets a CMIS object from the session cache. If the object is not in the cache or the cache is 
+        /// turned off per default <see cref="DotCMIS.Client.IOperationContext"/>, it will load the object 
+        /// from the repository and puts it into the cache.
+        /// </summary>
+        /// <param name="objectId">the object id</param>
+        ICmisObject GetObject(string objectId);
+        ICmisObject GetObject(string objectId, IOperationContext context);
+
+        /// <summary>
+        /// Gets a CMIS object from the session cache. If the object is not in the cache or the cache is 
+        /// turned off per default <see cref="DotCMIS.Client.IOperationContext"/>, it will load the object
+        /// from the repository and puts it into the cache.
+        /// </summary>
+        /// <param name="path">the path to the object</param>
         ICmisObject GetObjectByPath(string path);
         ICmisObject GetObjectByPath(string path, IOperationContext context);
 

Modified: chemistry/dotcmis/trunk/DotCMIS/const.cs
URL: http://svn.apache.org/viewvc/chemistry/dotcmis/trunk/DotCMIS/const.cs?rev=1082138&r1=1082137&r2=1082138&view=diff
==============================================================================
--- chemistry/dotcmis/trunk/DotCMIS/const.cs (original)
+++ chemistry/dotcmis/trunk/DotCMIS/const.cs Wed Mar 16 12:31:27 2011
@@ -50,6 +50,8 @@ namespace DotCMIS
         public const string WebServicesPolicyService = "org.apache.chemistry.dotcmis.binding.webservices.PolicyService";
         public const string WebServicesAclService = "org.apache.chemistry.dotcmis.binding.webservices.ACLService";
 
+        public const string WebServicesWCFBinding = "org.apache.chemistry.dotcmis.binding.webservices.wcfbinding";
+
         // authentication provider
         public const string AuthenticationProviderClass = "org.apache.chemistry.dotcmis.binding.auth.classname";