public CachedOpenSearchRequest(OpenSearchUrl url, IOpenSearchResponse response, NameValueCollection originalParameters, TimeSpan elapsed)
     : base(url, response.ContentType)
 {
     base.OpenSearchUrl = url;
     this.response = response;
     this.OriginalParameters = originalParameters;
 }
Beispiel #2
0
        public override OpenSearchUrl FindOpenSearchDescriptionUrlFromResponse(IOpenSearchResponse response)
        {
            if (response.ContentType == "application/json")
            {
                // TODO
                throw new NotImplementedException();
            }

            return(null);
        }
Beispiel #3
0
        public IOpenSearchResultCollection Sentinel1QcReadNative(IOpenSearchResponse response)
        {
            IOpenSearchResultCollection openSearchResultCollection = originalReadNativeFunctionToExtend(response);

            if (response.GetType() == typeof(PartialAtomSearchResponse))
            {
                throw new PartialAtomException("Attaching result to exception ", null, openSearchResultCollection);
            }

            return(openSearchResultCollection);
        }
Beispiel #4
0
 public override IOpenSearchResultCollection ReadNative(IOpenSearchResponse response)
 {
     if (response.ObjectType == typeof(byte[]))
     {
         if (response.ContentType == "application/json")
         {
             return(TransformJsonResponseToGenericJsonCollection((OpenSearchResponse <byte[]>)response));
         }
         throw new NotSupportedException("Generic Json extension does not transform OpenSearch response of contentType " + response.ContentType);
     }
     if (response.ObjectType == typeof(ISearchResponse <GenericJsonItem>))
     {
         return(GenericJsonCollection.TransformElasticSearchResponseToGenericJsonCollection((OpenSearchResponse <ISearchResponse <GenericJsonItem> >)response));
     }
     throw new InvalidOperationException("Generic Json extension does not transform OpenSearch response of type " + response.ObjectType);
 }
        // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
        private void HandleOpenSearchClientException(RequestData data, Exception clientException, IOpenSearchResponse response)
        {
            if (response.ApiCall is ApiCallDetails a)
            {
                //if original exception was not explicitly set during the pipeline
                //set it to the OpenSearchClientException we created for the bad response
                if (clientException != null && a.OriginalException == null)
                {
                    a.OriginalException = clientException;
                }
                //On .NET Core the IConnection implementation throws exceptions on bad responses
                //This causes it to behave differently to .NET FULL. We already wrapped the WebException
                //under OpenSearchServerException and it exposes way more information as part of it's
                //exception message e.g the the root cause of the server error body.
#if !DOTNETCORE
                if (a.OriginalException is WebException)
                {
                    a.OriginalException = clientException;
                }
#endif
            }

            Settings.OnRequestCompleted?.Invoke(response.ApiCall);
            if (data != null && (clientException != null && data.ThrowExceptions))
            {
                throw clientException;
            }
        }
Beispiel #6
0
 private static void ThrowBadAuthPipelineExceptionWhenNeeded(IApiCallDetails details, IOpenSearchResponse response = null)
 {
     if (details?.HttpStatusCode == 401)
     {
         throw new PipelineException(PipelineFailure.BadAuthentication, details.OriginalException)
               {
                   Response = response,
                   ApiCall  = details,
               }
     }
     ;
 }
        /// <summary>
        /// Applies the post search filters.
        /// </summary>
        /// <param name="request">Request.</param>
        /// <param name="response">Response.</param>
        private void ApplyPostSearchFilters(OpenSearchRequest request, ref IOpenSearchResponse response)
        {
            foreach (PostFilterAction filter in postFilters) {

                filter.Invoke(request, ref response);

            }
        }
        void ApplyOpenSearchElements(ref IOpenSearchResultCollection newResults, OpenSearchRequest request, IOpenSearchResponse response)
        {
            foreach (SyndicationElementExtension ext in newResults.ElementExtensions.ToArray()) {
                if (ext.OuterName == "startIndex" && ext.OuterNamespace == "http://a9.com/-/spec/opensearch/1.1/")
                    newResults.ElementExtensions.Remove(ext);
                if (ext.OuterName == "itemsPerPage" && ext.OuterNamespace == "http://a9.com/-/spec/opensearch/1.1/")
                    newResults.ElementExtensions.Remove(ext);
                if (ext.OuterName == "Query" && ext.OuterNamespace == "http://a9.com/-/spec/opensearch/1.1/")
                    newResults.ElementExtensions.Remove(ext);
            }
            newResults.ElementExtensions.Add("startIndex", "http://a9.com/-/spec/opensearch/1.1/", request.OpenSearchUrl.IndexOffset);
            newResults.ElementExtensions.Add("itemsPerPage", "http://a9.com/-/spec/opensearch/1.1/", request.OpenSearchUrl.Count);

            XElement query = new XElement(XName.Get("Query", "http://a9.com/-/spec/opensearch/1.1/"));
            OpenSearchDescription osd = null;
            if (response.Entity is IProxiedOpenSearchable)
                osd = ((IProxiedOpenSearchable)response.Entity).GetProxyOpenSearchDescription();
            else
                osd = response.Entity.GetOpenSearchDescription();
            foreach (var ns in osd.ExtraNamespace.ToArray()) {
                if (string.IsNullOrEmpty(ns.Name) || ns.Namespace == "http://www.w3.org/2001/XMLSchema" || ns.Namespace == "http://www.w3.org/2001/XMLSchema-instance" || ns.Namespace == XNamespace.Xmlns.NamespaceName)
                    continue;
                query.Add(new XAttribute(XNamespace.Xmlns + ns.Name, ns.Namespace));
            }
            var osUrl = OpenSearchFactory.GetOpenSearchUrlByType(osd, request.ContentType);
            var osparams = OpenSearchFactory.GetOpenSearchParameters(osUrl);
            foreach (var key in request.Parameters.AllKeys) {
                string osparam = OpenSearchFactory.GetParamNameFromId(osparams, key);
                if (!string.IsNullOrEmpty(osparam)) {
                    try {
                        if (osparam.Contains(":"))
                            query.Add(new XAttribute(XName.Get(osparam.Split(':')[1], osd.ExtraNamespace.ToArray().First(n => n.Name == osparam.Split(':')[0]).Namespace), request.Parameters[key]));
                        else {
                            query.Add(new XAttribute(XName.Get(osparam, osd.ExtraNamespace.ToArray().First(n => n.Name == "os").Namespace), request.Parameters[key]));
                        }
                    } catch {
                    }
                }
            }
            newResults.ElementExtensions.Add(query.CreateReader());
        }
Beispiel #9
0
 private Exception ThrowOnBadBulk(IOpenSearchResponse response, string message)
 {
     _incrementFailed();
     _partitionedBulkRequest.BackPressure?.Release();
     return(Throw(message, response.ApiCall));
 }
 public OpenSearchResponseCacheItem(OpenSearchUrl url, IOpenSearchResponse clonedResponse)
     : base(url.ToString(),clonedResponse)
 {
     created = DateTime.UtcNow;
 }
        /// <summary>
        /// Caches the response.
        /// </summary>
        /// <param name="request">Request.</param>
        /// <param name="response">Response.</param>
        public void CacheResponse(OpenSearchRequest request, ref IOpenSearchResponse response)
        {
            CacheItem it = cache.GetCacheItem(request.OpenSearchUrl.ToString());

                if (it != null) return;

            if (response.Entity != null && !response.Entity.CanCache)
                return;

            var clonedResponse = response.CloneForCache();

            if (clonedResponse == null)
                throw new InvalidOperationException(string.Format("Response cannot be cached because it is null. Check the CloneForCache of the response [{0}] or the CanCache() method of the Opensearchable [{1}] requested", response.GetType(), response.Entity.GetType()));

            OpenSearchResponseCacheItem item = new OpenSearchResponseCacheItem(request.OpenSearchUrl, clonedResponse);
            CacheItemPolicy policy = this.CreatePolicy(item, request);
            log.DebugFormat("OpenSearch Cache [store] {0}", request.OpenSearchUrl);

            cache.Set(item, policy);

            log.DebugFormat("OpenSearch Cache [count] {0}", cache.GetCount());
        }