public FileContentRepository(IContentPathProvider contentPathProvider) { _contentDirectoryPath = contentPathProvider.ContentDirectoryPath.EndsWith(Path.DirectorySeparatorChar.ToString()) ? contentPathProvider.ContentDirectoryPath : contentPathProvider.ContentDirectoryPath + Path.DirectorySeparatorChar; _contentDirectoryUri = new Uri(_contentDirectoryPath); _fileExtension = contentPathProvider.FileExtension; _contentSerializerFactory = EncelApplication.Configuration.ContentSerializerFactory; }
protected IContentSerializer GetSerializer(IRequest request, IContentSerializerFactory serializerFactory) { string serializerType = request.UrlBuilder.Query.Get(CommonParams.WT); if (serializerType == null && request.Header != null && request.Header.ContainsKey("content-type")) { serializerType = request.Header["content-type"]; } return(serializerFactory.GetContentSerializer(serializerType)); }
public MockSolrServerHandler(IContentSerializerFactory contentSerializerFactory = null, ICacheHandler cacheHandler = null) { baseUriBuilder = new SolrUriBuilder(null ?? "http://127.0.0.1:20440/solr/"); RequestHandler = new MockConnectionHandler(); SerializerFactory = contentSerializerFactory ?? new ContentSerializerFactory(); Cache = cacheHandler; DefaultCore = "MockCore"; Cores = new List <string> { DefaultCore }; IsReady = true; }
/// <summary> /// Transfers the Request to the Solr Server and returns it's Response. /// </summary> /// <typeparam name="T">IResponse type, which handles the response.</typeparam> /// <param name="request">IRequest implementation, which handles the required date for the Request.</param> /// <exception cref="MizoreConnectionExcpetion">Thrown when a problem with the Connection to the server occurs</exception> /// <returns>IResponse implementation for the Response</returns> public T Request <T>(IRequest request, IContentSerializerFactory serializerFactory) where T : IResponse { if (request == null) { throw new ArgumentNullException("request"); } if (serializerFactory == null) { throw new ArgumentNullException("serializerFactory"); } //if (request.Server.Cache != null) // ETag = request.Server.Cache.GetETag(request.CacheKey); try { var webRequest = CreateWebRequest(request, serializerFactory); var webResponse = webRequest.GetResponse(); Stream ms = null; using (var responseStream = webResponse.GetResponseStream()) { if (responseStream != null) { ms = new MemoryStream(); responseStream.CopyTo(ms); ms.Position = 0; } } var serializer = serializerFactory.GetContentSerializer(webResponse.ContentType); if (serializer == null) { throw new InvalidOperationException("No Matching ContentSerializer found for type " + webResponse.ContentType); } var nl = serializer.Deserialize(ms); return((T)request.GetResponse(nl)); } catch (WebException we) { //TODO: JIRA MIZORE-7: Http exceptionhandling //TODO: JIRA MIZORE-9: Cache handling //TODO-LOW: JIRA MIZORE-16: Solr errorpage parsing and own exception handling throw new MizoreConnectionException(request, "Connection exception occured in HttpWebRequestHandler.", we); } catch (Exception e) { //TODO: generic error handling throw new MizoreConnectionException(request, e); } }
public T Request <T>(IRequest request, IContentSerializerFactory serializerFactory) where T : IResponse { if (request == null) { throw new ArgumentNullException("request"); } if (request.UrlBuilder == null) { throw new ArgumentException("Request doesn't have a UrlBuilder", "request"); } var wt = request.UrlBuilder.Query.Get(CommonParams.WT); if (wt == null) { throw new ArgumentException("UrlBuilder doesn't have a WT set, it's required for testing!", "request"); } if (serializerFactory == null) { throw new ArgumentNullException("serializerFactory"); } var fileSuffix = GetSuffix(request); Stream ms = null; using (var responseStream = GetFileStream(request.UrlBuilder, fileSuffix)) { if (responseStream != null) { ms = new MemoryStream(); responseStream.CopyTo(ms); ms.Position = 0; } } var contentType = GetContentType(request.UrlBuilder); var serializer = serializerFactory.GetContentSerializer(contentType); if (serializer == null) { throw new InvalidOperationException("No Matching ContentSerializer found for type " + contentType); } var nl = serializer.Deserialize(ms); return((T)request.GetResponse(nl)); }
protected virtual HttpWebRequest CreateWebRequest(IRequest request, IContentSerializerFactory serializerFactory) { var serializer = GetSerializer(request, serializerFactory); var wt = request.UrlBuilder.Query.Get(CommonParams.WT); if (wt == null) { request.UrlBuilder.Query.Add(CommonParams.WT, serializer.WT); } var webRequest = (HttpWebRequest)WebRequest.Create(request.UrlBuilder.Uri); webRequest.Method = request.Method.ToString("G"); if (request.Method == RequestMethod.GET) { webRequest.Accept = serializer.ContentType; } else { webRequest.ContentType = serializer.ContentType; } //Default settings webRequest.KeepAlive = true; webRequest.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip; webRequest.UserAgent = "Mizore (.NET solr library)"; //TODO-LOW: ServicePoint.Expect100Continue for post values -> true or false? which is faster in the solr case? if (request.Content != null) { using (var requestStream = webRequest.GetRequestStream()) { serializer.Serialize(request.Content, requestStream); } } return(webRequest); }
public HttpSolrServer(string url, IContentSerializerFactory contentSerializerFactory = null, ICacheHandler cacheHandler = null, bool ignoreStatusCheck = false) { //Argument Validation if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentNullException("url"); } if (url.EndsWith("/")) { url = url.TrimEnd('/'); } Uri solrUri; if (!Uri.TryCreate(url, UriKind.Absolute, out solrUri)) { throw new ArgumentException("the URL is invalid", "url"); } RequestHandler = new HttpWebRequestHandler(); if (!RequestHandler.IsUriSupported(solrUri)) { throw new ArgumentException("the URL is invalid", "url"); } //Initialization RecheckInterval = new TimeSpan(0, 1, 0); baseUriBuilder = new SolrUriBuilder(solrUri); SerializerFactory = contentSerializerFactory ?? new ContentSerializerFactory(); DataMapping = new DataMappingCollection(); Cache = cacheHandler ?? null; IsReady = true; if (ignoreStatusCheck) { _isOnline = true; } else { CheckStatus(true); } }
public RestHttpClient(IContentSerializerFactory contentSerializerFactory) { _contentSerializerFactory = contentSerializerFactory; }