1111using BizTalkComponents . Utils ;
1212using BizTalkComponents . Utilities . ComponentInstrumentation ;
1313using System . Runtime . InteropServices ;
14+ using Microsoft . BizTalk . Streaming ;
15+
1416namespace BizTalkComponents . PipelineComponents . HttpDisassembler
1517{
1618
@@ -50,6 +52,11 @@ public void Disassemble(IPipelineContext pContext, IBaseMessage pInMsg)
5052 throw ex ;
5153 }
5254
55+ var data = pInMsg . BodyPart . GetOriginalDataStream ( ) ;
56+
57+ //Determine of the request body has any data. GET request will not have any body.
58+ var hasData = HasData ( data ) ;
59+
5360 //Get a reference to the BizTalk schema.
5461 DocumentSpec documentSpec ;
5562 try
@@ -89,11 +96,26 @@ public void Disassemble(IPipelineContext pContext, IBaseMessage pInMsg)
8996 ms . Seek ( 0 , SeekOrigin . Begin ) ;
9097
9198 var outMsg = pInMsg ;
92- outMsg . BodyPart . Data = ms ;
9399
94- //Promote message type and SchemaStrongName
95- outMsg . Context . Promote ( new ContextProperty ( SystemProperties . MessageType ) , documentSpec . DocType ) ;
96- outMsg . Context . Promote ( new ContextProperty ( SystemProperties . SchemaStrongName ) , documentSpec . DocSpecStrongName ) ;
100+ //If the request has a body it should be preserved an the query parameters should be written to it's own message part.
101+ if ( hasData )
102+ {
103+ outMsg = pInMsg ;
104+ outMsg . BodyPart . Data = pInMsg . BodyPart . Data ;
105+ outMsg . Context = PipelineUtil . CloneMessageContext ( pInMsg . Context ) ;
106+ var factory = pContext . GetMessageFactory ( ) ;
107+ var queryPart = factory . CreateMessagePart ( ) ;
108+ queryPart . Data = ms ;
109+
110+ outMsg . AddPart ( "querypart" , queryPart , false ) ;
111+ }
112+ else
113+ {
114+ outMsg . BodyPart . Data = ms ;
115+ //Promote message type and SchemaStrongName
116+ outMsg . Context . Promote ( new ContextProperty ( SystemProperties . MessageType ) , documentSpec . DocType ) ;
117+ outMsg . Context . Promote ( new ContextProperty ( SystemProperties . SchemaStrongName ) , documentSpec . DocSpecStrongName ) ;
118+ }
97119
98120 _outputQueue . Enqueue ( outMsg ) ;
99121 _instrumentationHelper . TrackComponentSuccess ( ) ;
@@ -119,5 +141,23 @@ public IBaseMessage GetNext(IPipelineContext pContext)
119141
120142 return null ;
121143 }
144+
145+ private bool HasData ( Stream data )
146+ {
147+ byte [ ] buffer = new byte [ 10 ] ;
148+ const int bufferSize = 0x280 ;
149+ const int thresholdSize = 0x100000 ;
150+
151+ if ( ! data . CanSeek || ! data . CanRead )
152+ {
153+ data = new ReadOnlySeekableStream ( data , new VirtualStream ( bufferSize , thresholdSize ) , bufferSize ) ;
154+ }
155+
156+ int num = data . Read ( buffer , 0 , buffer . Length ) ;
157+ data . Seek ( 0 , SeekOrigin . Begin ) ;
158+ data . Position = 0 ;
159+
160+ return num > 0 ;
161+ }
122162 }
123163}
0 commit comments