Try to send the JSON stream from Process to Operation and generate file
I created the Process to extract the required data from ADT message to a Dynamic Object. I wanted to send the JSON stream to EnsLib.File.PassthroughOperation operation and generate a file with the content of JSON stream.
Here are the codes for Process:
set oMetadata = ... /// metadata is from ADT message which is dynamic object
set jsonRequest = ##class(%ZEN.Auxiliary.jsonProvider).%ObjectToJSON(oMetadata)
set tSC = ..SendRequestAsync(..JSONOperation,jsonRequest,0,,..MetadataContext) /// send the jsonRequest to operation
Here are the errors in the operation: "ERROR <Ens>ErrGeneral: No MessageBody classname for MessageHeader"
I know there is no such messagebody class for the jsonRequest as it is a custom object. My question is how I should do to create the message body for the custom jsonRequest and how to generate a file with this jsonRequest content in the operation that utilizes EnsLib.File.PassthroughOperation or other proper class?
What version are you on?
Hi Eduard,
I am using healthshare 2017.1.1 version.
Thanks so much Eduard. Your answer is really helpful.
Hi Eduard,
I got another question for you: once I create the Json stream from dynamic object and send it to the operation, I got the message body as follows:
<StreamContainer><Stream>{
"_class":"%Library.DynamicObject"
}</Stream><Type>BG</Type></StreamContainer>
, which is totally different from what I have in the dynamic object. The dynamic object is supposed to have several key-value pairs like:
{"a": "1", "b": "2", ...}
. How could I get the correct content from that JSON stream? Thanks so much.
Your "SendRequestAsync" method is only available for Process.
And to be purist, in that case, it must be:
set tSC = ..SendRequestAsync(..JSONOperation,stream,"0",,..MetadataContext) /// send the stream to operation
Nothing to do with the reponse parameter.
Best Regards.
%ObjectToJSON writes stream to current device. You need to write to stream:
set oMetadata = ... /// metadata is from ADT message which is dynamic object set stream = ##class(%Stream.GlobalCharacter).%New() set tSC = ##class(%ZEN.Auxiliary.jsonProvider).%WriteJSONStreamFromObject(stream, oMetadata) quit:$$$ISERR(tSC) tSC set request = ##class(Ens.StreamContainer).%New(stream) set tSC = ..SendRequestAsync(..JSONOperation,stream,0,,..MetadataContext) /// send the stream to operation
And your JSONOperation should be able to accept messages of Ens.StreamContainer class.
I just checked Ens.BusinessService:SendRequestAsync signature and it's:
Method SendRequestAsync(pTargetDispatchName As %String, pRequest As %Library.Persistent, pDescription As %String = "") As %Status
So maybe the last line should be just:
set tSC = ..SendRequestAsync(..JSONOperation, stream)
Finally, use %ZEN.Auxiliary.altJSONProvider instad of %ZEN.Auxiliary.jsonProvider. It's faster.
Can you please provide the code to initialize sample oMetadata object?
SendRequestAsync is available in all Ensemble Hosts (Services, Operations, Processes).
For Operations and Services the signature is:
Method SendRequestAsync(pTargetDispatchName As %String, pRequest As %Library.Persistent, pDescription As %String = "") As %Status
And for Processes the signature is:
Method SendRequestAsync(pTargetDispatchName As %String, pRequest As Request, pResponseRequired As %Boolean = 1, pCompletionKey As %String = "", pDescription As %String = "") As %Status