Exemple #1
0
        public static void AddPluginsFromAssembly(this IAppHost appHost, params Assembly[] assembliesWithPlugins)
        {
            foreach (Assembly assembly in assembliesWithPlugins)
            {
                var pluginTypes =
                    from t in assembly.GetExportedTypes()
                    where t.GetInterfaces().Any(x => x == typeof(IPlugin))
                    select t;

                foreach (var pluginType in pluginTypes)
                {
                    try
                    {
                        var plugin = pluginType.CreateInstance() as IPlugin;
                        if (plugin != null)
                        {
                            EndpointHost.AddPlugin(plugin);
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Fatal("Error adding new Plugin " + pluginType.Name, ex, new Dictionary <string, string>()
                        {
                            { "ErrorCode", "FXD300007" }
                        });
                    }
                }
            }
        }
Exemple #2
0
        protected override bool PreProcessRequestAsync(IHttpRequest httpReq, IHttpResponse httpRes, string operationName, out object requestObject)
        {
            requestObject = null;

            if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes))
            {
                return(true);
            }

            var restPath = GetRestPath(httpReq.HttpMethod, httpReq.ServicePath, httpReq.PathInfo);

            if (restPath == null)
            {
                throw new NotSupportedException("No RestPath found for: " + httpReq.HttpMethod + " " + httpReq.PathInfo);
            }

            operationName = restPath.OperationName;

            if (ResponseContentType != null)
            {
                httpReq.ResponseContentType = ResponseContentType;
            }

            EndpointHost.Config.AssertContentType(httpReq.ResponseContentType);

            var request = GetRequest(httpReq, restPath);

            httpReq.RequestObject = requestObject = request;
            if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request, operationName))
            {
                return(true);
            }

            return(false);
        }
Exemple #3
0
        protected override bool PreProcessRequestAsync(IHttpRequest httpReq, IHttpResponse httpRes, string operationName, out object requestObject)
        {
            requestObject = null;

            EndpointHost.Config.AssertFeatures(format);

            if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes))
            {
                return(true);
            }

            httpReq.ResponseContentType = this.HandlerContentType;

            if (httpReq.HttpMethod != HttpMethods.Post)
            {
                throw new NotSupportedException("SOAP handler only supports HTTP Post method");
            }

            var request = CreateRequest(httpReq, operationName);

            httpReq.RequestObject = requestObject = request;
            if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request, operationName))
            {
                return(true);
            }

            return(false);
        }
Exemple #4
0
        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            try
            {
                EndpointHost.Config.AssertFeatures(format);

                if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes))
                {
                    return;
                }

                httpReq.ResponseContentType = this.HandlerContentType;

                if (httpReq.HttpMethod != HttpMethods.Post)
                {
                    throw new NotSupportedException("SOAP handler only supports HTTP Post method");
                }

                var request = CreateRequest(httpReq, operationName);
                httpReq.RequestObject = request;
                if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request, operationName))
                {
                    return;
                }

                var response = GetResponse(httpReq, httpRes, request);
                if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, response, operationName))
                {
                    return;
                }

                httpRes.WriteToResponse(httpReq, response, NO_XML_DECL_SERIALIZER, SOAP_ENVELOPE_PREFIX, SOAP_ENVELOPE_SUFFIX);
            }
            catch (Exception ex)
            {
                if (!EndpointHost.Config.WriteErrorsToResponse)
                {
                    throw;
                }
                HandleException(httpReq, httpRes, operationName, ex);
            }
            finally
            {
                if (EndpointHost.PostResponseFilters.Count > 0)
                {
                    EndpointHost.ApplyPostResponseFilters(new PostResponseFilterArgs()
                    {
                        ExecutionResult = httpRes.ExecutionResult,
                        ServicePath     = httpReq.ServicePath,
                        OperationName   = httpReq.OperationName,
                        RequestDeserializeTimeInMilliseconds = httpReq.DeserializationTimeInMillis,
                        ResponseSerializeTimeInMilliseconds  = httpRes.SerializationTimeInMillis
                    });
                }
            }
        }
Exemple #5
0
        protected override bool PostProcessRequestAsync(IHttpRequest httpReq, IHttpResponse httpRes, string operationName, object responseObject)
        {
            if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, responseObject, operationName))
            {
                return(true);
            }

            httpRes.WriteToResponse(httpReq, responseObject, NO_XML_DECL_SERIALIZER, SOAP_ENVELOPE_PREFIX, SOAP_ENVELOPE_SUFFIX);
            return(true);
        }
Exemple #6
0
        protected override bool PostProcessRequestAsync(IHttpRequest httpReq, IHttpResponse httpRes, string operationName, object responseObject)
        {
            var callback = httpReq.QueryString["callback"];
            var doJsonp  = EndpointHost.Config.AllowJsonpRequests && !string.IsNullOrEmpty(callback);

            if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, responseObject, operationName))
            {
                return(true);
            }

            if (doJsonp)
            {
                httpRes.WriteToResponse(httpReq, responseObject, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
                return(true);
            }

            return(false);
        }
Exemple #7
0
        protected override bool PreProcessRequestAsync(IHttpRequest httpReq, IHttpResponse httpRes, string operationName, out object requestObject)
        {
            requestObject = null;

            EndpointHost.Config.AssertFeatures(format);

            if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes))
            {
                return(true);
            }

            httpReq.ResponseContentType = httpReq.GetQueryStringContentType() ?? this.HandlerContentType;

            var request = CreateRequest(httpReq, operationName);

            httpReq.RequestObject = requestObject = request;
            if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request, operationName))
            {
                return(true);
            }

            return(false);
        }
Exemple #8
0
        protected override bool PostProcessRequestAsync(IHttpRequest httpReq, IHttpResponse httpRes, string operationName, object responseObject)
        {
            var callback = httpReq.GetJsonpCallback();
            var doJsonp  = EndpointHost.Config.AllowJsonpRequests && !string.IsNullOrEmpty(callback);

            if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, responseObject, operationName))
            {
                return(true);
            }

            if (httpReq.ResponseContentType.Contains("jsv") && !string.IsNullOrEmpty(httpReq.QueryString["debug"]))
            {
                JsvSyncReplyHandler.WriteDebugResponse(httpRes, httpReq, responseObject);
                return(true);
            }

            if (doJsonp)
            {
                httpRes.WriteToResponse(httpReq, responseObject, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
                return(true);
            }

            return(false);
        }
Exemple #9
0
        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            try
            {
                if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes))
                {
                    return;
                }

                var restPath = GetRestPath(httpReq.HttpMethod, httpReq.ServicePath, httpReq.PathInfo);
                if (restPath == null)
                {
                    throw new NotSupportedException("No RestPath found for: " + httpReq.HttpMethod + " " + httpReq.PathInfo);
                }

                operationName = restPath.OperationName;

                var callback = httpReq.GetJsonpCallback();
                var doJsonp  = EndpointHost.Config.AllowJsonpRequests &&
                               !string.IsNullOrEmpty(callback);

                if (ResponseContentType != null)
                {
                    httpReq.ResponseContentType = ResponseContentType;
                }

                EndpointHost.Config.AssertContentType(httpReq.ResponseContentType);

                var request = GetRequest(httpReq, restPath);
                httpReq.RequestObject = request;
                if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request, operationName))
                {
                    return;
                }

                var response = GetResponse(httpReq, httpRes, request);
                if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, response, operationName))
                {
                    return;
                }

                if (httpReq.ResponseContentType.Contains("jsv") && !string.IsNullOrEmpty(httpReq.QueryString["debug"]))
                {
                    JsvSyncReplyHandler.WriteDebugResponse(httpRes, httpReq, response);
                    return;
                }

                if (doJsonp)
                {
                    httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
                }
                else
                {
                    httpRes.WriteToResponse(httpReq, response);
                }
            }
            catch (Exception ex)
            {
                if (!EndpointHost.Config.WriteErrorsToResponse)
                {
                    throw;
                }
                HandleException(httpReq, httpRes, operationName, ex);
            }
            finally
            {
                if (EndpointHost.PostResponseFilters.Count > 0)
                {
                    EndpointHost.ApplyPostResponseFilters(new PostResponseFilterArgs()
                    {
                        ExecutionResult = httpRes.ExecutionResult,
                        ServicePath     = httpReq.ServicePath,
                        OperationName   = httpReq.OperationName,
                        RequestDeserializeTimeInMilliseconds = httpReq.DeserializationTimeInMillis,
                        ResponseSerializeTimeInMilliseconds  = httpRes.SerializationTimeInMillis
                    });
                }
            }
        }
Exemple #10
0
 protected AppHostBase(string serviceName, params Type[] serviceTypes)
 {
     EndpointHost.ConfigureHost(this, CreateServiceManager(serviceName, serviceTypes));
     AfterInitCallbacks = new List <Action <IAppHost> >();
     OnDisposeCallbacks = new List <Action <IAppHost> >();
 }
Exemple #11
0
 /// <summary>
 /// 配置EndpointHost
 /// 根据传入的Assembly 解析
 /// </summary>
 /// <param name="assembliesWithServices"></param>
 protected AppHostBase(params Assembly[] assembliesWithServices)
 {
     EndpointHost.ConfigureHost(this, CreateServiceManager(assembliesWithServices));
     AfterInitCallbacks = new List <Action <IAppHost> >();
     OnDisposeCallbacks = new List <Action <IAppHost> >();
 }
Exemple #12
0
        public void Init()
        {
            try
            {
                log.Info("SOA 2.0 Service Initialization", "SOA 2.0 Service is initializing...",
                         new Dictionary <string, string>
                {
                    { "StartUp", "SOA2.0" },
                    { "ErrorCode", "FXD300049" }
                });

                if (Instance != null)
                {
                    throw new InvalidDataException("AppHostBase.Instance has already been set");
                }

                Instance = this;

                var serviceManager = EndpointHost.Config.ServiceManager;
                if (serviceManager != null)
                {
                    serviceManager.Init();//服务初始化 route controller action
                    Configure(EndpointHost.Config.ServiceManager.Container);
                }
                else
                {
                    Configure(null);
                }

                EndpointHost.AfterInit();

                // periodically send metrics
                var mTimer = new Timer();
                mTimer.Interval  = DEFAULT_METRIC_SENDING_INTERVAL;
                mTimer.Enabled   = true;
                mTimer.AutoReset = true;
                mTimer.Elapsed  += new ElapsedEventHandler(sendMetrics);

                StartUpTime = DateTime.Now;

                //序列化日期
                JsConfig.UseStandardLongDateTime();

                log.Info("SOA 2.0 Service Initialization", "SOA 2.0 Service has been initialized.",
                         new Dictionary <string, string>
                {
                    { "StartUp", "SOA2.0" },
                    { "ErrorCode", "FXD300050" }
                });
            }
            catch (Exception ex)
            {
                log.Error("Error occurred while initializing SOA 2.0 Service", ex,
                          new Dictionary <string, string>
                {
                    { "StartUp", "SOA2.0" },
                    { "ErrorCode", "FXD300086" }
                });
                throw;
            }
        }
Exemple #13
0
        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            try
            {
                EndpointHost.Config.AssertFeatures(format);

                if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes))
                {
                    return;
                }

                httpReq.ResponseContentType = httpReq.GetQueryStringContentType() ?? this.HandlerContentType;
                var callback = httpReq.QueryString["callback"];
                var doJsonp  = EndpointHost.Config.AllowJsonpRequests &&
                               !string.IsNullOrEmpty(callback);

                var request = CreateRequest(httpReq, operationName);
                httpReq.RequestObject = request;
                if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request, operationName))
                {
                    return;
                }

                var response = GetResponse(httpReq, httpRes, request);
                if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, response, operationName))
                {
                    return;
                }

                if (doJsonp)
                {
                    httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
                }
                else
                {
                    httpRes.WriteToResponse(httpReq, response);
                }
            }
            catch (Exception ex)
            {
                if (!EndpointHost.Config.WriteErrorsToResponse)
                {
                    throw;
                }
                HandleException(httpReq, httpRes, operationName, ex);
            }
            finally
            {
                if (EndpointHost.PostResponseFilters.Count > 0)
                {
                    EndpointHost.ApplyPostResponseFilters(new PostResponseFilterArgs()
                    {
                        ExecutionResult = httpRes.ExecutionResult,
                        ServicePath     = httpReq.ServicePath,
                        OperationName   = httpReq.OperationName,
                        RequestDeserializeTimeInMilliseconds = httpReq.DeserializationTimeInMillis,
                        ResponseSerializeTimeInMilliseconds  = httpRes.SerializationTimeInMillis
                    });
                }
            }
        }