コード例 #1
0
        /// <summary>
        /// The build query bean.
        /// </summary>
        /// <param name="flowRef">
        /// The flow ref.
        /// </param>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <param name="providerRef">
        /// The provider ref.
        /// </param>
        /// <param name="queryParameters">
        /// The query parameters.
        /// </param>
        /// <returns>
        /// The <see cref="IRestDataQuery"/>.
        /// </returns>
        /// <exception cref="WebFaultException{T}">
        /// </exception>
        private IRestDataQuery BuildQueryBean(string flowRef, string key, string providerRef, NameValueCollection queryParameters)
        {
            var queryString = new string[4];
            queryString[0] = "data";
            queryString[1] = flowRef;
            queryString[2] = key;
            queryString[3] = providerRef;

            IDictionary<string, string> paramsDict = HeaderUtils.GetQueryStringAsDict(queryParameters);
            IRestDataQuery restQuery;

            try
            {
                restQuery = new RESTDataQueryCore(queryString, paramsDict);
            }
            catch (SdmxException e)
            {
                Logger.Error(e.Message, e);
                throw this._faultExceptionRestBuilder.Build(e);
            }
            catch (Exception e)
            {
                Logger.Error(e.Message, e);
                throw new WebFaultException<string>(e.Message, HttpStatusCode.BadRequest);
            }

            return restQuery;
        }
コード例 #2
0
        /// <summary>
        /// Parse the specified <paramref name="query"/>.
        /// </summary>
        /// <param name="query">
        /// The REST data query.
        /// </param>
        /// <param name="beanRetrievalManager">
        /// The <c>SDMX</c> object retrieval manager.
        /// </param>
        /// <returns>
        /// The <see cref="IDataQuery"/> from <paramref name="query"/>.
        /// </returns>
        public virtual IDataQuery ParseRestQuery(string query, ISdmxObjectRetrievalManager beanRetrievalManager)
        {
            // NOTE fixed MT bug Data -> data
            if (!query.ToLower().StartsWith("data/"))
            {
                throw new SdmxSemmanticException("Expecting REST Query for Data to start with 'Data/'");
            }

            string[] split = Regex.Split(query, "\\?");

            //Everything one split[1] this point are query parameters
            IDictionary<string, string> queryParameters = new Dictionary<string, string>(StringComparer.Ordinal);
            if (split.Length > 1)
            {
                string[] queryParametersSplit = Regex.Split(split[1], "&");
                for (int i = 0; i < queryParametersSplit.Length; i++)
                {
                    string[] queryParam = Regex.Split(queryParametersSplit[i], "=");
                    if (queryParam.Length != 2)
                    {
                        throw new SdmxSemmanticException("Missing equals '=' in query parameters '" + split[i] + "'");
                    }

                    queryParameters.Add(queryParam[0], queryParam[1]);
                }
            }

            string queryPrefix = split[0];
            var dataQuery = new RESTDataQueryCore(queryPrefix.Split('/'), queryParameters);
            return new DataQueryImpl(dataQuery, beanRetrievalManager);
        }
コード例 #3
0
        public void ProcessRequest(HttpContext context) {
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;
            string restUrl = Regex.Replace(request.Url.PathAndQuery, @"^\/RestService.ashx", string.Empty);
            if (restUrl.StartsWith("/data/"))
            {
                IRestDataQuery query = new RESTDataQueryCore(restUrl);

                // get the first known Accept Header value and IDataFormat from the request
                KeyValuePair<string, IDataFormat> dataFormat = GetDataFormat(request);

                // for simplicity use the first known accept header
                response.ContentType = dataFormat.Key;
                response.AddHeader("Content-Disposition", new ContentDisposition { FileName = "data.xml", Inline = true }.ToString());
                this._dataQueryManager.ExecuteQuery(query, dataFormat.Value, response.OutputStream);

            }
            else
            {
                IRestStructureQuery query = new RESTStructureQueryCore(restUrl);
                KeyValuePair<string, IStructureFormat> format = GetStructureFormat(request);

                // for simplicity use the first known accept header
                response.ContentType = format.Key;
                response.AddHeader("Content-Disposition", new ContentDisposition { FileName = "structure.xml", Inline = true }.ToString());
                this._restStructureQueryManager.GetStructures(query, response.OutputStream, format.Value);
            }

            response.End();
        }