Author |
Message
|
rsinha |
Posted: Mon Jan 10, 2005 10:58 am Post subject: more getJMSCorrelationID question |
|
|
Apprentice
Joined: 29 Aug 2003 Posts: 42
|
Hi,
I did search this forum for the related problem, but wasn't able to get a clear understanding of how to convert from hex correlId to a proper ascii char. My send application is using setJMSCorrelationID("0000"), the receive application, when does String correlID = getJMSCorrelationID(), displays following value -
ID:303030300000000000000000000000000000000000000000
Tried using following code to first convert the correlID to bytes and then toHexString()
// convert CorrelId character string into bytes
byte [] bytes = testString.getBytes();
StringBuffer sb = new StringBuffer();
for(int i = 0; i < bytes.length ; i++)
{
sb.append(Integer.toHexString(bytes[i]));
}
int correlationIDLength = 48;
int zerosToFill = correlationIDLength - sb.length();
for(int i = 0; i < zerosToFill; i++ )
{
sb.append("0");
}
This displays -
49443a333033303330333030303030303030303030303030303030303030303030303030303030303030303030303030303030
Which translates to -
hex char
---------------
49 I
44 D
3a :
33 3
30 0
33 3
30 0
As you can see, it still is in hex, in addition, it changed from orig value of "0000" to "30303030"
Can anyone explain how I can get the exact value of "0000" in correlID when I retrieve the message and its MQMD header?
Thanx |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Jan 10, 2005 11:08 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Correlation IDs are not "proper ascii chars".
They are fields that contain binary characters that may or may not map to useable, printable ascii characters. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
rsinha |
Posted: Mon Jan 10, 2005 11:21 am Post subject: |
|
|
Apprentice
Joined: 29 Aug 2003 Posts: 42
|
so what does that mean? when I don't use JMS to retrieve the correlID, when I simply use amqsbcg qname, the browser program that came with MQ, it clearly shows me the CorrelID field at MQMD header, containing the exact hex value for "0000".
StrucId : 'MD ' Version : 2
Report : 0 MsgType : 8
Expiry : -1 Feedback : 0
Encoding : 273 CodedCharSetId : 1208
Format : 'MQSTR '
Priority : 4 Persistence : 1
MsgId : X'414D512045324F50454E2E4445562E519F57DC4101030020'
CorrelId : X'303030300000000000000000000000000000000000000000'
So why can't JMS interpret it correctly?
Thanx |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Jan 10, 2005 11:47 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
What are you actually trying to do with your correlation ID? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Jan 10, 2005 11:50 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Read the manual
When the MsgID/CorrelID is in the provider's format it is rendered as:
"ID:" + hex representation of byte array.
Enjoy 
Last edited by fjb_saper on Mon Jan 10, 2005 11:52 am; edited 1 time in total |
|
Back to top |
|
 |
rsinha |
Posted: Mon Jan 10, 2005 11:52 am Post subject: |
|
|
Apprentice
Joined: 29 Aug 2003 Posts: 42
|
Our Trading Partner is sending some identifier in this field, which our application is supposed to retrieve and take some action based on the identifier (value) they've sent in correlID field.
Thanx |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Jan 10, 2005 11:56 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
You need to request the byte value of the partner's identifier from the partner.
If there is a platform change (as400 -> unix or pc) etc... the bytes are not converted from one CCSID to the other. (EBCDIC to ASCII).
You need to treat the information as bytes!
Enjoy  |
|
Back to top |
|
 |
rsinha |
Posted: Mon Jan 10, 2005 12:21 pm Post subject: |
|
|
Apprentice
Joined: 29 Aug 2003 Posts: 42
|
Yes, When I do getJMSCorrelationIDAsBytes(), that does give me the correct value of "0000", how ever, the partner is using some other charset, that we have no knowledge of. We use following code -
String correlId = new String(message.getJMSCorrelationIDAsBytes());
As you can seem, with String coversion, this code is assuming that the charset used in corelID is the default machine charset, which in our case is utf-8. But I know for sure that partner is using some othe charset, because using the above code when we check the correlId.length(), it give us 0. I think thats happening due to wrong charset conversion.
Thats why I wanted to use getJMSCorrelationID(), hoping that JMS would be smart enough to do the charset conversion from whatever the partner is sending, to utf-8. But in that case we are facing a different hurdle, the string is coming as a hex string, which is no good to us.
Thanx |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Jan 10, 2005 12:55 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
As stated before:
You CANNOT treat the msgID/correlationID fields as String fields.
They are byte arrays and will not be converted when the CCSID changes.
You need to request the byte[] value of the field as the sender put it in and compare to the same byte[].
Enjoy |
|
Back to top |
|
 |
|