/// <summary>
        /// Gets the HTTP response.
        /// </summary>
        /// <returns>The response.</returns>
        public override IOpenSearchResponse GetResponse()
        {
            try {
                Stopwatch sw = Stopwatch.StartNew();
                FileStream fs = new FileStream(this.OpenSearchUrl.ToString().Replace("file://",""),FileMode.Open);
                byte[] fileBytes= new byte[fs.Length];
                fs.Read(fileBytes, 0, fileBytes.Length);
                fs.Close();
                MemoryOpenSearchResponse response = new MemoryOpenSearchResponse(fileBytes, ContentType);
                sw.Stop();

                return response;

            } catch (Exception e) {
                throw new Exception("Unknown error during query at " + this.OpenSearchUrl, e);
            }
        }
예제 #2
0
        public BulkOperationsResponse Ingest(IOpenSearchableElasticType type, IHttpRequest request)
        {
            OpenSearchEngine ose = type.GetOpenSearchEngine(new NameValueCollection());

            IOpenSearchEngineExtension osee = ose.GetExtensionByContentTypeAbility(request.ContentType);

            if (osee == null)
            {
                throw new NotImplementedException(string.Format("No OpenSearch extension found for reading {0}", Request.ContentType));
            }

            MemoryOpenSearchResponse payload = new MemoryOpenSearchResponse(request.GetRawBody(), request.ContentType);

            IOpenSearchResultCollection results = osee.ReadNative(payload);

            return(Ingest(type, results));
        }
예제 #3
0
        public BulkOperationsResponse Ingest(IOpenSearchableElasticType type, IHttpRequest request)
        {
            OpenSearchEngine ose = type.GetOpenSearchEngine(new NameValueCollection());

            IOpenSearchEngineExtension osee = ose.GetExtensionByContentTypeAbility(request.ContentType);
            if (osee == null)
                throw new NotImplementedException(string.Format("No OpenSearch extension found for reading {0}", Request.ContentType));

            MemoryOpenSearchResponse payload = new MemoryOpenSearchResponse(request.GetRawBody(), request.ContentType);

            IOpenSearchResultCollection results = osee.ReadNative(payload);

            return Ingest(type, results);
        }
 public override IOpenSearchResponse GetResponse()
 {
     memStream.Seek(0, SeekOrigin.Begin);
     MemoryOpenSearchResponse mosr = new MemoryOpenSearchResponse(memStream.ToArray(), ContentType);
     mosr.Validity = this.ResponseValidity.Ticks == 0 ? mosr.Validity : this.ResponseValidity;
     return mosr;
 }
        /// <summary>
        /// Gets the HTTP response.
        /// </summary>
        /// <returns>The response.</returns>
        public override IOpenSearchResponse GetResponse()
        {
            int retry = 2;

            while (retry >= 0) {
                try {
                    Stopwatch sw = Stopwatch.StartNew();
                    byte[] data;
                    MemoryOpenSearchResponse response;

                    HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(this.OpenSearchUrl);

                    if (contentType != null) {
                        ((HttpWebRequest)httpWebRequest).Accept = contentType;
                    }
                    httpWebRequest.Timeout = timeOut;

                    log.DebugFormat("Querying {0}", this.OpenSearchUrl);

                    HttpWebResponse webResponse = (HttpWebResponse)httpWebRequest.GetResponse();

                    using (var ms = new MemoryStream()) {
                        webResponse.GetResponseStream().CopyTo(ms);
                        ms.Flush();
                        data = ms.ToArray();
                    }

                    response = new MemoryOpenSearchResponse(data, webResponse.ContentType, sw.Elapsed);

                    webResponse.Close();
                    webResponse.Dispose();

                    sw.Stop();
                    return response;

                } catch (WebException e) {
                    if (e.Status == WebExceptionStatus.Timeout)
                        throw new TimeoutException(String.Format("Search Request {0} has timed out", this.OpenSearchUrl), e);
                    retry--;
                    if (retry > 0) {
                        Thread.Sleep(1000);
                        continue;
                    }
                    throw e;
                } catch (Exception e) {
                    throw new Exception("Unknown error during query at " + this.OpenSearchUrl, e);
                }
            }

            throw new Exception("Unknown error during query at " + this.OpenSearchUrl);
        }