ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » General Discussion » Printing changing the correlation-Id from Byte to String

Post new topic  Reply to topic
 Printing changing the correlation-Id from Byte to String « View previous topic :: View next topic » 
Author Message
starki78
PostPosted: Tue Oct 07, 2008 8:21 am    Post subject: Printing changing the correlation-Id from Byte to String Reply with quote

Acolyte

Joined: 24 Sep 2007
Posts: 53

Hi

I've that urgent request.

1. sending the correlation-id with binary to queue
String str = "000000000000000000000000000000000000000000081DA1";

mBuf.correlationId = str.getBytes();

2. Extracting it:

MQQueue q1 = qMgr.accessQueue(queuereceive, getqOpenOptions, null, null, null);
q1.get(rcvMessage,gmo);

3. Converting the byte to Sting.
System.out.println(new String(rcvMessage.correlationId));


This is what I get:
000000000000000000000000


Please help me finding the error

Thanks
Christian
Back to top
View user's profile Send private message
elvis_gn
PostPosted: Tue Oct 07, 2008 10:05 am    Post subject: Reply with quote

Padawan

Joined: 08 Oct 2004
Posts: 1905
Location: Dubai

Hi starki78,

Look up the MQ Samples on the IBM Website...there are samples related to MessageId and CorrelationId where you'll find Hex conversion code.

Regards.
Back to top
View user's profile Send private message Send e-mail
atheek
PostPosted: Wed Oct 08, 2008 1:58 am    Post subject: Reply with quote

Partisan

Joined: 01 Jun 2006
Posts: 327
Location: Sydney

For (1) you need to do hex string to byte array conversion

For (3) you need to do byte array to hex string conversion

Sample piece of code from google:

Hex String to Byte Array

Code:
public static byte[] toBinArray( String hexStr ){
       byte bArray[] = new byte[hexStr.length()/2]; 
       for(int i=0; i<(hexStr.length()/2); i++){
          byte firstNibble  = Byte.parseByte(hexStr.substring(2*i,2*i+1),16); // [x,y)
          byte secondNibble = Byte.parseByte(hexStr.substring(2*i+1,2*i+2),16);
          int finalByte = (secondNibble) | (firstNibble << 4 ); // bit-operations only with numbers, not bytes.
          bArray[i] = (byte) finalByte;
       }
       return bArray;
   }


Byte Array to Hex String

Code:
static char[] hexChar = {
           '0' , '1' , '2' , '3' ,
           '4' , '5' , '6' , '7' ,
           '8' , '9' , 'A' , 'B' ,
           'C' , 'D' , 'E' , 'F'
   };
 
   public static String toHexString ( byte[] b ) {
       StringBuffer sb = new StringBuffer( b.length * 2 );
       for ( int i=0; i<b.length; i++ ) {
           // look up high nibble char
           sb.append( hexChar [( b[i] & 0xf0 ) >>> 4] ); // fill left with zero bits
 
           // look up low nibble char
           sb.append( hexChar [b[i] & 0x0f] );
       }
       return sb.toString();
   }
Back to top
View user's profile Send private message
meetgaurav
PostPosted: Sun Dec 14, 2008 8:41 am    Post subject: For Testing Purpose Reply with quote

Voyager

Joined: 08 Sep 2008
Posts: 94

Hi

For testing purpose I need to set the message id and Corel id as

MsgId =NSC123
CorrelId =BSC123 from JAVA API or JMS API..

In JMS API I can able to set the coreel id and the msg id is generated by QMGR to some unique one and not NSC123..

In Java API not able to convert it to byte char. Since 'N' and 'S' are not an Hexadecimal

Please assist me
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Sun Dec 14, 2008 11:39 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

Best practice says you let the qmgr set msgId and CorrelId....
MQJMS adheres to best practice and you will never be allowed to set the msgId.

Anyways... here it goes.
Get an array of byte[24] that you initialize with x00 for each byte.
String myString = "NSB123";
byte[] mystartbytes=myString.getBytes();
You overwrite the first bytes of your initialized array with mystartbytes...

And remember a byte is a byte is a byte... so it NEVER gets translated from one platform to the other or one CCSID to the other!!


Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
bruce2359
PostPosted: Sun Dec 14, 2008 2:43 pm    Post subject: Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 9469
Location: US: west coast, almost. Otherwise, enroute.

And remember a byte is a byte is a byte...
Which means that it is not character; and therefore does not conform to a coded character set id (CCSID).
_________________
I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live.
Back to top
View user's profile Send private message
meetgaurav
PostPosted: Mon Dec 15, 2008 1:32 am    Post subject: Reply with quote

Voyager

Joined: 08 Sep 2008
Posts: 94

I tried this but not able to do that.. could you please give me the extact code what you were guided me to do??
Back to top
View user's profile Send private message
meetgaurav
PostPosted: Thu Dec 18, 2008 10:47 pm    Post subject: Reply with quote

Voyager

Joined: 08 Sep 2008
Posts: 94

I tried but this is not working.. Could you please assist me

byte [] test = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte[] mystring = msgId.getBytes();

byte[] msg1 = new byte[mystring.length];
for(int i=0;i<msg1.length;++i)
mystring[i] = (byte)(test[i]);

msg.messageId = mystring;
msg.correlationId = mystring;
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Fri Dec 19, 2008 9:25 am    Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3264
Location: London, ON Canada

meetgaurav wrote:
I tried but this is not working.. Could you please assist me

Code:
byte [] test = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte[] mystring = msgId.getBytes();

byte[] msg1 = new byte[mystring.length];
for(int i=0;i<msg1.length;++i)
   mystring[i] = (byte)(test[i]);

msg.messageId = mystring;
msg.correlationId = mystring;


What in the world are you doing?

Code:
for(int i=0;i<msg1.length;++i)
   mystring[i] = (byte)(test[i]);

This just copies 0x00 to every byte of "mystring" (because that is all that test contains).

Use the toHexString() method that atheek gave you.

If you only want to save then reuse the MsgId then just do:
Code:
byte[] savedMsgId = msgId.getBytes();

...

msg.correlationId = savedMsgId;


Regards,
Roger Lacroix
Capitalware Inc.
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » General Discussion » Printing changing the correlation-Id from Byte to String
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.