Author |
Message
|
fjb_saper |
Posted: Wed Jan 03, 2018 7:15 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
zpat wrote: |
If your message is XML, and the MQMD.Format is MQSTR - you should code MQGMO_CONVERT on the MQ GET.
Assuming the message is a string and any binary data is encoded as BASE64 that is. |
I am not a fan on the MQGMO_CONVERT option because depending on the CCSID of the queue manager you could be loosing stuff...
I'd rather read a UTF-8 stream into a String than loose Chinese chars because the CCSID of the qmgr was 819 or 437... and I used convert...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Jan 03, 2018 7:44 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
scravr wrote: |
I got the msg.Encoding into integer and
String text = new String (BYTES, Encoding);
Generated chins chars.
Again msg generated on unix and java debug on windows.
What i am missing? |
You are missing the fact that XML Encoding and MQ Encoding are 2 completely different things. MQ Encoding describes numbers (little / big endian, floating point characteristics etc...) CCSID describes the coded CharSet Id.
XML Encoding is closest to CCSID. However if your message is MQ and the Blob parts should be 64 bit encoded in XML. Then you need to know once you have the original BLOB what kind of CCSID and encoding it was in when written...
Otherwise there is no transforming back into a String. It would just be guesswork. Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
zpat |
Posted: Wed Jan 03, 2018 7:51 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
fjb_saper wrote: |
zpat wrote: |
If your message is XML, and the MQMD.Format is MQSTR - you should code MQGMO_CONVERT on the MQ GET.
Assuming the message is a string and any binary data is encoded as BASE64 that is. |
I am not a fan on the MQGMO_CONVERT option because depending on the CCSID of the queue manager you could be loosing stuff...
I'd rather read a UTF-8 stream into a String than loose Chinese chars because the CCSID of the qmgr was 819 or 437... and I used convert...  |
With the MQ client, you can set the CCSID you want the message converted to - or use the default which is not in fact the QMGR CCSID, it is the platform default for the client (UTF-8 for JVM).
I don't think it' dangerous to use MQGMO_CONVERT with a MQ client providing you know which CCSID MQ is going to pick for you (and it's actually not the QMGR default CCSID). _________________ Well, I don't think there is any question about it. It can only be attributable to human error. This sort of thing has cropped up before, and it has always been due to human error. |
|
Back to top |
|
 |
scravr |
Posted: Wed Jan 03, 2018 4:18 pm Post subject: |
|
|
 Partisan
Joined: 03 Apr 2003 Posts: 391 Location: NY NY USA 10021
|
Here is a short description:
I have a flow geting MQ XML messages from multiple other flows. XML elements (acc-num, UID, dates...) are in char, and original-msg-body is BLOB
ESQL CASTs the BLOB to CHAR and inserts all into oracle:
...
...
DECLARE message CHARACTER '';
DECLARE msgInBlob BLOB '';
...
...
SET msgInBlob = inRef.MSG_BLOB;
SET message = CAST(msgInBlob AS CHARACTER CCSID InputRoot.Properties.CodedCharSetId);
...
...
INSERT INTO Database.oracle-table (........
I am trying to replace this flow with a stand-alowne JAVA, to get upto 1000 msgs and do oracle bulk insert.
I am looking for a java code to replace: SET message = CAST(msgInBlob AS CHARACTER CCSID InputRoot.Properties.CodedCharSetId);
What open Q options (for GET) and what options on GET itself do I need?
How in JAVA can I "cast" the BLOB?
How can I get the CCSID and CodePage in JAVA and use them in "translation" ?
See code at the begging of this thread. |
|
Back to top |
|
 |
abhi_thri |
Posted: Thu Jan 04, 2018 1:40 am Post subject: |
|
|
 Knight
Joined: 17 Jul 2017 Posts: 516 Location: UK
|
Hi...As CCSID & Encoding are part of the Properties tree I think it can be accessed as,
Code: |
MbElement header = inMessage.getRootElement().getFirstChild();
|
The header should now have the Properties tree as that is the first child of the Root msg. Once you've retrieved the ccsid and encoding you can use toBitStream function to convert it to String, eg:-
Code: |
MbElement _inRoot = inMessage.getRootElement();
MbElement _messageBody = _inRoot.getLastChild();//This is the message body
String _str = new String((byte[]) _messageBody.toBitstream("","","",<encoding>,<ccsid>,<options>));
|
Must admit that i'm no java expert, please refer to Java API for syntax details...https://www.ibm.com/support/knowledgecenter/en/SSMKHH_9.0.0/com.ibm.etools.mft.plugin.doc/index.html
Can I ask why you are planning to replace the message flow with java? Is it due to performance reasons, if so have you tried tuning/scaling up the flow (additional instances, commit count etc)?
Regards, Abhi |
|
Back to top |
|
 |
scravr |
Posted: Thu Jan 04, 2018 4:23 pm Post subject: |
|
|
 Partisan
Joined: 03 Apr 2003 Posts: 391 Location: NY NY USA 10021
|
I got the idea. XML and MQ are diff CCSID.
But still, I am looking for simple java sample to convert just the BLOB element in the XML msg.
This is JAVA stand-alone. Its NOT part of JCN.
So as in the begging of this thread, I got the whole msg into XML DOC, parsed it, and extract each element into String. Got the BLOB into Bytes.
Now: how do i convert this byte-BLOB to char?
Please respond with java sample of how to get CCSID, Encoding.... from msg and how to use java to convert.
samples....
samples....
samples....
samples....
samples....
samples.... |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Jan 05, 2018 10:54 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
scravr wrote: |
I got the idea. XML and MQ are diff CCSID.
But still, I am looking for simple java sample to convert just the BLOB element in the XML msg.
This is JAVA stand-alone. Its NOT part of JCN.
So as in the begging of this thread, I got the whole msg into XML DOC, parsed it, and extract each element into String. Got the BLOB into Bytes.
Now: how do i convert this byte-BLOB to char?
Please respond with java sample of how to get CCSID, Encoding.... from msg and how to use java to convert.
samples....
samples....
samples....
samples....
samples....
samples.... |
Well the MQ message has properties one of which is the CCSID.
Depending on whether you use MQ Base or JMS you will access these a little bit differently.
Once you have the CCSID from the message MetaData, you need to look at the correspondance table with the ccsid and the ccsidname used in Java for naming the character set... for the String method: new String(byte[] blob, String "ccsidname"); ... and don't forget to use syncpoint for your batches ....
Hope this helps...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
scravr |
Posted: Fri Jan 05, 2018 4:55 pm Post subject: |
|
|
 Partisan
Joined: 03 Apr 2003 Posts: 391 Location: NY NY USA 10021
|
How do I get " correspondance table with the ccsid and the ccsidname " ?
any specific java class/function to use?
what is the syncpoint about? |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Jan 05, 2018 8:29 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
scravr wrote: |
How do I get " correspondance table with the ccsid and the ccsidname " ?
any specific java class/function to use?
what is the syncpoint about? |
Syncpoint is about having a transacted session and running in a Unit of Work.
Think about commit points.
You will have to build the table. ex ccsid 819 = xxxx-1 where xxxx is something like ISO8859... 1208 = UTF-8 etc... You will have to look up what is available in Java as code sets. I believe that if you use JMS you have 2 properties:
JMS_CodedCharSetId and JMS_IBM_MQMD_CCSID (You'll have to look it up, this is from memory)... One will give you the Java form name the other the IBM number....
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
scravr |
Posted: Tue Jan 09, 2018 12:07 pm Post subject: |
|
|
 Partisan
Joined: 03 Apr 2003 Posts: 391 Location: NY NY USA 10021
|
I try converting BYTES with multiple ISO8859, iso8859, UTF-... but string stays as is.
String msg = new String (BYTES, "ISO...");
What else is missing?
BYTES is byte [] parsed from xml doc, eElement.getelementbytagname |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Jan 09, 2018 6:06 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
scravr wrote: |
I try converting BYTES with multiple ISO8859, iso8859, UTF-... but string stays as is.
String msg = new String (BYTES, "ISO...");
What else is missing?
BYTES is byte [] parsed from xml doc, eElement.getelementbytagname |
In XML a binary field is often either 64 bit encoded or hex encoded.  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|