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 » IBM MQ Java / JMS » JMS - correlation ID

Post new topic  Reply to topic
 JMS - correlation ID « View previous topic :: View next topic » 
Author Message
mnicolls
PostPosted: Mon Aug 08, 2005 1:54 pm    Post subject: JMS - correlation ID Reply with quote

Newbie

Joined: 08 Aug 2005
Posts: 2

When I am using JMS and I set a correlation ID that happens to contain characters above 128 in the ASCII chart something strange happens. If you look at the output below you sill see that the ascii characters "231" which the ID starts with are interpreted just fine but beyond those first three characters what goes in is not interpreted as I expect. The other characters are all wrong and the mqmd correlation id and doesn't have all the characters that the jms correlation id show. At some point it gets truncated. Any Ideas?

correlation id in java code set to =
(ascii) "231ððóóóòôùøøõôùóð@@@@@"
(hex) 32 33 31 f0 f0 f3 f3 f3 f2 f4 f9 f8 f8 f5 f4 f9 f3 f0 40 40 40 40 40

mqmd Correl Id =
(ascii) "231ððóóóòôùøøÃ"
(hex) 32 33 31 c3 b0 c3 b0 c3 b3 c3 b3 c3 b3 c3 b2 c3 b4 c3 b9 c3 b8 c3 b8 c3

jms correlation id =
(ascii) "231ððóóóòôùøøõôùóð@@@@@"
(hex) 32 33 31 c3 b0 c3 b0 c3 b3 c3 b3 c3 b3 c3 b2 c3 b4 c3 b9 c3 b8 c3 b8 c3 b5 c3 b4 c3 b9 c3 b3 c3 b0 40 40 40 40 40
Back to top
View user's profile Send private message
EddieA
PostPosted: Mon Aug 08, 2005 1:58 pm    Post subject: Reply with quote

Jedi

Joined: 28 Jun 2001
Posts: 2453
Location: Los Angeles

Quote:
Any Ideas

Yes. Do NOT try and interpret/use the CorrelationID as a string. It is a byte stream.

Cheers,
_________________
Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0
Back to top
View user's profile Send private message
mnicolls
PostPosted: Tue Aug 09, 2005 7:04 am    Post subject: It is a byte stream Reply with quote

Newbie

Joined: 08 Aug 2005
Posts: 2

Thanks for the reply Eddie. I appreciate the response, but telling me not to evaluate the byte stream is like telling me that despite things not working I really don't have a problem. If you can suggest a different way then that would be cool!

The tool that we use to look at the message shows us the mqmd correlation id and the jms correlation id. They should match, and they do under some circumstances (when I send and receive messages only in java . The times they don't is when a message is placed on a queue from COBOL (EBCDIC) then picked up in our Java application (ASCII). The Java app 'gets' the correclation id, creates a new message and 'sets' the correlation id of the new message to be that of the old message.

Since the alpha-numeric characters used in the ebcdic message are in the extended ascii range (above 128) we end up dealing with the extended ascii set as you see in my initial posting.

For some reason when the 'µ' character is encountered in the mqmd correl id it and no other characters beyond it are held. For the jms correlation id all the characters persist.

Also I have no other means to set the jms correlation id than via the method that takes a string, so I can't 'get' the correlation id as a byte stream and move that byte stream into the 'set' on the new message (not that I believe it would matter).

Lastly, since the only way I know of to set the correlation id is with a setter taking a string I pass it "231ððóóóòôùøøõôùóð@@@@@" as this is what equates to the cobol/ebcdic id.

If there is a better way to do this I'm all for it.

Thanks for your support - Michael
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Tue Aug 09, 2005 7:10 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

If you do a search here, for correlation ID, you will find probably at least three messages that have actual code for doing exactly what you need to do.

And at least three messages that point people asking similar questions at the sample code provided by IBM, along with a direct link to that sample code.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
HMed
PostPosted: Fri Sep 09, 2005 8:38 am    Post subject: JMS - correlation ID Reply with quote

Novice

Joined: 17 Sep 2004
Posts: 17
Location: Camp Hill, PA. - USA

Was anybody able to find out how to code a solution for this problem? I've searched the Intercommunication Guide as well as this site as Jeff suggested, however, I have not been able to find any information on this subject.

If anybody can point me in the right direction I would sure appreciate it.

Thanks.
Back to top
View user's profile Send private message Send e-mail
jefflowrey
PostPosted: Fri Sep 09, 2005 8:42 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Did you try searching for "correlation" and limiting it to the Java/JMS forum?

When I did that, I found
http://www.mqseries.net/phpBB2/viewtopic.php?t=21819&highlight=correlation
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
HMed
PostPosted: Fri Sep 09, 2005 10:28 am    Post subject: JMS - correlation ID Reply with quote

Novice

Joined: 17 Sep 2004
Posts: 17
Location: Camp Hill, PA. - USA

I looked through every example and can not find one where the incoming message is from JMS and the outgoing message is using IBM MQ.

This appears to be the problem that MQSeries.net user mnicolls originally had and that I (and others based on the number of views and similar posts) also have. However, I have never seen a solution posted on this particular situation.

I did see an example where IBM converted the jms correlation ID (in String format) to a byte array using getbytes, however, that does not work in this case, since the char sets from both the originating and destination systems are different, getbytes does not produce the desired results.

If anybody else has an idea, I would greatly appreciate it. Thanks.
Back to top
View user's profile Send private message Send e-mail
jefflowrey
PostPosted: Fri Sep 09, 2005 10:37 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Ahh. That might be a little trickier.

Except, of course, that IBM's implementation of JMSMessage includes getJMSCorrelationIDAsBytes and possibly getJMSMessageIDAsBytes (even though it's not documented).

And, also, MessageID and CorrelationID are not in any character set, nor are they affected by charset conversion when for example moving from EBCDIC to ASCII systems . So if you set the bytevalue on mainframe to be all 1s, then it will still be all 1s on unix or windows or anything else.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
HMed
PostPosted: Fri Sep 09, 2005 10:44 am    Post subject: JMS - correlation ID Reply with quote

Novice

Joined: 17 Sep 2004
Posts: 17
Location: Camp Hill, PA. - USA

Yes, that is true, that a 1 is a 1 is a 1, but a 221 has a different meaning between char sets.

I did see the getJMSCorrelationIDAsBytes in the javadoc and am anxious to try it, however we don't have that version of MQ (yet).

I think for now I will go back to this user and force him to not use extended Ascii.

Thanks for your thoughts on this subject.
Back to top
View user's profile Send private message Send e-mail
jefflowrey
PostPosted: Fri Sep 09, 2005 10:52 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

I'm fairly sure getJMSCorrelationIDAsBytes is available in the 5.3 JMS implementation...

You should go back and force the user not to try to pass string data in the correlation ID, and not to try and use the correlation id in any design pattern other than request/reply.

It's not intended to hold business data, it's not intended to be used as a general purpose filtering tool.

To do anything other than request/reply with this field is an anti-pattern.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
HMed
PostPosted: Tue Sep 13, 2005 10:02 am    Post subject: JMS - correlation ID Reply with quote

Novice

Joined: 17 Sep 2004
Posts: 17
Location: Camp Hill, PA. - USA

Jeff, by the way, the user wasn't putting anything in the Message ID. It was being generated by MQ.

Anyway, I just thought I'd post this code to convert a jmsMessageID or jmsCorrelationID (which is acquired from JMS as an ascii hex text string) to a bytearray (what MQ uses). This will enable WAS or other container users to use MDB's (Message Driven Beans) and send the reply using MQ rather than JMS.

Hope it helps somebody.

Code:
   
public byte[] convertAsciiHexToByteArray(String jmsMsgID) throws ControllerException {
      
      try {
            
         byte byteArray[] = new byte[24];
         boolean found1 = false;
         boolean found2 = false;
         int hex1 = 0;
         int hex2 = 0;
         int b,i,j,k;
         String strA[] = {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"};
         int intA[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
            

// Loop through the jmsMessageID starting at the 4th character,
// as JMS prefixes both the jmsMessageID and the jmsCorrelationID with ID:

         for (j=3,k=4,b=0; (j<51); j=j+2,k=j+1,b++) {

// Convert each two hex bytes to an integer.  I used an evaluation method.

            for (i=0; i<16; i++){


               if (jmsMsgID.substring(j,j+1).equalsIgnoreCase(strA[i])) {
                  hex1 = intA[i];
                  found1 = true;
               }
               if (jmsMsgID.substring(k,k+1).equalsIgnoreCase(strA[i])) {
                  hex2 = intA[i];
                  found2 = true;
               }
            }
// check for errors, ie... not a valid hex digit.

            if (!found1) {
               String s = new String (this.getClass().getName() + " Problem Converting JMSMessageID/JMSCorrelationID at position " + (j+1) + ". " + jmsMsgID );
               System.out.println(s);
               throw new ControllerException(s);
            }
            else {
// reinitialize
               found1=false;
            }
// check for errors, ie... not a valid hex digit.

            if (!found2) {
               String s = new String (this.getClass().getName() + " Problem Converting JMSMessageID/JMSCorrelationID at position " + (k+1) + ". " + jmsMsgID );
               System.out.println(s);
               throw new ControllerException(s);
            }
            else {
// reinitialize
               found2=false;
            }
// Once both hex bytes are converted to integers,
// add them together (remember they are base 16)
// and store as one byte in the bytearray that MQ will use

            byteArray[b] = (byte) ((hex1 * 16) + hex2);
         }
   
         return(byteArray);
      }
            
      catch(ControllerException ex) {
         logger.fatal("Exception = " + ex);
         System.out.println("Exception = " + ex);
         if (logger.isDebugEnabled())
            ex.printStackTrace(System.err);
         throw ex;
      } //catch

      catch(Exception ex) {
         logger.fatal("Exception = " + ex);
         System.out.println("Exception = " + ex);
         if (logger.isDebugEnabled())
            ex.printStackTrace(System.err);
         throw new ControllerException(ex);
      } //catch
   }
Back to top
View user's profile Send private message Send e-mail
fjb_saper
PostPosted: Tue Sep 13, 2005 7:42 pm    Post subject: Reply with quote

Grand High Poobah

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

What part of ANTI - PATTERN do you not understand.
If the byte array really was only text it could easily be converted back into text using standard String functions.

However what is a String in EBCDIC is just a byte array and NOT a char array in ASCII and vice versa....

So you should really only use a formula that returns either the message id or the existing correlationid of the request message.

The standard pattern calls for the message id of the request message.
Due to transformation at broker and on the way it may be necessary to use the correlation id of the request message.

However for the reasons already stated by Jeff you should treat it as an array of bytes with no special significance whatsoever.....

Enjoy
Back to top
View user's profile Send private message Send e-mail
HMed
PostPosted: Wed Sep 14, 2005 4:16 am    Post subject: JMS ascii hex text string to MQ bytearray Reply with quote

Novice

Joined: 17 Sep 2004
Posts: 17
Location: Camp Hill, PA. - USA

I know that you guys are way smarter than I am and I don't want to beat a dead horse, but I'm not sure that you totally understand this situation. So my question to you is what are you supposed to do in the following situation?

    1. A MDB monitors a queue and uses JMS to retrieve the message. JMS is what the container, Websphere Application Server, uses by default.

    2. The container (WAS in this case) automatically reads the queue once the MDB is kicked off and destroys the message from the queue.

    3. The message is automatically passed as a parameter to a method in the MDB by WAS (the container).

    4. The message is in the format javax.jms.Message.

    5. As you know, you read the messageID of the message that was passed with the java class javax.jms.Message.getJMSMessageID().

    6. A JMSMessageID is a String value.

    7. All JMSMessageID values start with the prefix 'ID:' (taken from javadoc)

    Here is a sample of the message ID returned: "ID:414D5120666A73753033355F716D3120431A392E2079CA01".

    Ok, at this point is probably where I made the wrong decision. Maybe I should have programmed the rest of the applicaiton using JMS. Then I could easily have resent the messageID using the javax.jms.Message.getJMSMessageID() method, however, being an MQ programmer, and since I work in an MQ shop, I programmed the rest of the application using MQ.

    Now the problem.

    8. When I want to send the reply message, using MQ, my only choice to set the messageID and/or correlationID is by setting the bytearray variable com.ibm.mqbind.MQMessage.messageId.

    9. If you look above, you will see that you just can't simply convert the string ID:414D5120666A73753033355F716D3120431A392E2079CA01 using getbytes. The result will be incorrect.

    10. You need to do some manipulation. Each two string characters after the "ID:" must be converted to one byte and then inserted into the com.ibm.mqbind.MQMessage.messageId bytearray that is 24 bytes long.

    Like Jeff stated before, there is a getJMSCorrelationIDAsBytes available in the 5.3 JMS implementation, however, we do not currently have this at our installation.


If you have another suggestion, other than the code that I posted, on how to put the ascii hex text string from the JMS messageID into the bytearray of the MQ messageID, I'm all ears.

I'd also like to mention that the original messageID is generated by another MQ system and is not user generated.

Thanks for considering this situation.
Back to top
View user's profile Send private message Send e-mail
fjb_saper
PostPosted: Wed Sep 14, 2005 4:44 pm    Post subject: Reply with quote

Grand High Poobah

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

OK so if you need to translate a hex representation of a byte array into a byte array you can do that like this:

Code:
//strip the ID: from the String hexstring
public byte[] getbytearray(String hexstring){
hexlength= string.length;
byte[] mybyte = new byte[hexlength];
bytelength = hexlength / 2;
for (int i =0; i< bytelength; i++){
  strbyte = hexstring.substring(2*i,2);
  Integer my_Int = Integer.decode("0x"+strbyte);
  mybyte[i]= my_Int.byteValue();
}//end for
return mybyte;
}// end method

Et voila...

Enjoy
Back to top
View user's profile Send private message Send e-mail
HMed
PostPosted: Thu Sep 15, 2005 3:07 am    Post subject: Success! Reply with quote

Novice

Joined: 17 Sep 2004
Posts: 17
Location: Camp Hill, PA. - USA

That's it! Thanks alot.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » JMS - correlation ID
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.