private static IApiDocumentation GetApiDocumentation(HttpUrl url) { string contentType; var responseStream = new UnclosableStream(GetResponse(Method, url, out contentType)); var container = UrsaConfigurationSection.InitializeComponentProvider(); container.Register<IHttpServerConfiguration>(new StaticHttpServerConfiguration((Uri)url)); var headers = new HeaderCollection(); if (!String.IsNullOrEmpty(contentType)) { ((IDictionary<string, string>)headers)[Header.Accept] = contentType; ((IDictionary<string, string>)headers)[Header.ContentType] = contentType; } var apiDocumentationId = url.WithFragment(String.Empty); var httpRequest = new RequestInfo(Verb.Parse(Method), apiDocumentationId, responseStream, new BasicClaimBasedIdentity(), headers); var converterProvider = container.Resolve<IConverterProvider>(); var converter = converterProvider.FindBestInputConverter<IApiDocumentation>(httpRequest); if (converter == null) { throw new NotSupportedException(String.Format("Content type of '{0}' is not supported.", contentType)); } converter.ConvertTo<IApiDocumentation>(httpRequest); return _container.Resolve<IEntityContext>().Load<IApiDocumentation>((Uri)apiDocumentationId); }
public RequestInfo(Verb method, HttpUrl url, Stream body, IClaimBasedIdentity identity, HeaderCollection headers) { if (method == null) { throw new ArgumentNullException("method"); } if (url == null) { throw new ArgumentNullException("url"); } if (body == null) { throw new ArgumentNullException("body"); } if (identity == null) { throw new ArgumentNullException("identity"); } Method = method; Url = url; Body = new UnclosableStream(_stream = body); _identity = identity; Headers = headers ?? new HeaderCollection(); }
private EntryPointDescriptionController CreateControllerInstance(HttpUrl entryPoint) { var builder = new Mock<IApiEntryPointDescriptionBuilder>(MockBehavior.Strict); builder.SetupSet(instance => instance.EntryPoint = entryPoint); builder.SetupGet(instance => instance.EntryPoint).Returns(entryPoint); return new EntryPointDescriptionController( entryPoint, new Mock<IEntityContextProvider>(MockBehavior.Strict).Object, builder.Object, new Mock<INamedGraphSelectorFactory>(MockBehavior.Strict).Object); }
public RequestMapping(IController target, OperationInfo<Verb> operation, HttpUrl methodRoute) { if (target == null) { throw new ArgumentNullException("target"); } if (operation == null) { throw new ArgumentNullException("operation"); } Target = target; Operation = operation; MethodRoute = methodRoute; ArgumentSources = new Dictionary<int, ArgumentValueSources>(operation.UnderlyingMethod.GetParameters().Length + (operation.UnderlyingMethod.ReturnType != typeof(void) ? 1 : 0)); }
public OptionsRequestMapping(OperationInfo<Verb> operation, HttpUrl methodRoute, HttpStatusCode responseStatusCode, params string[] allowed) { if (operation == null) { throw new ArgumentNullException("operation"); } if (allowed == null) { throw new ArgumentNullException("allowed"); } if (allowed.Length == 0) { throw new ArgumentOutOfRangeException("allowed"); } Target = new OptionsController(responseStatusCode, allowed); Operation = operation; MethodRoute = methodRoute; ArgumentSources = new Dictionary<int, ArgumentValueSources>(operation.UnderlyingMethod.GetParameters().Length + (operation.UnderlyingMethod.ReturnType != typeof(void) ? 1 : 0)); }
public OptionsRequestMapping(OperationInfo <Verb> operation, HttpUrl methodRoute, HttpStatusCode responseStatusCode, params string[] allowed) { if (operation == null) { throw new ArgumentNullException("operation"); } if (allowed == null) { throw new ArgumentNullException("allowed"); } if (allowed.Length == 0) { throw new ArgumentOutOfRangeException("allowed"); } Target = new OptionsController(responseStatusCode, allowed); Operation = operation; MethodRoute = methodRoute; ArgumentSources = new Dictionary <int, ArgumentValueSources>(operation.UnderlyingMethod.GetParameters().Length + (operation.UnderlyingMethod.ReturnType != typeof(void) ? 1 : 0)); }
public ProductClient(HttpUrl baseUri, string authenticationScheme) : base(baseUri, authenticationScheme) { }
public ProductClient(HttpUrl baseUri) : base(baseUri) { }
public PersonClient(HttpUrl baseUri) : base(baseUri) { }
/// <inheritdoc /> public override bool Equals(object obj) { HttpUrl other = obj as HttpUrl; return((other != null) && (other._asString.Equals(_asString))); }
private static Stream GetResponse(string method, HttpUrl url, out string contentType) { var request = WebRequest.CreateHttp((Uri)url); request.Method = method; request.UserAgent = "URSA Proxy Generator"; request.Accept = String.Join(", ", EntityConverter.MediaTypes); var response = (HttpWebResponse)request.GetResponse(); contentType = response.Headers[HttpResponseHeader.ContentType]; return response.GetResponseStream(); }
public TypeClient(HttpUrl baseUri) : base(baseUri) { }
public void Setup() { var parameters = new ParametersCollection("&", "="); parameters.AddValue("with", "query"); _url = new HttpUrl(true, "http://temp.uri/whatever/path?with=query#and-fragment", "http", "temp.uri", 80, "/whatever/path", parameters, "and-fragment", "whatever", "path"); }
public void Teardown() { _url = null; }
private bool Test(ICredentials credentials, HttpUrl url, string expectedUserName, string expectedPassword) { Uri uri = new Uri(String.Format("{0}://{1}/", url.Scheme, url.Host)); return (credentials.GetCredential(uri, AuthenticationScheme).UserName == expectedUserName) && (credentials.GetCredential(uri, AuthenticationScheme).Password == expectedPassword); }
public void should_give_same_instance_if_no_fragments_are_given() { var expected = new HttpUrl(true, "http://temp.uri/", "http", "temp.uri", 80, "/", null, null); expected.WithFragment(null).Should().BeSameAs(expected); }
private static void CreateProxy(string targetDirectory, HttpUrl url) { var namedGraphSelector = _container.Resolve<INamedGraphSelector>() as ILocallyControlledNamedGraphSelector; if (namedGraphSelector != null) { namedGraphSelector.NamedGraph = (Uri)url; } var apiDocumentation = GetApiDocumentation(url); if (apiDocumentation == null) { throw new InvalidOperationException(String.Format("No API documentation found at '{0}'.", url)); } if (apiDocumentation.SupportedClasses.Count == 0) { throw new InvalidOperationException(String.Format("No supported classes found at '{0}'.", url)); } var generator = _container.Resolve<IClassGenerator>(); var supportedClasses = from supportedClass in apiDocumentation.SupportedClasses where supportedClass.Id.ToString() != EntityConverter.Hydra + "ApiDocumentation" from @class in generator.CreateCode(supportedClass) select @class; foreach (var @class in supportedClasses) { File.WriteAllText(Path.Combine(targetDirectory, @class.Key), @class.Value); } if (namedGraphSelector != null) { namedGraphSelector.NamedGraph = null; } }
public Client(HttpUrl baseUrl) : this(baseUrl, DefaultAuthenticationScheme) { }
public RequestInfo(Verb method, HttpUrl url, Stream body, IClaimBasedIdentity identity, params Header[] headers) : this(method, url, body, identity, new HeaderCollection(headers)) { }
/// <summary>Parses a given string as a <see cref="RequestInfo" />.</summary> /// <param name="method">Method of the request.</param> /// <param name="url">URL of the request.</param> /// <param name="message">Request content.</param> /// <returns>Instance of the <see cref="RequestInfo" />.</returns> public static RequestInfo Parse(Verb method, HttpUrl url, string message) { if (method == null) { throw new ArgumentNullException("method"); } if (url == null) { throw new ArgumentNullException("url"); } if (!url.IsAbsolute) { throw new ArgumentOutOfRangeException("url"); } if (message == null) { throw new ArgumentNullException("message"); } if (message.Length == 0) { throw new ArgumentOutOfRangeException("message"); } string[] parts = Regex.Split(message, "\r\n\r\n"); Encoding encoding = Encoding.UTF8; HeaderCollection headers = HeaderCollection.Parse(parts[0]); return new RequestInfo(method, url, (parts.Length > 1 ? new MemoryStream(encoding.GetBytes(parts[1].Trim('\r', '\n'))) : new MemoryStream()), new BasicClaimBasedIdentity(), headers); }