public CreateWebRequest ( |
||
baseUri | Uri that will have the command run against | |
commandToExecute | Command to execute | |
return |
public virtual Response Execute(Command commandToExecute) { if (commandToExecute == null) { throw new ArgumentNullException("commandToExecute", "commandToExecute cannot be null"); } CommandInfo commandInfo = this.commandInfoRepository.GetCommandInfo(commandToExecute.Name); HttpWebRequest httpWebRequest = commandInfo.CreateWebRequest(this.remoteServerUri, commandToExecute); httpWebRequest.Timeout = (int)this.serverResponseTimeout.TotalMilliseconds; httpWebRequest.Accept = "application/json, image/png"; httpWebRequest.KeepAlive = this.enableKeepAlive; httpWebRequest.ServicePoint.ConnectionLimit = 2000; if (httpWebRequest.Method == "POST") { string parametersAsJsonString = commandToExecute.ParametersAsJsonString; byte[] bytes = Encoding.UTF8.GetBytes(parametersAsJsonString); httpWebRequest.ContentType = "application/json;charset=utf-8"; Stream requestStream = httpWebRequest.GetRequestStream(); requestStream.Write(bytes, 0, bytes.Length); requestStream.Close(); } Response response = this.CreateResponse(httpWebRequest); if (commandToExecute.Name == DriverCommand.NewSession && response.IsSpecificationCompliant) { this.commandInfoRepository = new W3CWireProtocolCommandInfoRepository(); } return(response); }
/// <summary> /// Executes a command /// </summary> /// <param name="commandToExecute">The command you wish to execute</param> /// <returns>A response from the browser</returns> public virtual Response Execute(Command commandToExecute) { if (commandToExecute == null) { throw new ArgumentNullException("commandToExecute", "commandToExecute cannot be null"); } CommandInfo info = CommandInfoRepositoryExtended.Instance.GetCommandInfo(commandToExecute.Name); HttpWebRequest request = info.CreateWebRequest(this.remoteServerUri, commandToExecute); request.Timeout = (int)this.serverResponseTimeout.TotalMilliseconds; request.Accept = RequestAcceptHeader; request.KeepAlive = this.enableKeepAlive; request.ServicePoint.ConnectionLimit = 2000; string authInfo = user + ":" + password; authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo)); request.Headers["Authorization"] = "Basic " + authInfo; if (request.Method == CommandInfo.PostCommand) { string payload = commandToExecute.ParametersAsJsonString; byte[] data = Encoding.UTF8.GetBytes(payload); request.ContentType = ContentTypeHeader; Stream requestStream = request.GetRequestStream(); requestStream.Write(data, 0, data.Length); requestStream.Close(); } return(this.CreateResponse(request)); }
/// <summary> /// Executes a command /// </summary> /// <param name="commandToExecute">The command you wish to execute</param> /// <returns>A response from the browser</returns> public virtual Response Execute(Command commandToExecute) { if (commandToExecute == null) { throw new ArgumentNullException("commandToExecute", "commandToExecute cannot be null"); } CommandInfo info = this.commandInfoRepository.GetCommandInfo(commandToExecute.Name); HttpWebRequest request = info.CreateWebRequest(this.remoteServerUri, commandToExecute); request.Timeout = (int)this.serverResponseTimeout.TotalMilliseconds; request.Accept = RequestAcceptHeader; request.KeepAlive = this.enableKeepAlive; request.ServicePoint.ConnectionLimit = 2000; if (request.Method == CommandInfo.PostCommand) { string payload = commandToExecute.ParametersAsJsonString; byte[] data = Encoding.UTF8.GetBytes(payload); request.ContentType = ContentTypeHeader; Stream requestStream = request.GetRequestStream(); requestStream.Write(data, 0, data.Length); requestStream.Close(); } Response toReturn = this.CreateResponse(request); if (commandToExecute.Name == DriverCommand.NewSession) { // If we are creating a new session, sniff the response to determine // what protocol level we are using. If the response contains a // capability called "specificationLevel" that's an integer value // and that's greater than 0, that means we're using the W3C protocol // dialect. // TODO(jimevans): Reverse this test to make it the default path when // most remote ends speak W3C, then remove it entirely when legacy // protocol is phased out. Dictionary <string, object> capabilities = toReturn.Value as Dictionary <string, object>; if (capabilities != null) { if (capabilities.ContainsKey("specificationLevel")) { int returnedSpecLevel = Convert.ToInt32(capabilities["specificationLevel"]); if (returnedSpecLevel > 0) { this.commandInfoRepository = new W3CWireProtocolCommandInfoRepository(); } } } } return(toReturn); }
/// <summary> /// Executes a command /// </summary> /// <param name="commandToExecute">The command you wish to execute</param> /// <returns>A response from the browser</returns> public Response Execute(Command commandToExecute) { CommandInfo info = CommandInfoRepository.Instance.GetCommandInfo(commandToExecute.Name); HttpWebRequest request = info.CreateWebRequest(this.remoteServerUri, commandToExecute); request.Timeout = (int)this.serverResponseTimeout.TotalMilliseconds; request.Accept = RequestAcceptHeader; if (request.Method == CommandInfo.PostCommand) { string payload = commandToExecute.ParametersAsJsonString; byte[] data = Encoding.UTF8.GetBytes(payload); request.ContentType = JsonMimeType; System.IO.Stream requestStream = request.GetRequestStream(); requestStream.Write(data, 0, data.Length); requestStream.Close(); } return(CreateResponse(request)); }
/// <summary> /// Executes a command /// </summary> /// <param name="commandToExecute">The command you wish to execute</param> /// <returns>A response from the browser</returns> public virtual Response Execute(Command commandToExecute) { if (commandToExecute == null) { throw new ArgumentNullException("commandToExecute", "commandToExecute cannot be null"); } CommandInfo info = this.commandInfoRepository.GetCommandInfo(commandToExecute.Name); HttpWebRequest request = info.CreateWebRequest(this.remoteServerUri, commandToExecute); request.Timeout = (int)this.serverResponseTimeout.TotalMilliseconds; request.Accept = RequestAcceptHeader; request.KeepAlive = this.enableKeepAlive; request.ServicePoint.ConnectionLimit = 2000; if (request.Method == CommandInfo.PostCommand) { string payload = commandToExecute.ParametersAsJsonString; byte[] data = Encoding.UTF8.GetBytes(payload); request.ContentType = ContentTypeHeader; Stream requestStream = request.GetRequestStream(); requestStream.Write(data, 0, data.Length); requestStream.Close(); } Response toReturn = this.CreateResponse(request); if (commandToExecute.Name == DriverCommand.NewSession && toReturn.IsSpecificationCompliant) { // If we are creating a new session, sniff the response to determine // what protocol level we are using. If the response contains a // field called "status", it's not a spec-compliant response. // Each response is polled for this, and sets a property describing // whether it's using the W3C protocol dialect. // TODO(jimevans): Reverse this test to make it the default path when // most remote ends speak W3C, then remove it entirely when legacy // protocol is phased out. this.commandInfoRepository = new W3CWireProtocolCommandInfoRepository(); } return(toReturn); }
/// <summary> /// Executes a command /// </summary> /// <param name="commandToExecute">The command you wish to execute</param> /// <returns>A response from the browser</returns> public Response Execute(Command commandToExecute) { CommandInfo info = CommandInfoRepository.Instance.GetCommandInfo(commandToExecute.Name); HttpWebRequest.DefaultMaximumErrorResponseLength = -1; HttpWebRequest request = info.CreateWebRequest(remoteServerUri, commandToExecute); request.Timeout = 15000; request.Accept = "application/json, image/png"; if (request.Method == CommandInfo.PostCommand) { string payload = commandToExecute.ParametersAsJsonString; byte[] data = Encoding.UTF8.GetBytes(payload); request.ContentType = "application/json"; System.IO.Stream requestStream = request.GetRequestStream(); requestStream.Write(data, 0, data.Length); requestStream.Close(); } return(CreateResponse(request)); }
/// <summary> /// Executes a command /// </summary> /// <param name="commandToExecute">The command you wish to execute</param> /// <returns>A response from the browser</returns> public virtual Response Execute(Command commandToExecute) { if (commandToExecute == null) { throw new ArgumentNullException("commandToExecute", "commandToExecute cannot be null"); } CommandInfo info = CommandInfoRepository.Instance.GetCommandInfo(commandToExecute.Name); HttpWebRequest request = info.CreateWebRequest(this.remoteServerUri, commandToExecute); request.Timeout = (int)this.serverResponseTimeout.TotalMilliseconds; request.Accept = RequestAcceptHeader; request.KeepAlive = this.enableKeepAlive; request.ServicePoint.ConnectionLimit = 2000; if (request.Method == CommandInfo.PostCommand) { string payload = commandToExecute.ParametersAsJsonString; byte[] data = Encoding.UTF8.GetBytes(payload); request.ContentType = ContentTypeHeader; Stream requestStream = request.GetRequestStream(); requestStream.Write(data, 0, data.Length); requestStream.Close(); // Petruc Remove - Debug only--------------------- Console.WriteLine("Request Uri: " + request.RequestUri); Console.WriteLine("Request Method: " + request.Method); Console.WriteLine("Request Body: " + payload); //----------------------------------------------- } else { Console.WriteLine("Request Uri: " + request.RequestUri); Console.WriteLine("Request Method: " + request.Method); } return(this.CreateResponse(request)); }