示例#1
0
        /// <summary>
        /// Generates the service document for Sword service.
        /// </summary>
        /// <param name="context">Object of HttpContext containing the request information.</param>
        /// <returns>String containing the service document.</returns>
        public string GetServiceDocument(HttpContext context)
        {
            ServiceDocument serviceDocument = base.GetServiceDocument(context, base.BaseUri);

            // Do some SWORD specific processing here.
            // Add <sword:level>0</sword:level> element.
            serviceDocument.ElementExtensions.Add(SwordConstants.SwordLevel,
                                                  SwordConstants.SwordNamespace,
                                                  SwordConstants.SwordLevelValue);

            return(AtomPubGetProcessor.GetServiceDocument(serviceDocument));
        }
示例#2
0
        /// <summary>
        /// Processes the request sent to the specified AtomPub Uri.
        /// </summary>
        /// <param name="context">An instance of HttpContext containing the request details.</param>
        /// <param name="statusCode">The HttpStatusCode indicating status of the request.</param>
        /// <returns>A string containing the response to the request.</returns>
        /// <remarks>This method assumes that the request is already validated.</remarks>
        public string ProcessRequest(HttpContext context, out HttpStatusCode statusCode)
        {
            var unknownContentHeaders = context.Request.Headers.AllKeys
                                        .Intersect(AtomPubHelper.UnknownContentHeaders);

            if (0 < unknownContentHeaders.Count())
            {
                statusCode = HttpStatusCode.NotImplemented;
                return(string.Format(CultureInfo.InvariantCulture,
                                     Resources.ATOMPUB_UNKNOWN_CONTENT_HEADER,
                                     unknownContentHeaders.First()));
            }

            HttpRequestProcessor processor = null;

            switch (context.Request.RequestType)
            {
            case PlatformConstants.GetRequestType:
                processor = new AtomPubGetProcessor();
                break;

            case PlatformConstants.PostRequestType:
                processor = new AtomPubPostProcessor();
                break;

            case PlatformConstants.PutRequestType:
                processor = new AtomPubPutProcessor();
                break;

            case PlatformConstants.DeleteRequestType:
                processor = new AtomPubDeleteProcessor();
                break;

            default:
                processor = null;
                break;
            }

            if (null == processor)
            {
                statusCode = HttpStatusCode.NotImplemented;
                return(Properties.Resources.ATOMPUB_UNSUPPORTED_REQUEST);
            }

            try
            {
                bool   isValidrequest = false;
                string responseString = string.Empty;

                isValidrequest = processor.ValidateRequest(context, out responseString);

                if (isValidrequest)
                {
                    return(processor.ProcessRequest(context, out statusCode));
                }
                else
                {
                    statusCode = HttpStatusCode.BadRequest;
                    return(responseString);
                }
            }
            catch (UnauthorizedException ex)
            {
                statusCode = HttpStatusCode.Forbidden;
                return(ex.Message);
            }
        }