diff --git a/CHANGELOG b/CHANGELOG index 37723f1f..b698ebb3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,8 @@ = LitleOnline CHANGELOG +== Version 11.4.9 (October 25, 2019) +* BugFix: Fixed timeout not being used in non-async methods + == Version 11.4.8 (August 22, 2019) * BugFix: merchantSdk field in generated xml request is synced. diff --git a/LitleSdkForNet/LitleSdkForNet/Communications.cs b/LitleSdkForNet/LitleSdkForNet/Communications.cs index 0cf0d3d0..dfe35c00 100644 --- a/LitleSdkForNet/LitleSdkForNet/Communications.cs +++ b/LitleSdkForNet/LitleSdkForNet/Communications.cs @@ -115,7 +115,109 @@ public virtual Task HttpPostAsync(string xmlRequest, Dictionary config) { - return HttpPostCoreAsync(xmlRequest, config, isAsync: false).GetAwaiter().GetResult(); + string logFile = null; + if (config.ContainsKey("logFile")) + { + logFile = config["logFile"]; + } + + var uri = config["url"]; + + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11; + var req = (HttpWebRequest)WebRequest.Create(uri); + + var neuterAccNums = false; + if (config.ContainsKey("neuterAccountNums")) + { + neuterAccNums = ("true".Equals(config["neuterAccountNums"])); + } + + var neuterCreds = false; + if (config.ContainsKey("neuterUserCredentials")) + { + neuterCreds = ("true".Equals(config["neuterUserCredentials"])); + } + + var printxml = false; + if (config.ContainsKey("printxml")) + { + if ("true".Equals(config["printxml"])) + { + printxml = true; + } + } + + if (printxml) + { + Console.WriteLine(xmlRequest); + Console.WriteLine(logFile); + Console.WriteLine(logFile); + } + + //log request + if (logFile != null) + { + Log(xmlRequest, logFile, neuterAccNums, neuterCreds); + } + + req.ContentType = ContentTypeTextXmlUTF8; + req.Method = "POST"; + req.ServicePoint.MaxIdleTime = 8000; + req.ServicePoint.Expect100Continue = false; + req.KeepAlive = false; + + if (config.ContainsKey("timeout")) { + try { + req.Timeout = Convert.ToInt32(config["timeout"]); + } + catch (FormatException e) { + // If timeout setting contains non-numeric + // characters, we will fall back to 1 minute + // default timeout. + req.Timeout = 60000; + } + } + + + if (IsProxyOn(config)) + { + var myproxy = new WebProxy(config["proxyHost"], int.Parse(config["proxyPort"])) + { + BypassProxyOnLocal = true + }; + req.Proxy = myproxy; + } + + OnHttpAction(RequestType.Request, xmlRequest, neuterAccNums, neuterCreds); + + // submit http request + using (var writer = new StreamWriter(req.GetRequestStream())) + { + writer.Write(xmlRequest); + } + + // read response + var response = req.GetResponse(); + + string xmlResponse; + using (var reader = new StreamReader(response.GetResponseStream())) + { + xmlResponse = reader.ReadToEnd().Trim(); + } + if (printxml) + { + Console.WriteLine(xmlResponse); + } + + OnHttpAction(RequestType.Response, xmlResponse, neuterAccNums, neuterCreds); + + //log response + if (logFile != null) + { + Log(xmlResponse, logFile, neuterAccNums, neuterCreds); + } + + return xmlResponse; } private async Task HttpPostCoreAsync(string xmlRequest, Dictionary config, bool isAsync, CancellationToken cancellationToken = default(CancellationToken)) @@ -170,15 +272,6 @@ public virtual string HttpPost(string xmlRequest, Dictionary con req.ServicePoint.MaxIdleTime = 8000; req.ServicePoint.Expect100Continue = false; req.KeepAlive = false; - - //set timeout for request if available. #Issue 58 - //connection timeout is increased 3 times on successful establishment. - if(config.ContainsKey("timeout") && config["timeout"] != null && int.Parse(config["timeout"]) > 0) - { - var timeOut = int.Parse(config["timeout"]); - req.Timeout = timeOut; - req.ReadWriteTimeout = 3*timeOut; - } if (IsProxyOn(config)) diff --git a/LitleSdkForNet/LitleSdkForNet/LitleBatchRequest.cs b/LitleSdkForNet/LitleSdkForNet/LitleBatchRequest.cs index 649a6346..62805006 100644 --- a/LitleSdkForNet/LitleSdkForNet/LitleBatchRequest.cs +++ b/LitleSdkForNet/LitleSdkForNet/LitleBatchRequest.cs @@ -1376,7 +1376,7 @@ public string generateXmlHeader() xmlHeader += "sameDayFunding=\"" + sameDayFunding.ToString().ToLower() + "\"\r\n"; } - xmlHeader += "merchantSdk=\"DotNet;11.4.8\"\r\n"; + xmlHeader += "merchantSdk=\"DotNet;11.4.9\"\r\n"; xmlHeader += "merchantId=\"" + config["merchantId"] + "\">\r\n"; return xmlHeader; diff --git a/LitleSdkForNet/LitleSdkForNet/LitleOnline.cs b/LitleSdkForNet/LitleSdkForNet/LitleOnline.cs index 19e80d86..e43daa81 100644 --- a/LitleSdkForNet/LitleSdkForNet/LitleOnline.cs +++ b/LitleSdkForNet/LitleSdkForNet/LitleOnline.cs @@ -678,7 +678,7 @@ private litleOnlineRequest CreateLitleOnlineRequest() { var request = new litleOnlineRequest(); request.merchantId = _config["merchantId"]; - request.merchantSdk = "DotNet;11.4.8"; + request.merchantSdk = "DotNet;11.4.9"; var authentication = new authentication(); authentication.password = _config["password"]; authentication.user = _config["username"]; diff --git a/LitleSdkForNet/LitleSdkForNet/Properties/AssemblyInfo.cs b/LitleSdkForNet/LitleSdkForNet/Properties/AssemblyInfo.cs index 320abad0..95c1d429 100644 --- a/LitleSdkForNet/LitleSdkForNet/Properties/AssemblyInfo.cs +++ b/LitleSdkForNet/LitleSdkForNet/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("11.4.8")] -[assembly: AssemblyFileVersion("11.4.8")] +[assembly: AssemblyVersion("11.4.9")] +[assembly: AssemblyFileVersion("11.4.9")] diff --git a/LitleSdkForNet/LitleSdkForNet/Properties/Settings.Designer.cs b/LitleSdkForNet/LitleSdkForNet/Properties/Settings.Designer.cs index 9822a5f2..8051f613 100644 --- a/LitleSdkForNet/LitleSdkForNet/Properties/Settings.Designer.cs +++ b/LitleSdkForNet/LitleSdkForNet/Properties/Settings.Designer.cs @@ -49,7 +49,7 @@ public string printxml { [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("500")] + [global::System.Configuration.DefaultSettingValueAttribute("5000")] public string timeout { get { return ((string)(this["timeout"])); diff --git a/LitleSdkForNet/LitleSdkForNet/Properties/Settings.settings b/LitleSdkForNet/LitleSdkForNet/Properties/Settings.settings index 33311243..2702e0f7 100644 --- a/LitleSdkForNet/LitleSdkForNet/Properties/Settings.settings +++ b/LitleSdkForNet/LitleSdkForNet/Properties/Settings.settings @@ -9,7 +9,7 @@ true - 500 + 5000 payments.vantivprelive.com diff --git a/LitleSdkForNet/LitleSdkForNetTest/Functional/TestTimeout.cs b/LitleSdkForNet/LitleSdkForNetTest/Functional/TestTimeout.cs new file mode 100644 index 00000000..a06c4456 --- /dev/null +++ b/LitleSdkForNet/LitleSdkForNetTest/Functional/TestTimeout.cs @@ -0,0 +1,106 @@ +using System.Collections.Generic; +using System.Net; +using NUnit.Framework; + +namespace Litle.Sdk.Test.Functional { + [TestFixture] + internal class TestTimeout + { + private LitleOnline _cnp; + private Dictionary _config; + + [Test] + public void TestTimeoutNotDefined() + { + _config = new Dictionary + { + {"url", Properties.Settings.Default.url}, + {"reportGroup", "Default Report Group"}, + {"username", "DOTNET"}, + {"version", "11.0"}, + {"merchantId", "101"}, + {"password", "TESTCASE"}, + {"printxml", "true"}, + {"proxyHost", Properties.Settings.Default.proxyHost}, + {"proxyPort", Properties.Settings.Default.proxyPort}, + {"logFile", Properties.Settings.Default.logFile}, + {"neuterAccountNums", "true"} + }; + + _cnp = new LitleOnline(_config); + + var registerTokenRequest = new registerTokenRequestType + { + id = "1", + reportGroup = "Planets", + orderId = "12344", + accountNumber = "1233456789103801", + }; + + var rtokenResponse = _cnp.RegisterToken(registerTokenRequest); + StringAssert.AreEqualIgnoringCase("Account number was successfully registered", rtokenResponse.message); + } + + [Test] + public void TestTimeoutNotParsable() + { + _config = new Dictionary + { + {"url", Properties.Settings.Default.url}, + {"reportGroup", "Default Report Group"}, + {"username", "DOTNET"}, + {"version", "11.0"}, + {"timeout", "notparsableasint"}, + {"merchantId", "101"}, + {"password", "TESTCASE"}, + {"printxml", "true"}, + {"proxyHost", Properties.Settings.Default.proxyHost}, + {"proxyPort", Properties.Settings.Default.proxyPort}, + {"logFile", Properties.Settings.Default.logFile}, + {"neuterAccountNums", "true"} + }; + + _cnp = new LitleOnline(_config); + + var registerTokenRequest = new registerTokenRequestType + { + id = "1", + reportGroup = "Planets", + orderId = "12344", + accountNumber = "1233456789103801", + }; + + var rtokenResponse = _cnp.RegisterToken(registerTokenRequest); + StringAssert.AreEqualIgnoringCase("Account number was successfully registered", rtokenResponse.message); + } + + [Test] + public void TestTimeoutReached() { + _config = new Dictionary { + {"url", Properties.Settings.Default.url}, + {"reportGroup", "Default Report Group"}, + {"username", "DOTNET"}, + {"version", "11.0"}, + {"timeout", "0"}, + {"merchantId", "101"}, + {"password", "TESTCASE"}, + {"printxml", "true"}, + {"proxyHost", Properties.Settings.Default.proxyHost}, + {"proxyPort", Properties.Settings.Default.proxyPort}, + {"logFile", Properties.Settings.Default.logFile}, + {"neuterAccountNums", "true"} + }; + + _cnp = new LitleOnline(_config); + + var registerTokenRequest = new registerTokenRequestType { + id = "1", + reportGroup = "Planets", + orderId = "12344", + accountNumber = "1233456789103801", + }; + + Assert.Throws(() => { _cnp.RegisterToken(registerTokenRequest); }); + } + } +} \ No newline at end of file diff --git a/LitleSdkForNet/LitleSdkForNetTest/LitleSdkForNetTest.csproj b/LitleSdkForNet/LitleSdkForNetTest/LitleSdkForNetTest.csproj index e3198dac..50e705cb 100644 --- a/LitleSdkForNet/LitleSdkForNetTest/LitleSdkForNetTest.csproj +++ b/LitleSdkForNet/LitleSdkForNetTest/LitleSdkForNetTest.csproj @@ -117,6 +117,7 @@ + diff --git a/LitleSdkForNet/LitleSdkForNetTest/Unit/TestBatchRequest.cs b/LitleSdkForNet/LitleSdkForNetTest/Unit/TestBatchRequest.cs index 687ff877..25da0d1a 100644 --- a/LitleSdkForNet/LitleSdkForNetTest/Unit/TestBatchRequest.cs +++ b/LitleSdkForNet/LitleSdkForNetTest/Unit/TestBatchRequest.cs @@ -55,7 +55,7 @@ public void testBatchRequestContainsMerchantSdkAttribute() var actual = batchRequest.generateXmlHeader(); var expected = @" ";