示例#1
0
        private static EndpointHandlerBase GetHandler(string httpMethod, string pathInfo)
        {
            var httpHandler = SStackHttpHandlerFactory.GetHandlerForPathInfo(httpMethod, pathInfo, pathInfo, null) as EndpointHandlerBase;

            if (httpHandler == null)
            {
                throw new NotSupportedException(pathInfo);
            }
            return(httpHandler);
        }
示例#2
0
        public static string GetBaseUrl(this IHttpRequest httpReq)
        {
            var baseUrl = SStackHttpHandlerFactory.GetBaseUrl();

            if (baseUrl != null)
            {
                return(baseUrl);
            }

            var handlerPath = EndpointHost.Config.SStackHandlerFactoryPath;

            if (handlerPath != null)
            {
                var pos = httpReq.AbsoluteUri.IndexOf(handlerPath, StringComparison.InvariantCultureIgnoreCase);
                if (pos >= 0)
                {
                    baseUrl = httpReq.AbsoluteUri.Substring(0, pos + handlerPath.Length);
                    return(baseUrl);
                }
                return("/" + handlerPath);
            }

            return("/"); //Can't infer Absolute Uri, fallback to root relative path
        }
示例#3
0
        private IHttpHandler GetHandlerForPathParts(string[] pathParts)
        {
            var pathController = string.Intern(pathParts[0].ToLower());

            if (pathParts.Length == 1)
            {
                if (pathController == "metadata")
                {
                    return(new IndexMetadataHandler());
                }

                return(null);
            }

            var pathAction = string.Intern(pathParts[1].ToLower());

            if (pathAction == "wsdl")
            {
                if (pathController == "soap11")
                {
                    return(new Soap11WsdlMetadataHandler());
                }
                if (pathController == "soap12")
                {
                    return(new Soap12WsdlMetadataHandler());
                }
            }

            if (pathAction != "metadata")
            {
                return(null);
            }

            switch (pathController)
            {
            case "json":
                return(new JsonMetadataHandler());

            case "xml":
                return(new XmlMetadataHandler());

            case "jsv":
                return(new JsvMetadataHandler());

            case "soap11":
                return(new Soap11MetadataHandler());

            case "soap12":
                return(new Soap12MetadataHandler());

            case "types":

                if (EndpointHost.Config == null ||
                    EndpointHost.Config.MetadataTypesConfig == null)
                {
                    return(null);
                }

                if (EndpointHost.Config.MetadataTypesConfig.BaseUrl == null)
                {
                    EndpointHost.Config.MetadataTypesConfig.BaseUrl = SStackHttpHandlerFactory.GetBaseUrl();
                }

                return(new MetadataTypesHandler {
                    Config = EndpointHost.AppHost.Config.MetadataTypesConfig
                });

            case "operations":

                return(new ActionHandler((httpReq, httpRes) =>
                                         EndpointHost.Config.HasAccessToMetadata(httpReq, httpRes)
                            ? EndpointHost.Metadata.GetOperationDtos()
                            : null, "Operations"));

            default:
                string contentType;
                if (EndpointHost.ContentTypeFilter
                    .ContentTypeFormats.TryGetValue(pathController, out contentType))
                {
                    var format = Common.Web.ContentType.GetContentFormat(contentType);
                    return(new CustomMetadataHandler(contentType, format));
                }
                break;
            }
            return(null);
        }