Disassembler weirdness
hi
finally getting this....
i have created disassembling component using xmltextreader, streamwriter and virtualstream after solicitng advice several helpful folks here. i've followed several examples blogs , component outputs want when test using pipeline.exe. when use in actual pipeline on receive location, bombs message:
"a body part or part same name has been added message. message can have 1 body part , part names must unique. "
my goal able take message this, instance pipeline property used specify node split on "order" in case:
<root someattribute='value' xmlns='value'>
<order/> - bunch of subnodes
<order/>- bunch of subnodes
</root>
and create this:
<root someattribute='value' xmlns='value'>
<order/>- bunch of subnodes
</root>
<root someattribute='value' xmlns='value'>
<order/>- bunch of subnodes
</root>
i have reviewed code , added diagnostics , still not understand why blows up. appears happen in getnext seems called once. below meat of i'm doing error checks , null checks removed
private system.collections.queue _msgs = new system.collections.queue(); private object _debatchnode; private string _documentroottag = string.empty; private string _documentrootclosetag = string.empty;
public
void disassemble(microsoft.biztalk.component.interop.ipipelinecontext pc, microsoft.biztalk.message.interop.ibasemessage inmsg){
xmltextreader originalmessage = null;system.diagnostics.
debug.writeline("disassemble entered"); try{
//error checks //read message streamreader , write out wrapper (wraps each message) member var.originalmessage =
new xmltextreader(inmsg.bodypart.data);originalmessage.whitespacehandling =
whitespacehandling.all;originalmessage.normalization =
false;system.diagnostics.
debug.writeline("split on " + this._nodenametodebatchon); this._debatchnode = originalmessage.nametable.add(this._nodenametodebatchon); //read copy of stream while (originalmessage.read()){
//build rootnode if ((originalmessage.nodetype == xmlnodetype.element) && (originalmessage.isstartelement()) && (originalmessage.depth == 0)){
//build root namespace, name, , attributes this._documentrootclosetag = "</" + originalmessage.name + ">"; this._documentroottag = this.messagenodebuilder(originalmessage);}
//check desired debatch node if (originalmessage.nodetype == xmlnodetype.element && object.referenceequals(originalmessage.name, this._debatchnode)) this.messageextractbuilder(pc, inmsg, originalmessage);}
}
catch (exception oex){
throw (oex);}
finally{
if (originalmessage != null)originalmessage.close();
}
}
public microsoft.biztalk.message.interop.ibasemessage getnext(microsoft.biztalk.component.interop.ipipelinecontext pipelinecontext)
{
// next message queue , return itmicrosoft.biztalk.message.interop.
ibasemessage msg = null;system.diagnostics.
debug.writeline("checking messages"); //return next available msg if (_msgs.count > 0){
msg = ((microsoft.biztalk.message.interop.
ibasemessage)(_msgs.dequeue()));msg.bodypart.data.position = 0;
system.diagnostics.debug.writeline("returning message: " + msg.bodypart.data.length);}
return msg;}
private void copyallmsgparts(ibasemessage sourcemessage, ibasemessage destinationmessage, ibasemessagepart newbodypart)
{
string bodypartname; ibasemessagepart messagepart; string partname; try{
bodypartname = sourcemessage.bodypartname;
for (int part = 0; part < sourcemessage.partcount; ++part){
partname =
null;messagepart = sourcemessage.getpartbyindex(part,
out partname); if (partname != bodypartname)destinationmessage.addpart(partname, messagepart,
false); elsedestinationmessage.addpart(bodypartname, newbodypart,
true);}
}
catch (exception oex){
throw (oex);}
finally{
bodypartname =
null;messagepart =
null;partname =
null;}
}
private
void messageextractbuilder(ipipelinecontext pc, ibasemessage inmsg, xmltextreader msgreader){
streamwriter messagewriter = null; virtualstream newmessage = null; string msgtext = string.empty; try{
system.diagnostics.
debug.writeline("creating new message"); //create stream write our message tonewmessage =
new virtualstream(virtualstream.memoryflag.autooverflowtodisk); //create message stringmsgtext =
this._documentroottag + msgreader.readouterxml() + this._documentrootclosetag; //create writermessagewriter =
new streamwriter(newmessage, encoding.unicode, msgtext.length);messagewriter.write(msgtext);
//create messagepart ibasemessagepart bodypart = pc.getmessagefactory().createmessagepart();bodypart.partproperties = inmsg.bodypart.partproperties;
newmessage.position = 0;
bodypart.data = newmessage;
//flush streammessagewriter.flush();
//create message ibasemessage outmsg = pc.getmessagefactory().createmessage();outmsg.context = inmsg.context;
outmsg.addpart(
"body", bodypart, true); this.copyallmsgparts(inmsg, outmsg, bodypart);system.diagnostics.
debug.writeline("message enqueued: " + bodypart.data.length); //put message in queue_msgs.enqueue(outmsg);
//see if should recurse readouterxml have moved reader forward next node if (msgreader.nodetype == xmlnodetype.element && object.referenceequals(msgreader.name, this._debatchnode)) this.messageextractbuilder(pc, inmsg, msgreader);}
catch (exception oex){
if (messagewriter != null)messagewriter.close();
throw (oex);}
finally{
}
}
when run debugview on sample message should split into 2 messages, can see i've created 2 messages in messageextractbuilder() , added them queue. appears getnext() called once , bring correct 1st extracted message dies error message above. hat seems indicate never got debatched, show whole, predebatched message. againm, works fine, 2 spearate messages when use pipeline.exe test. missing here?
thanks in advance
BizTalk Server > BizTalk Server General
Comments
Post a Comment