public static Resources LoadResources(HttpProperties properties, ILogger logger) { var namedResources = new Dictionary <string, IResource>(); foreach (var resource in FindResources(properties, ResourceNamePrefix)) { var loaded = LoadResource(properties, resource, logger); namedResources[loaded.Name] = loaded; } foreach (var item in LoadSseResources(properties, logger)) { namedResources[item.Key] = item.Value; } foreach (var item in LoadFeedResources(properties, logger)) { namedResources[item.Key] = item.Value; } foreach (var item in LoadStaticFilesResource(properties, logger)) { namedResources[item.Key] = item.Value; } return(new Resources(namedResources)); }
private static List <Action> ResourceActionsOf( HttpProperties properties, string resourceName, string[] resourceActionNames) { var resourceActions = new List <Action>(resourceActionNames.Length); foreach (var actionName in resourceActionNames) { try { var keyPrefix = $"action.{resourceName}.{char.ToLowerInvariant(actionName[0])}{actionName.Substring(1)}."; var actionId = resourceActions.Count; var method = properties.GetProperty($"{keyPrefix}method", null); var uri = properties.GetProperty($"{keyPrefix}uri", null); var to = properties.GetProperty($"{keyPrefix}to", null); var mapper = properties.GetProperty($"{keyPrefix}mapper", null); resourceActions.Add(new Action(actionId, method, uri, to, mapper)); } catch (Exception e) { Console.WriteLine($"vlingo-net/http: Failed to load resource: {resourceName} action:{actionName} because: {e.Message}"); throw; } } return(resourceActions); }
private bool ActivateServer(Agent agent, AgentProperties agentProps, bool isPushModeZone) { HttpProperties props = (HttpProperties)fProps; bool webAppEnabled = props.ServletEnabled; // Create the http server if it doesn't exist. All HttpTransport // objects share once instance of the server. if ((sServer == null || !sServer.IsStarted) && (webAppEnabled || isPushModeZone)) { if ((Adk.Debug & AdkDebugFlags.Transport) != 0 && log.IsInfoEnabled) { log.Info("Activating " + fProps.Protocol.ToUpperInvariant() + " transport..."); } if (sServer == null) { // TODO: This should be using some type of a factory metaphor, based on a config setting // We may be going to support, at the minimum, three different HttpPushProtocol configurations // 1) Using the embedded AdkHttpSifServer() // 2) a Wrapper arround HTTP.SYS on Windows 2003 // 3) an implementation that runs inside IIS sServer = new AdkHttpApplicationServer(this); } sServer.Start(); } return(sServer != null); }
private void button1_Click(object sender, System.EventArgs e) { string section = "Ecyware.GreenBlue.ScriptingData"; Hashtable handler = new Hashtable(); handler.Add(section, typeof(Ecyware.GreenBlue.Protocols.Http.Scripting.SessionRequestSerializer)); ConfigManager.SetSectionHandlersOverrides(handler); ConfigManager.SetConfigurationFilePathOverrides("C:\\Tester.xml"); HttpProperties client = new HttpProperties(); client.UserAgent = "Mozilla"; client.Pipeline = true; client.Referer = ""; try { ScriptingData sd = new ScriptingData(); GetWebRequest sr01 = new GetWebRequest(); sr01.Url = "http://www.hotmail.com"; sr01.RequestHttpSettings = client; //WebHeader.FillWebHeaderCollection(coll, sr01.RequestHeaders); sd.AddWebRequest(sr01); //System.Security.Permissions.SecurityPermission perm = new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.SerializationFormatter); XmlNode node = ConfigManager.WriteXmlNode(section, sd); MessageBox.Show(node.OuterXml); } catch ( Exception ex ) { MessageBox.Show(ex.ToString()); } }
private HttpTransport(HttpProperties props, IHttpServer server) : base(props) { Construct(props); sServer = server; }
internal FeatureRequestor(LdClientContext context, Uri baseUri) { _httpProperties = context.Http.HttpProperties; _httpClient = context.Http.NewHttpClient(); _connectTimeout = context.Http.ConnectTimeout; _allUri = baseUri.AddPath(StandardEndpoints.PollingRequestPath); _log = context.Basic.Logger.SubLogger(LogNames.DataSourceSubLog); }
public void CloneCopiesAllTheProperties() { HttpProperties item = CommonTestHelpers.Factory.CreateHttpProperties(); HttpProperties clone = item.Clone(); Assert.AreEqual(JsonSerializer.Serialize(item), JsonSerializer.Serialize(clone)); }
public static HttpProperties CreateHttpProperties() { var result = new HttpProperties(CreateHttpRequest()); result.SetResponse(CreateHttpResponse()); return(result); }
public void MachineNameIsCopied() { HttpProperties result = HttpPropertiesFactory.Create("/"); string machineName = InternalHelpers.GetMachineName(); Assert.AreEqual(machineName, result.Request.MachineName); }
internal FeatureRequestor(LdClientContext context, Uri baseUri) { _httpProperties = context.Http.HttpProperties; _httpClient = context.Http.NewHttpClient(); _connectTimeout = context.Http.ConnectTimeout; _allUri = new Uri(baseUri.AbsoluteUri + "sdk/latest-all"); _flagsUri = new Uri(baseUri.AbsoluteUri + "sdk/latest-flags/"); _segmentsUri = new Uri(baseUri.AbsoluteUri + "sdk/latest-segments/"); _log = context.Basic.Logger.SubLogger(LogNames.DataSourceSubLog); }
public void ResetKeepsTheHttpPropertiesReference(string url) { Logger logger = new Logger(url: url); HttpProperties httpProperties = logger.DataContainer.HttpProperties; logger.Reset(); Assert.AreSame(httpProperties, logger.DataContainer.HttpProperties); }
public void SetResponseWithNullArgumentsThrowsException() { HttpProperties item = new HttpProperties(new HttpRequest(new HttpRequest.CreateOptions { HttpMethod = "GET", Url = UrlParser.GenerateUri(null) })); item.SetResponse(null); }
public void ResponseIsNull() { HttpProperties item = new HttpProperties(new HttpRequest(new HttpRequest.CreateOptions { HttpMethod = "GET", Url = UrlParser.GenerateUri(null) })); Assert.IsNull(item.Response); }
private static HashSet <string> FindResources(HttpProperties properties, string namePrefix) { var resource = new HashSet <string>(); properties.Keys .Where(k => k.StartsWith(namePrefix)) .ToList() .ForEach(k => resource.Add(k)); return(resource); }
internal HttpConfiguration( HttpProperties httpProperties, HttpMessageHandler messageHandler ) { HttpProperties = httpProperties; ConnectTimeout = httpProperties.ConnectTimeout; DefaultHeaders = httpProperties.BaseHeaders; MessageHandler = messageHandler; Proxy = httpProperties.Proxy; ReadTimeout = httpProperties.ReadTimeout; }
public void HttpRequestConstructorUpdatesProperties() { HttpRequest httpRequest = new HttpRequest(new HttpRequest.CreateOptions { HttpMethod = "GET", Url = UrlParser.GenerateUri(null) }); HttpProperties item = new HttpProperties(httpRequest); Assert.AreSame(httpRequest, item.Request); }
internal FlushLogArgs Clone() { return(new FlushLogArgs(new CreateOptions { HttpProperties = HttpProperties.Clone(), MessagesGroups = MessagesGroups.Select(p => p.Clone()).ToList(), Exceptions = Exceptions.ToList(), Files = Files.Select(p => p.Clone()).ToList(), CustomProperties = CustomProperties.ToList(), IsCreatedByHttpRequest = IsCreatedByHttpRequest })); }
internal void Reset() { HttpProperties httpProperties = DataContainer.HttpProperties; DataContainer.Dispose(); DataContainer = new LoggerDataContainer(this); if (httpProperties != null) { DataContainer.SetHttpProperties(httpProperties); } }
public static IServer StartWith(Stage stage, HttpProperties properties) { var configuration = Configuration.DefineWith(properties); var resources = Loader.LoadResources(properties, stage.World.DefaultLogger); return(StartWith( stage, resources, configuration.Port, configuration.Sizing, configuration.Timing)); }
public void ThrowsExceptionWhenHttpPropertiesResponseIsNull() { HttpProperties httpProperties = new HttpProperties(new HttpRequest(new HttpRequest.CreateOptions { HttpMethod = "GET", Url = UrlParser.GenerateUri(null) })); FlushLogArgs item = new FlushLogArgs(new FlushLogArgs.CreateOptions { HttpProperties = httpProperties }); }
private void ConfigureSocketListener(AdkSocketBinding listener, IZone zone, int port, IPAddress address) { listener.HostAddress = address; listener.Port = port; listener.RawBufferSize = zone.Properties.MaxBufferSize + 512; // TT 1440 Add support for a "Max-Connections" feature in the ADK // This is currently an experimental, undocumented and untested feature. // See http://jetty.mortbay.org/jetty5/doc/optimization.html for more // information on optimization with Jetty HttpProperties httpProps = (HttpProperties)fProps; int maxRequestThreads = httpProps.MaxConnections; if (maxRequestThreads > 0) { listener.MaxClientConnections = maxRequestThreads; // No support in the .NET ADK yet for these features // int minRequestThreads = httpProps.getMinConnections(); // if (minRequestThreads < 0) { // minRequestThreads = (int) Math.ceil(maxRequestThreads / 5); // } // listener.setMinThreads(minRequestThreads); // // int maxIdleTimeMs = httpProps.getMaxIdleTimeMs(); // if (maxIdleTimeMs > 0) { // listener.setMaxIdleTimeMs(maxIdleTimeMs); // } // int lowResourcesPersistTimeMs = httpProps // .getLowResourcesPersistTimeMs(); // if (lowResourcesPersistTimeMs > 0) { // listener.setLowResourcePersistTimeMs(lowResourcesPersistTimeMs); // } if ((Adk.Debug & AdkDebugFlags.Transport) != 0 && log.IsDebugEnabled) { log.Debug("Set HttpListener.maxThreads to " + maxRequestThreads); // if (minRequestThreads > 0) { // log.Debug("Set HttpListener.minThreads to " + minRequestThreads ); // } // if (maxIdleTimeMs > 0) { // log.Debug("Set HttpListener.maxIdleTimeMs to " + maxIdleTimeMs ); // } // if (lowResourcesPersistTimeMs > 0) { // log.Debug("Set HttpListener.lowResourcesPersistTimeMs to " + lowResourcesPersistTimeMs ); // } } } }
public static FlushLogArgs Create(Logger[] loggers) { if (loggers == null || !loggers.Any()) { throw new ArgumentNullException(); } Logger defaultLogger = loggers.FirstOrDefault(p => p.CategoryName == Constants.DefaultLoggerCategoryName) ?? loggers.First(); var options = new FlushLogArgs.CreateOptions { MessagesGroups = GetLogMessages(loggers), Exceptions = GetExceptions(loggers), Files = GetFiles(loggers), CustomProperties = GetCustomProperties(loggers), IsCreatedByHttpRequest = defaultLogger.DataContainer.LoggerProperties.IsManagedByHttpRequest }; HttpProperties httpProperties = defaultLogger.DataContainer.HttpProperties; if (httpProperties == null) { httpProperties = new HttpProperties(new HttpRequest(new HttpRequest.CreateOptions { HttpMethod = "GET", Url = UrlParser.GenerateUri(null), MachineName = InternalHelpers.GetMachineName(), StartDateTime = defaultLogger.DataContainer.DateTimeCreated })); } if (httpProperties.Response == null) { int statusCode = options.Exceptions.Any() ? (int)HttpStatusCode.InternalServerError : (int)HttpStatusCode.OK; httpProperties.SetResponse(new HttpResponse(new HttpResponse.CreateOptions { StatusCode = statusCode })); } int?explicitStatusCode = GetExplicitStatusCode(loggers); if (explicitStatusCode.HasValue) { httpProperties.Response.SetStatusCode(explicitStatusCode.Value); } options.HttpProperties = httpProperties; return(new FlushLogArgs(options)); }
private static IDictionary <string, IConfigurationResource> LoadSseResources(HttpProperties properties, ILogger logger) { var sseResourceActions = new Dictionary <string, IConfigurationResource>(); foreach (var streamResourceName in FindResources(properties, SsePublisherNamePrefix)) { var streamUri = properties.GetProperty(streamResourceName); var resourceName = streamResourceName.Substring(SsePublisherNamePrefix.Length); var feedClassnameKey = $"sse.stream.{resourceName}.feed.class"; var feedClassname = properties.GetProperty(feedClassnameKey); var feedPayloadKey = "sse.stream." + resourceName + ".feed.payload"; var maybeFeedPayload = int.Parse(properties.GetProperty(feedPayloadKey, "20") ?? "20"); var feedPayload = maybeFeedPayload <= 0 ? 20 : maybeFeedPayload; var feedIntervalKey = $"sse.stream.{resourceName}.feed.interval"; var maybeFeedInterval = int.Parse(properties.GetProperty(feedIntervalKey, "1000") ?? "1000"); var feedInterval = maybeFeedInterval <= 0 ? 1000 : maybeFeedInterval; var feedDefaultIdKey = $"sse.stream.{resourceName}.feed.default.id"; var feedDefaultId = properties.GetProperty(feedDefaultIdKey, ""); var poolKey = $"sse.stream.{resourceName}.pool"; var maybePoolSize = int.Parse(properties.GetProperty(poolKey, "1") ?? "1"); var handlerPoolSize = maybePoolSize <= 0 ? 1 : maybePoolSize; var subscribeUri = streamUri?.Replace(resourceName, SsePublisherNamePathParameter); var unsubscribeUri = subscribeUri + "/" + SsePublisherIdPathParameter; try { var feedClass = ActorClassWithProtocol(feedClassname, typeof(ISseFeed)); var mappedParameterClass = new Action.MappedParameter("Type", feedClass); var mappedParameterPayload = new Action.MappedParameter("int", feedPayload); var mappedParameterInterval = new Action.MappedParameter("int", feedInterval); var mappedParameterDefaultId = new Action.MappedParameter("string", feedDefaultId); var actions = new List <Action>(2); var additionalParameters = new List <Action.MappedParameter> { mappedParameterClass, mappedParameterPayload, mappedParameterInterval, mappedParameterDefaultId }; actions.Add(new Action(0, Method.Get.Name(), subscribeUri, SsePublisherSubscribeTo, null, additionalParameters)); actions.Add(new Action(1, Method.Delete.Name(), unsubscribeUri, SsePublisherUnsubscribeTo, null)); var resource = ResourceFor(resourceName, typeof(SseStreamResource), handlerPoolSize, actions, logger); sseResourceActions[resourceName] = resource; } catch (Exception e) { Console.WriteLine("vlingo-net/http: Failed to load SSE resource: " + streamResourceName + " because: " + e.Message); Console.WriteLine(e.StackTrace); throw; } } return(sseResourceActions); }
public void SetResponseUpdatesProperty() { HttpResponse httpResponse = new HttpResponse(new HttpResponse.CreateOptions()); HttpProperties item = new HttpProperties(new HttpRequest(new HttpRequest.CreateOptions { HttpMethod = "GET", Url = UrlParser.GenerateUri(null) })); item.SetResponse(httpResponse); Assert.AreSame(httpResponse, item.Response); }
public DefaultEventSender(HttpProperties httpProperties, EventsConfiguration config, Logger logger) { _httpClient = httpProperties.NewHttpClient(); _httpProperties = httpProperties; _eventsUri = config.EventsUri; _diagnosticUri = config.DiagnosticUri; _retryInterval = config.RetryInterval ?? DefaultRetryInterval; _logger = logger; // Currently we do not have a good method of setting the connection timeout separately // from the socket read timeout, so the value we're computing here is for the entire // request-response cycle. See comments in HttpProperties. _timeout = httpProperties.ConnectTimeout.Add(httpProperties.ReadTimeout); }
internal HttpConfiguration( HttpProperties httpProperties, HttpMessageHandler messageHandler, TimeSpan responseStartTimeout, bool useReport ) { HttpProperties = httpProperties; ConnectTimeout = httpProperties.ConnectTimeout; DefaultHeaders = httpProperties.BaseHeaders; MessageHandler = messageHandler; Proxy = httpProperties.Proxy; ResponseStartTimeout = responseStartTimeout; UseReport = useReport; }
public LogListenerInputStreamArgs(ILogListener listener, HttpProperties httpProperties) { if (httpProperties == null) { throw new ArgumentNullException(nameof(httpProperties)); } if (httpProperties.Response == null) { throw new ArgumentNullException(nameof(httpProperties.Response)); } Listener = listener ?? throw new ArgumentNullException(nameof(listener)); HttpProperties = httpProperties ?? throw new ArgumentNullException(nameof(httpProperties)); }
private Configuration(HttpProperties properties) : this() { Port = int.Parse(properties.GetProperty("server.http.port", Port.ToString())); var processorPoolSize = int.Parse(properties.GetProperty("server.processor.pool.size", Sizing.ProcessorPoolSize.ToString())); var dispatcherPoolSize = int.Parse(properties.GetProperty("server.dispatcher.pool", Sizing.DispatcherPoolSize.ToString())); var maxBufferPoolSize = int.Parse(properties.GetProperty("server.buffer.pool.size", Sizing.MaxBufferPoolSize.ToString())); var maxMessageSize = int.Parse(properties.GetProperty("server.message.buffer.size", Sizing.MaxMessageSize.ToString())); var probeInterval = long.Parse(properties.GetProperty("server.probe.interval", Timing.ProbeInterval.ToString())); var probeTimeout = long.Parse(properties.GetProperty("server.probe.timeout", Timing.ProbeInterval.ToString())); var requestMissingContentTimeout = long.Parse(properties.GetProperty("server.request.missing.content.timeout", Timing.RequestMissingContentTimeout.ToString())); Sizing = new SizingConf(processorPoolSize, dispatcherPoolSize, maxBufferPoolSize, maxMessageSize); Timing = new TimingConf(probeInterval, probeTimeout, requestMissingContentTimeout); }
/// <summary> Clone this HttpTransport. /// /// Cloning a transport results in a new HttpTransport instance with /// HttpProperties that inherit from this object's properties. However, the /// web server owned by this transport will be shared with the cloned /// instance. /// </summary> public ITransport CloneTransport() { HttpProperties props; if (fProps is HttpsProperties) { props = new HttpsProperties((HttpsProperties)fProps.Parent); } else { props = new HttpProperties((HttpProperties)fProps.Parent); } // This object and the clone share the server HttpTransport t = new HttpTransport(props, sServer); return(t); }
private HttpProperties GetHttpProperties(bool includeResponse) { HttpProperties httpProperties = new HttpProperties(new HttpRequest(new HttpRequest.CreateOptions { HttpMethod = "GET", Url = UrlParser.GenerateUri(null) })); if (includeResponse) { httpProperties.SetResponse(new HttpResponse(new HttpResponse.CreateOptions() { })); } return(httpProperties); }
public Logger(string categoryName = null, string url = null) { Id = Guid.NewGuid(); CategoryName = string.IsNullOrWhiteSpace(categoryName) ? Constants.DefaultLoggerCategoryName : categoryName; DataContainer = new LoggerDataContainer(this); HttpProperties httpProperties = string.IsNullOrWhiteSpace(url) ? null : HttpPropertiesFactory.Create(url); if (httpProperties != null) { DataContainer.SetHttpProperties(httpProperties); InternalHelpers.WrapInTryCatch(() => { NotifyBeginRequest.Notify(httpProperties.Request); }); } }
public UnitTestSessionProcessor(UnitTestSession uts, HttpProxy proxySettings,HttpProperties httpProperties) { this.CurrentUnitTestSession = uts; this.Proxy = proxySettings; this.ProtocolProperties = httpProperties; }
/// <summary> Constructs an HttpTransport for HTTP or HTTPS</summary> /// <param name="props">Transport properties (usually an instance of HttpProperties /// or HttpsProperties) /// </param> public HttpTransport( HttpProperties props ) : base(props) { Construct( props ); }
private HttpTransport( HttpProperties props, IHttpServer server ) : base(props) { Construct( props ); sServer = server; }
/// <summary> Clone this HttpTransport. /// /// Cloning a transport results in a new HttpTransport instance with /// HttpProperties that inherit from this object's properties. However, the /// web server owned by this transport will be shared with the cloned /// instance. /// </summary> public ITransport CloneTransport() { HttpProperties props; if ( fProps is HttpsProperties ) { props = new HttpsProperties( (HttpsProperties) fProps.Parent ); } else { props = new HttpProperties( (HttpProperties) fProps.Parent ); } // This object and the clone share the server HttpTransport t = new HttpTransport( props, sServer ); return t; }
private void Construct( HttpProperties props ) { fProps = props; log = LogManager.GetLogger( Adk.LOG_IDENTIFIER + ".Agent.transport$" + fProps.Protocol ); }
/// <summary> /// Redirects to url. /// </summary> /// <param name="state"> The HTTP State.</param> /// <param name="cookies"> The cookie collection.</param> /// <param name="settings"> The HTTP Settings.</param> /// <param name="url"> The url to redirect to.</param> private void ApplyUrlRedirection(HttpState state, CookieCollection cookies,HttpProperties settings, string url) { this.DisplaySessionProcessEvent(this, new SessionCommandProcessEventArgs("Requesting " + url)); // Request, we only use url, http settings and cookies, because // IE doesn't returns and arraylist of values for GET requests. this.StartGetRequest(safeSessionGetRequest,url,null, cookies, settings, state); }
/// <summary> /// Get Async get request. /// </summary> /// <param name="getUrl"> The url.</param> /// <param name="values"> The get values.</param> /// <param name="cookies"> The cookies.</param> /// <param name="state"> The http state.</param> private void StartGetRequest(GetForm httpCommand, string getUrl, ArrayList values, CookieCollection cookies, HttpProperties settings, HttpState state) { try { httpCommand.StartAsyncHttpGet( getUrl, settings, values, cookies, state, false); } catch (Exception ex) { // register and show Utils.ExceptionHandler.RegisterException(ex); AbortSessionRun(ex.Message); } }