Skip to content

Commit d51517e

Browse files
committed
Message type was not promoted when handling requests with body.
Now determines and promotes the message type from the body,
1 parent ab1f04b commit d51517e

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

Src/HttpDisassembler/HttpDisassembler.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,13 @@ public void Disassemble(IPipelineContext pContext, IBaseMessage pInMsg)
100100
//If the request has a body it should be preserved an the query parameters should be written to it's own message part.
101101
if (hasData)
102102
{
103+
string msgType = GetMessageType(MakeMarkable(pInMsg.BodyPart.Data), null);
104+
103105
outMsg = pInMsg;
104106
outMsg.BodyPart.Data = pInMsg.BodyPart.Data;
107+
105108
outMsg.Context = PipelineUtil.CloneMessageContext(pInMsg.Context);
109+
outMsg.Context.Promote(new ContextProperty(SystemProperties.MessageType),msgType);
106110
var factory = pContext.GetMessageFactory();
107111
var queryPart = factory.CreateMessagePart();
108112
queryPart.Data = ms;
@@ -141,7 +145,64 @@ public IBaseMessage GetNext(IPipelineContext pContext)
141145

142146
return null;
143147
}
148+
149+
private MarkableForwardOnlyEventingReadStream MakeMarkable(Stream stream)
150+
{
151+
MarkableForwardOnlyEventingReadStream eventingReadStream = null;
152+
153+
if (stream != null)
154+
{
155+
eventingReadStream = stream as MarkableForwardOnlyEventingReadStream ?? new MarkableForwardOnlyEventingReadStream(stream);
156+
}
157+
158+
return eventingReadStream;
159+
}
160+
161+
private string GetMessageType(MarkableForwardOnlyEventingReadStream stm, Encoding encoding)
162+
{
163+
string msgType = null;
144164

165+
stm.MarkPosition();
166+
try
167+
{
168+
XmlTextReader xmlTextReader = null;
169+
if (encoding != null)
170+
{
171+
xmlTextReader = new XmlTextReader(new StreamReader(stm, encoding));
172+
}
173+
else
174+
{
175+
xmlTextReader = new XmlTextReader((Stream)stm);
176+
}
177+
178+
while (msgType == null)
179+
{
180+
if (xmlTextReader.Read())
181+
{
182+
if (xmlTextReader.NodeType == XmlNodeType.Element && xmlTextReader.Depth == 0)
183+
{
184+
if (xmlTextReader.NamespaceURI == null || xmlTextReader.NamespaceURI.Length <= 0)
185+
{
186+
msgType = xmlTextReader.LocalName;
187+
}
188+
else
189+
{
190+
msgType = xmlTextReader.NamespaceURI + '#' + xmlTextReader.LocalName;
191+
}
192+
}
193+
}
194+
else
195+
{
196+
break;
197+
}
198+
}
199+
}
200+
finally
201+
{
202+
stm.ResetPosition();
203+
}
204+
return msgType;
205+
}
145206
private bool HasData(Stream data)
146207
{
147208
byte[] buffer= new byte[10];

Tests/UnitTests/HttpDisassemblerTest.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,36 @@ public void CreateMessageWithBodyTest()
7070
Assert.AreEqual(testMessage, bodyDoc.ToString());
7171
}
7272

73+
[TestMethod]
74+
public void CreateMessageWithBodyAndNamespaceTest()
75+
{
76+
var pipeline = PipelineFactory.CreateEmptyReceivePipeline();
77+
78+
pipeline.AddDocSpec(typeof(TestSchema));
79+
80+
var disassembler = new PipelineComponents.HttpDisassembler.HttpDisassembler
81+
{
82+
DocumentSpecName = "BizTalkComponents.HttpDisassembler.Tests.UnitTests.TestSchema"
83+
};
84+
string testMessage = "<testmessage xmlns=\"testns\"></testmessage>";
85+
var message = MessageHelper.CreateFromString(testMessage);
86+
message.Context.Promote(new ContextProperty("http://BiztalkComponents.PropertySchema#TestProperty1"), "value1");
87+
message.Context.Promote(new ContextProperty("http://BiztalkComponents.PropertySchema#TestProperty2"), "value2");
88+
89+
pipeline.AddComponent(disassembler, PipelineStage.Disassemble);
90+
91+
var result = pipeline.Execute(message);
92+
93+
Assert.AreEqual(1, result.Count);
94+
Assert.AreEqual(2, result[0].PartCount);
95+
96+
var doc = XDocument.Load(result[0].GetPart("querypart").GetOriginalDataStream());
97+
var bodyDoc = XDocument.Load(result[0].BodyPart.GetOriginalDataStream());
98+
99+
Assert.IsTrue(result[0].Context.IsPromoted("MessageType", "http://schemas.microsoft.com/BizTalk/2003/system-properties"));
100+
Assert.AreEqual("testns#testmessage", result[0].Context.Read("MessageType", "http://schemas.microsoft.com/BizTalk/2003/system-properties"));
101+
}
102+
73103
[TestMethod]
74104
[ExpectedException(typeof(COMException))]
75105
public void UnknownDocType()

0 commit comments

Comments
 (0)