Mirth: overwriting msg object with contents in an XML object - e4x

The task is to send an XML object from Channel-A to Channel-B
<MyMessage>
<ID>42</ID>
<hl7v2>
MSH|^~\&|LAB|....
PID|1|....
</hl7v2>
</MyMessage>
The steps of the channel communication:
in the Channel-B's source transformer, extract the HL7v2 contents
OVERWRITE the current msg object in Channel-B with the extracted contents
continue in the other Channel-B source transformers and expecting to reference msg['PID']['PID.5'] as normal.
The good news is that I can extract the HL7v2 'payload' into a variable. The problem or difficulty is resetting the msg object, or any other object to be able to reference the HL7 properties as expected.
When I create a new variable with the SerializerFactory.getHL7Serializer, it wraps with the tags <HL7Message>.
channelMap.put('MessageID', msg['ID']); //successful
channelMap.put('v2payload',msg['HL7v2']); //also looks good
var v2Msg = SerializerFactory.getHL7Serializer(false,false,true).toXML(msg['HL7v2']);
channelMap.put('v2Msg', v2Msg );
link to full size image
Question: Do you have any suggestions on how to overwrite the msg object?
How can I start referencing the msg as such:
msg['PID']['PID.5']
Current Conditions
the receiving channel's input type is XML
the need is to take extract all the properties from that XML object; ID is a database PK to be used later in the destination.

I'm sorry my original answer was bogged down with the peculiarities of my own scenario. I have reworked and tested to ensure that this works in your scenario.
Sending Channel - wraps the raw hl7 into your xml structure, and forwards to a channel called ReceiveXML. I have coded this in the Source Transformer, but you should code it where it works for you.
var wrappedHL7 = <MyMessage><ID>123</ID>
<hl7v2>{messageObject.getRawData()}</hl7v2>
</MyMessage>;
router.routeMessage("ReceiveXML", wrappedHL7);
Receiving Channel - extracts the hl7 from the xml, converts it to xml, and assigns back to the msg object. I have coded this in the source Filter - hence "return true;"
msg = new XML(SerializerFactory.getHL7Serializer(false,false,true).toXML(msg['hl7v2'].toString()));
return true;

All you have to do is put your incoming xml message into the inbound template area in mirth and then use the message tree to drag and drop the info from the XML that you need to the javascript section of the connector.

Related

Where is the structure for payload of netlink message defined for NETLINK_XFRM socket

I am running strongswan daemon to perform IKEv2 messaging.
I wrote some python code to be notified everytime any xfrm change happens.
The socket is created like so:
my_socket = socket.socket(socketAF_NETLINK, socket.SOCK_RAW, socket.NETLINK_XFRM)
I receive and decode the nlmsghdr structure defined in ./uapi/linux/netlink.h like so:
while True:
data = my_socket.recv(65535)
msg_len, msg_type, flags, seq, pid = struct.unpack("=LHHLL", data[:16])
print msg_type
This works fine, I get the message type every time an new SA is made or updated or deleted.
Now, I attempt to decode the payload of this message, but I cannot locate the structure in linux to decode it with.
There is a file called uapi/linux/xfrm.h but I am not sure if this file contains the payload structure.
Can someone share where the payload structure is defined for xfrm netlink messages?
uapi/linux/xfrm.h is indeed the file you needed. struct xfrm_usersa_info is the struct you're looking for

How to send multiple json body using jmeter?

I have written a REST API and now my requirement is to send the multiple JSON body to the API using POST method from JMeter. I have a csv file with four values(1,2,3,4). And in each of the four files I have the JSON body. I used :
Step-1) added the csv file to jmeter and create a reference and named it JSON_FILE
Step-2) ${__FileToString(C:Path_to_csv_file/${__eval(${JSON_FILE})}.txt,,)}
But from this I am able to access only first file i.e which is named with one. How do I send the body of all file to the API?
Help is highly appreciated.
You won't be able to use CSV Data Set Config as it will read the next value for each thread (virtual user) and/or Thread Group iteration.
If your requirement is to send all the files bodies at once you can go for an alternative approach
Add JSR223 PreProcessor as a child of the HTTP Request sampler which you use for sending the JSON payload
Put the following code into "Script" area:
def builder = new StringBuilder()
new File('/path/to/plans.csv').readLines().each { line ->
builder.append(new File(line).text).append(System.getProperty('line.separator'))
}
sampler.getArguments().removeAllArguments()
sampler.addNonEncodedArgument('', builder.toString(), '')
sampler.setPostBodyRaw(true)
the above code iterates through entries in plans.csv file, reads the file contents into a string and concatenates them altogether. Once done it sets the HTTP Request sampler body data to the generated cumulative string.
Check out The Groovy Templates Cheat Sheet for JMeter to learn more and what else could be achieved using Groovy scripting in JMeter.
Use Body data as follows in HTTP Sampler:
{__FileToString(${JSON_FILE},,)}
You have to put all the file path in your plan.csv file. At each line, there should be a file path.
Example:
Suppose, you have 4 files with JSON body which you want to use in your HTTP sampler.
Give the file path of these 4 files in your CSV file which is plan.csv. Each line contains a file path like this:
/User/file/file1.json
/User/file/file2.json
/User/file/file3.json
/User/file/file4.json
Now, in your CSV data set config, Use the proper file name of CSV file which contains all the file path and give it a variable name like JSON_FILE.
Now, Use {__FileToString(${JSON_FILE},,)} this line in your Body data. Also use the loop count value accordingly.

How to Send multiple request concurrently/Sequentially in postman with different set of values for each request?

For example, below is the JSON request data to "add a device" in the DB.
For example, I want to add 10000 devices with different IMEI number and different phone number to the server for testing purpose. So, how to send the request at once.
I'm ready to create 10000 devices data with different values manually.
Now I can able to send one by one only.But how to send all the request at once?
{
"device_name":"34793812453274392",
"imei_num":"36xxxxxxxxxxxx5",
"phone_num":"8666606451",
"device_city":"Chennai",
"device_state":"Tamil Nadu",
}
As I'm new to POSTMAN, required detailed info. Thanks in advance.
The thing that should work is :
you prepare your input JSon body with variables. ie, from your example :
{ "device_name":{{device_name}}, "imei_num":{{imei_num}}, "phone_num":{{phone_num}}, "device_city":{{device_city}}, "device_state":{{device_state}}, }
the {{}} is for variables
You create a CSV file with the corresponding headers (one for each variable of your input JSON) and all the values you need:
example:
line 1 : device_name, imei_num, phone_num, device_city, device_state
line 2 : "34793812453274392", "36xxxxxxxxxxxx5", "8666606451", "Chennai", "Tamil Nadu"
... and so on ...
line 10000 : ...
Then, in the Postman runner (see here ), you select the data file (Data / Select file) with CSV type (you should have an option to check the content, but be careful as you'll have a lots of rows, it may take a long time, I suggest you try first with a small CSV file)
You just set ONE iteration (otherwise you'll play x times 10000 requests).
It will parse your file and, for each data line, it will send your request with replacing the body's variables by the corresponding data associated to the corresponding header. Header names must have the same label as your variables.
Launching the runner will launch your 10000 requests sequentially
If you prefer, you can use JSON input file as data file, see here
Don't hesitate to have a look at postman documentation, it's pretty complete.
There is an option called Runner at the top left corner of your Postman application. You can select the collection you need to run with number of iterations and delay time between each request. But the thing is you cannot alter the values inside the JSON request. Thanks
Put all the data into a JSON Array
and then do them all as one post. Currently you only have one set of data you're posting in.
Just create a json body with all the data you need to enter and post them into the same API endpoint.

Aggregation Correlation Strategy based on XML Payload

Issue: How to correlate messages for an aggregator based on a XML value in the payload? I have a scenerio where I call a third party application and it only gives back an xml response. Based on an xml value in the payload I would like to correlate the messages to produce a single response back to the consumer.
Example using Header Attribute
#CorrelationStrategy
public Object correlate(Message message) throws JMSException {
return message.getHeaders().get("JMSXUserID");
}
Solution Notes:
As described below and referenced in the spring documentation for xml payload support.
http://docs.spring.io/spring-integration/reference/html/xml.html#xpath-spel-function
Sample Config Applied:
<aggregator
id="agg"
input-channel="jmsInChannel"
output-channel="outputChannel"
ref="AggregatorPOJO"
method="combineResponesMessages"
correlation-strategy-expression="#xpath(payload, '/test/name')"
release-strategy="AggregatorPOJO"
release-strategy-method="isComplete"/>
This will correlate the following xml.
<test><name>test1</name></test>
Take a look if #xpath() SpEL function can help you, for example:
correlation-strategy-expression="#xpath(payload, '/name')"
where payload is a payload in some XML representation of messages to correlated and /name is an XPath against that payload.
You should be sure that spring-integratrion-xml jar is on your CLASSPATH.
You would have to parse the XML; you might be able to use a simple regex Pattern or you might have to convert the payload to a DOM for more complex situations.

Verifying/testing the output of mime4j parsed content

I am creating a tool that is required to parse incoming MIME streams and return the email body and email attachments as separate file streams.
I am using mime4j for this purpose.
Following are the problems that I am stuck on:
How can I test whether the email body file or email attachment file that I parsed out via mime4j from MIME stream is correct?
I have a large corpus of emails available in raw mime form that I want to run my tests on and need some automated way to determine which ones might be breaking the mime parsing by mime4j and tweak the code for that.
You could decode the attachments and then re-encode them. If the re-encoded stream matches (byte-for-byte) the original, then that's a good sign that mime4j is properly handling them.
I initially parsed out a sample corpus *.eml files using mime4j. I had to manually check them for parsing errors as I had no other good choice.
Now I am using the earlier parsed out emails as testbed over which I check my parsed out results iteratively.