public static Message HttpPostMessage(this Message message, HttpConnectorConfiguration config, string relativePath, string contentType = "text/xml") { Logger.DebugFormat("Step"); var client = new System.Net.WebClient(); var url = String.Format("http://{0}:{1}{2}", config.Host, config.Port, config.BasePath); config.Headers.ToList().ForEach(h => client.Headers.Add(h.Key, h.Value)); message.Variables.Where(v => v.Key.StartsWith("HttpHeader")).ToList().ForEach(h => client.Headers.Add(h.Key.Replace("HttpHeader", ""), h.Value.ToString())); config.Query.ToList().ForEach(h => client.QueryString.Add(h.Key, h.Value)); message.Variables.Where(v => v.Key.StartsWith("HttpQuery")).ToList().ForEach(h => client.QueryString.Add(h.Key.Replace("HttpQuery", ""), h.Value.ToString())); client.Encoding = Encoding.UTF8; try { message.SetPayload(client.UploadString(url, message.Payload.FirstNode.ToString())); message.Variables["ContentType"] = contentType; } catch (WebException ex) { message.SetPayload(ex.Response.GetResponseStream()); message.Variables["ContentType"] = "text/plain"; } return(message); }
public static Message HttpPostMessage(this Message message, HttpConnectorConfiguration config, string relativePath, string contentType = "text/xml") { Logger.DebugFormat("Step"); var client = new System.Net.WebClient(); var url = String.Format("http://{0}:{1}{2}", config.Host, config.Port, config.BasePath); config.Headers.ToList().ForEach(h => client.Headers.Add(h.Key, h.Value)); message.Variables.Where(v => v.Key.StartsWith("HttpHeader")).ToList().ForEach(h => client.Headers.Add(h.Key.Replace("HttpHeader", ""), h.Value.ToString())); config.Query.ToList().ForEach(h => client.QueryString.Add(h.Key, h.Value)); message.Variables.Where(v => v.Key.StartsWith("HttpQuery")).ToList().ForEach(h => client.QueryString.Add(h.Key.Replace("HttpQuery", ""), h.Value.ToString())); client.Encoding = Encoding.UTF8; try { message.SetPayload(client.UploadString(url, message.Payload.FirstNode.ToString())); message.Variables["ContentType"] = contentType; } catch (WebException ex) { message.SetPayload(ex.Response.GetResponseStream()); message.Variables["ContentType"] = "text/plain"; } return message; }
public static Message LoadToken(this Message message, HttpConnectorConfiguration plentyConfig) { return message .LoadTempToken() .If(m => m.Variables.ContainsKey("Token") && !string.IsNullOrEmpty((string)m.Variables["Token"])) .Then(Message.NoChange) .Else(m => m .SetPayload(Resources.LoadModuleResourceXml<Module>(@"PlentyConfig.xml")) .ClearVariables() .XslTransformFromModuleResource<Module>(@"GetToken/GetTokenTransform.xsl") .SetVariable("HttpHeaderSoapAction", "GetAuthentificationToken") .LogDebug(me => String.Format("Configured Request:\r\n{0}", me)) .HttpPostMessage(plentyConfig, "") .LogDebug(me => String.Format("Received Response:\r\n{0}", me)) .ClearVariables() .ExtractVariable("//Token", "Token") .SaveTempToken() ) .EndIf() ; }