Skip to content

Commit 38a4c2e

Browse files
Ashley LewisAshley Lewis
authored andcommitted
Merge branch '7335-mywarewolfioErrorAndMissingData' of https://gitlab.com/warewolf/warewolf into 7335-mywarewolfioErrorAndMissingData
2 parents f6d909a + f19341d commit 38a4c2e

File tree

8 files changed

+212
-64
lines changed

8 files changed

+212
-64
lines changed

Dev/Dev2.Activities.Designers/Designers2/Web Post New/Large.xaml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
MinWidth="430"
2020
Width="430"
2121
MinHeight="553"
22-
Height="533"
22+
Height="650"
2323
MaxWidth="Infinity"
2424
mc:Ignorable="d"
25-
d:DesignHeight="300"
26-
d:DesignWidth="350"
25+
d:DesignHeight="650"
26+
d:DesignWidth="500"
2727
d:DataContext="{d:DesignInstance webPost:WebPostActivityViewModelNew}">
2828

2929
<core:ActivityDesignerTemplate.Resources>
@@ -59,8 +59,8 @@
5959
</Grid.ColumnDefinitions>
6060
<Grid.RowDefinitions>
6161
<RowDefinition Height="Auto"/>
62-
<RowDefinition Height="*" MinHeight="287"/>
63-
<RowDefinition>
62+
<RowDefinition Height="*" MinHeight="350"/>
63+
<RowDefinition Height="*" MinHeight="120">
6464
<RowDefinition.Style>
6565
<Style>
6666
<Style.Triggers>
@@ -82,24 +82,24 @@
8282
<!-- INPUTS -->
8383
<Grid Grid.Row="1">
8484
<Grid.RowDefinitions>
85-
<RowDefinition Height="*"/>
85+
<RowDefinition Height="*" MinHeight="125"/>
8686
<RowDefinition Height="Auto"/>
87-
<RowDefinition Height="*"/>
87+
<RowDefinition Height="*" MinHeight="100"/>
8888
<RowDefinition Height="Auto"/>
8989
</Grid.RowDefinitions>
9090

9191
<Grid Grid.Row="0">
9292
<Grid.RowDefinitions>
9393
<RowDefinition Height="Auto"/>
94-
<RowDefinition Height="*"/>
94+
<RowDefinition Height="*" />
9595
</Grid.RowDefinitions>
9696
<TextBlock x:Name="HeadersLabel" Text="Headers" Grid.Column="0" Grid.Row="0" />
9797

9898
<controls:Dev2DataGrid x:Name="Headers"
9999
Grid.Row="1"
100+
Height="Auto"
100101
ItemsSource="{Binding InputArea.Headers, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
101102
Style="{StaticResource ActivityMappingDataGridStyle}"
102-
Height="Auto"
103103
IsEnabled="{Binding InputArea.IsEnabled}"
104104
ColumnWidth="*"
105105
Margin="{StaticResource ControlBorderTop}">
@@ -229,7 +229,7 @@
229229
<Grid.RowDefinitions>
230230
<RowDefinition Height="Auto"/>
231231
<RowDefinition Height="Auto"/>
232-
<RowDefinition Height="*"/>
232+
<RowDefinition Height="*" MinHeight="60"/>
233233
</Grid.RowDefinitions>
234234

235235
<TextBlock x:Name="BodyLabel" Text="Body" Grid.Row="0" />
@@ -240,7 +240,6 @@
240240
HorizontalAlignment="Stretch"
241241
AcceptsReturn="True"
242242
Height="Auto"
243-
MinHeight="40"
244243
IsEnabled="{Binding InputArea.IsEnabled}"
245244
VerticalContentAlignment="Top"
246245
TextWrapping="Wrap"

Dev/Dev2.Runtime.Services/ServiceModel/WebSources.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public static string Execute(IWebSource source, WebRequestMethod method, IEnumer
215215
if (method == WebRequestMethod.Post)
216216
{
217217
var bytesData = Encoding.ASCII.GetBytes(data);
218-
return PerformMultipartWebRequest(webRequestFactory, client, address, bytesData, timeout);
218+
return PerformMultipartWebRequest(webRequestFactory, client, address, bytesData, timeout, headers);
219219
}
220220

221221
switch (method)
@@ -369,13 +369,14 @@ static byte[] Execute(IWebSource source, string relativeUri, WebRequestMethod me
369369
return method == WebRequestMethod.Get ? client.DownloadData(address) : client.UploadData(address, method.ToString().ToUpperInvariant(), data);
370370
}
371371

372-
public static string PerformMultipartWebRequest(IWebRequestFactory webRequestFactory, IWebClientWrapper client, string address, byte[] bytesData, int timeout = 0)
372+
public static string PerformMultipartWebRequest(IWebRequestFactory webRequestFactory, IWebClientWrapper client, string address, byte[] bytesData, int timeout = 0, IEnumerable<string> headers = null)
373373
{
374374
var wr = webRequestFactory.New(address);
375375
wr.Headers[HttpRequestHeader.Authorization] = client.Headers[HttpRequestHeader.Authorization];
376376
wr.ContentType = client.Headers[HttpRequestHeader.ContentType];
377377
wr.Method = "POST";
378378
wr.ContentLength = bytesData.Length;
379+
AddHeaders(wr, headers);
379380
if (timeout > 0)
380381
{
381382
wr.Timeout = timeout * 1000;
@@ -454,5 +455,19 @@ private static void AddHeaders(IWebClientWrapper webClient, IEnumerable<string>
454455
}
455456
}
456457
}
458+
459+
private static void AddHeaders(IWebRequest wr, IEnumerable<string> headers)
460+
{
461+
if (headers != null)
462+
{
463+
foreach (var header in headers)
464+
{
465+
if (header != ":" && !header.ToLower().StartsWith("content-type:"))
466+
{
467+
wr.AddHeader(header.Trim());
468+
}
469+
}
470+
}
471+
}
457472
}
458473
}

Dev/Dev2.Runtime.Tests/ESB/RemoteWorkflowExecutionContainerTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ WebResponse IWebRequest.GetResponse()
114114
GetResponseCallCount++;
115115
return new TestWebResponse();
116116
}
117+
118+
public void AddHeader(string header)
119+
{
120+
Headers.Add(header);
121+
}
117122
}
118123

119124
[TestMethod]

Dev/Dev2.Runtime.Tests/ServiceModel/WebSourcesTests.cs

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ public void WebSources_PerformMultipartWebRequest_SetsContentTypeHeaders_And_Sho
446446
mockWebRequestFactory.Setup(o => o.New(address))
447447
.Returns(mockWebRequest.Object);
448448

449+
449450
var source = new WebSource
450451
{
451452
Address = address,
@@ -474,9 +475,81 @@ public void WebSources_PerformMultipartWebRequest_SetsContentTypeHeaders_And_Sho
474475
var contentType = client.Headers["Content-Type"];
475476
Assert.IsNotNull(contentType);
476477
Assert.AreEqual("multipart/form-data", contentType);
477-
478478
Assert.IsNull(result);
479479
}
480+
481+
[TestMethod]
482+
[Owner("Njabulo Nxele")]
483+
[TestCategory(nameof(WebSources))]
484+
public void WebSources_PerformMultipartWebRequest_SetsContentTypeHeaders_And_AddCustomHeaders()
485+
{
486+
var address = "http://www.msn.com/";
487+
var responseFromWeb = Encoding.ASCII.GetBytes("response from web request");
488+
var mockWebClientWrapper = new Mock<IWebClientWrapper>();
489+
490+
var headers = new System.Collections.Generic.List<string>();
491+
headers.Add("a:x");
492+
headers.Add("b:e");
493+
494+
mockWebClientWrapper.Setup(o => o.Headers).Returns(new WebHeaderCollection { "a:x", "b:e" });
495+
mockWebClientWrapper.Setup(o => o.UploadData(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<byte[]>()))
496+
.Returns(responseFromWeb);
497+
498+
var mockWebResponseWrapper = new Mock<HttpWebResponse>();
499+
mockWebResponseWrapper.Setup(o => o.StatusCode)
500+
.Returns(HttpStatusCode.OK);
501+
502+
var mockWebRequest = new Mock<IWebRequest>();
503+
mockWebRequest.Setup(o => o.Headers)
504+
.Returns(new WebHeaderCollection
505+
{
506+
"Authorization:bear: sdfsfff",
507+
});
508+
mockWebRequest.Setup(o => o.ContentType)
509+
.Returns("Content-Type: multipart/form-data");
510+
mockWebRequest.Setup(o => o.ContentLength)
511+
.Returns(Encoding.ASCII.GetBytes(postData).Length);
512+
mockWebRequest.Setup(o => o.Method)
513+
.Returns("POST");
514+
mockWebRequest.Setup(o => o.GetRequestStream())
515+
.Returns(new MemoryStream());
516+
mockWebRequest.Setup(o => o.GetResponse())
517+
.Returns(mockWebResponseWrapper.Object);
518+
519+
var mockWebRequestFactory = new Mock<IWebRequestFactory>();
520+
mockWebRequestFactory.Setup(o => o.New(address))
521+
.Returns(mockWebRequest.Object);
522+
523+
524+
var source = new WebSource
525+
{
526+
Address = address,
527+
AuthenticationType = AuthenticationType.Anonymous,
528+
Client = new WebClientWrapper
529+
{
530+
Headers = new WebHeaderCollection
531+
{
532+
"a:x",
533+
"b:e",
534+
"Content-Type: multipart/form-data"
535+
}
536+
}
537+
};
538+
539+
var result = string.Empty;
540+
try
541+
{
542+
result = WebSources.PerformMultipartWebRequest(mockWebRequestFactory.Object, source.Client, source.Address, postData.ToBytesArray(), headers: headers);
543+
}
544+
catch (WebException e)
545+
{
546+
Assert.Fail("Error connecting to " + source.Address + "\n" + e.Message);
547+
}
548+
549+
mockWebRequest.Verify(o => o.AddHeader(It.IsAny<string>()), Times.Exactly(2));
550+
mockWebRequest.Verify(o => o.AddHeader("a:x"), Times.Once);
551+
mockWebRequest.Verify(o => o.AddHeader("b:e"), Times.Once);
552+
}
480553

481554
[TestMethod]
482555
[Owner("Siphamandla Dube")]

Dev/Warewolf.Common.Interfaces.NetStandard20/Wrappers/IWebRequest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ public interface IWebRequest
2929
WebResponse GetResponse();
3030
Task<WebResponse> GetResponseAsync();
3131
int Timeout { get; set; }
32+
void AddHeader(string header);
3233
}
3334
}

Dev/Warewolf.Common.NetStandard20/Wrappers/WebRequestWrapper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,10 @@ public int Timeout
7979
get => _request.Timeout;
8080
set => _request.Timeout = value;
8181
}
82+
83+
public void AddHeader(string header)
84+
{
85+
_request.Headers.Add(header);
86+
}
8287
}
8388
}

0 commit comments

Comments
 (0)