Example #1
0
        protected IHttpRealProxy CreateHttpRealProxy(Type objectType, string url, string contentType, IDictionary options = null)
        {
            if (contentType == null)
            {
                contentType = string.Empty;
            }
            IHttpRealProxy proxy   = null;
            var            setting = this.handlers.FirstOrDefault(x => url.StartsWith(x.Name, StringComparison.InvariantCultureIgnoreCase));

            if (!string.IsNullOrEmpty(setting?.TypeName))
            {
                var typeName = setting.TypeName;
                proxy = this.ObjectService.CreateObject(typeName, objectType, url, contentType) as IHttpRealProxy;
                if (proxy == null)
                {
                    typeName = this.ObjectService.GetTypeName(typeName);
                    proxy    = TypeHelper.CreateObject(typeName, typeof(IHttpRealProxy), false, objectType, url, contentType) as IHttpRealProxy;
                }
            }
            if (proxy == null)
            {
                proxy = this.ObjectService.CreateObject <IHttpRealProxy>(objectType, url, contentType);
            }
            proxy.Init(this, options);
            return(proxy);
        }
Example #2
0
        protected IHttpRealProxy CreateHttpRealProxy(Type objectType, string url, string contentType, IDictionary options = null)
        {
            if (contentType == null)
            {
                contentType = string.Empty;
            }
            IHttpRealProxy proxy = null;
            //根据Url前缀选择相应的代理,比如前缀esb://
            var attribute = this.handlers.FirstOrDefault(x => url.StartsWith(x.Name, StringComparison.InvariantCultureIgnoreCase));

            if (attribute != null)
            {
                proxy = this.ObjectService.CreateObject(attribute.OwnerType, objectType, url, contentType) as IHttpRealProxy;
            }
            //未找到,则使用缺省的
            if (proxy == null)
            {
                proxy = this.ObjectService.CreateObject <IHttpRealProxy>(objectType, url, contentType);
            }
            proxy?.Init(this, options);
            return(proxy);
        }