Author |
Message
|
ktg |
Posted: Thu Jun 24, 2010 2:00 am Post subject: C Custom node: How to convert incoming message to C string |
|
|
Centurion
Joined: 09 Jan 2006 Posts: 138 Location: India
|
Hi,
Am writing a UDN(user defined node) in C as we need to communicate with a 3rd party system. 3rd party system provides only C APIs for interaction. The incoming message will be in CSV(Comma seperated values) format which is to be used by custom node to send request to external server. The incoming CSV string has to be partially parsed by user defined node and partial/full csv string has to be passed AS A PARAMETER to C functions. The parameter for the function is of type (char *). How to convert incoming message data to (char *)?
The external system hosts various services. For each service we have corresponding message set. One option we have for getting the concatenated CSV string is, UDN need to parse the incoming message tree(using message set) one by one and adding comma after each element.
Is it the only way or is there is any simpler/better method to achive this?
Please, help.
Thanks,
Kalpana |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Jun 24, 2010 2:46 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
The message that is passed to the UDN should already be constructed in such a way that the UDN does not have to do extensive transformation of it to meet the needs of the node.
The MRM-TDS parser is ideally suited for handling CSV data formats and can easily convert a CSV structure into a logical message tree and can also easily convert a properly built logical message tree into a CSV structure.
A C language (char *) structure is technically defined as a pointer to a char variable. It is usually used as a pointer to a char[] array of characters, and thus a "string". You can easily convert between a char* and a CciString object using the UDN C API's.
You need to go review all of the documentation under this topic:
http://publib.boulder.ibm.com/infocenter/wmbhelp/v7r0m0/index.jsp?topic=/com.ibm.etools.mft.doc/as37484_.htm
Read it through a couple of times. Your questions do not indicate a good understanding of the information there. |
|
Back to top |
|
 |
ktg |
Posted: Thu Jun 24, 2010 3:07 am Post subject: |
|
|
Centurion
Joined: 09 Jan 2006 Posts: 138 Location: India
|
Thanks for the reply.
Actually both questions are w.r.t same issue.
I know conversion between char* and CciString. But, inside UDN, I can access message only as type CciElement/CciMessage. (CciElement Name and values can also be extracted). The question is, is there way or function to convert from Element to CciString/Char * |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Jun 24, 2010 4:59 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Yes. There is an entire set (or do I mean group?) of method calls to retrieve the contents of a CciElement. |
|
Back to top |
|
 |
jml |
Posted: Thu Jun 24, 2010 7:11 pm Post subject: |
|
|
Newbie
Joined: 17 Sep 2008 Posts: 4
|
Use the function cniElementAsBitstream,you can find it in the include file BipCni.h. |
|
Back to top |
|
 |
ktg |
Posted: Thu Jun 24, 2010 8:57 pm Post subject: |
|
|
Centurion
Joined: 09 Jan 2006 Posts: 138 Location: India
|
Yes, there are functions to get value of CciElement like CniElementBitArrayValue, cniElementBooleanValue, cniElementCharacterValue etc., These functions gets the value in the form of (struct CciBitArray*), (CciBool), (CciChar* ) respectively. As I will be sending CSV, i tried to retrive the value as (CciChar* ) using CniElementCharacterValue. But it is not working.
The function cniElementAsBitstream gets the value as (struct CciByteArray*). Again there is no function to convert from (struct CciByteArray*) to (char *)
Btw, I am using blob parser. |
|
Back to top |
|
 |
smdavies99 |
Posted: Thu Jun 24, 2010 9:28 pm Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
I'm sure the readers of this forum would be interested in why you have chosen this path (UDN) rather than using an existing mechanism to parse & format your message.
CSV generation are there in Broker (and have been since at least 2.0.1 days) _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
ktg |
Posted: Thu Jun 24, 2010 10:15 pm Post subject: |
|
|
Centurion
Joined: 09 Jan 2006 Posts: 138 Location: India
|
I didnt get your question exactly.
If you are asking what is the need of writing UDN?
Am writing a UDN(user defined node) in C as we need to communicate with a 3rd party system. 3rd party system provides only C APIs for interaction. The incoming message will be in CSV(Comma seperated values) format which is to be used by custom node to send request to external server. The incoming CSV string has to be partially parsed by user defined node and partial/full csv string has to be passed AS A PARAMETER to C functions. The parameter for the function is of type (char *).
If you are asking why I am trying for a function to get incoming csv as (char *) instead of parsing Element tree using message set parser?
I thought parsing the tree and extracting element by element would be tedious. At least, I want to make sure that is the ONLY way. |
|
Back to top |
|
 |
smdavies99 |
Posted: Thu Jun 24, 2010 11:41 pm Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
ktg wrote: |
If you are asking why I am trying for a function to get incoming csv as (char *) instead of parsing Element tree using message set parser?
I thought parsing the tree and extracting element by element would be tedious. At least, I want to make sure that is the ONLY way. |
Yep, that was what I was asking.
You seem to be wanting to do some mapping between the input model and the message model that the 3rd party app requires.
This is one of the areas where Broker excells. Look at what the Mapping Node can do for you especially in you have the message model that the 3rd party app requires. (you do have this don't you?)
Developing the mapping might indeed be tedious if done in broker but it will be (IMHO) far easier than trying to roll your own in C inside a UDN. Using a 'stub' UDN that sends the data passed to is to a trace file would be the way I'd go. This way, you can really be sure that the data you are sending is right before you get into the troubles you are probably going to encounter with the 3rd part API inside the UDN.
KISS really applies here. _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
ktg |
Posted: Fri Jun 25, 2010 12:21 am Post subject: |
|
|
Centurion
Joined: 09 Jan 2006 Posts: 138 Location: India
|
Mapping required to convert data to the format required by 3rd party system is done using mapping node.
After that, converted message would be passed to UDN. I would get data in UDN as CciMessage type which will be having data in CSV format. Now I need to create a (char *) corresponding to the in coming message and pass it to a function provided by 3rd party system.
How to get that CSV string from CciMessage is my question
Thanks,
Kalpana |
|
Back to top |
|
 |
mgk |
Posted: Fri Jun 25, 2010 12:44 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Lookup cniElementAsBitstream in the docs, topic as07885.
Regards, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
ktg |
Posted: Fri Jun 25, 2010 12:47 am Post subject: |
|
|
Centurion
Joined: 09 Jan 2006 Posts: 138 Location: India
|
The function cniElementAsBitstream gets the value as (struct CciByteArray*). Again, there is no function to convert from (struct CciByteArray*) to (char *)
Thanks,
Kalpana |
|
Back to top |
|
 |
mgk |
Posted: Fri Jun 25, 2010 1:12 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
But that byte array is the hexbinary version of your whole message. Once you have that you can easily write code in C to convert that to char*... _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
ktg |
Posted: Fri Jun 25, 2010 4:04 am Post subject: |
|
|
Centurion
Joined: 09 Jan 2006 Posts: 138 Location: India
|
Thanks for the reply. It made me to think further in that direction and I got it working
Here is the code snippet
Code: |
{
struct CciByteArray *Blob = NULL;
char *msgData;
Blob = (struct CciByteArray *)malloc(sizeof(struct CciByteArray));
Blob->pointer = (char *)malloc(sizeof(char) * 10240);
Blob->size = 10240;
blobSize = cniElementByteArrayValue(&rc, blobElement, Blob);
fprintf(outputFile, "%d = cniElementByteArrayValue rc = %d\n", blobSize, rc);
fflush(outputFile);
msgData = (char *) malloc (Blob->size + 1);
memcpy(msgData, (char *)Blob->pointer, Blob->size);
msgData[Blob->size] = '\0';
fprintf(outputFile, "elementValue = %s ",msgData );
fflush(outputFile);
}
|
Thanks for all the inputs
Kalpana |
|
Back to top |
|
 |
|