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 » MQMessage.writeInt and readInt strange behavor

Post new topic  Reply to topic
 MQMessage.writeInt and readInt strange behavor « View previous topic :: View next topic » 
Author Message
HenriqueS
PostPosted: Mon Sep 25, 2006 10:22 am    Post subject: MQMessage.writeInt and readInt strange behavor Reply with quote

Master

Joined: 22 Sep 2006
Posts: 235

Folks, the code below writes some ints to the queue, and when pops up the same message back, the java variables that are fed with readInt are holding bizarre values, making the JVM into crashing because one of the read variables are used to allocate memory (and the value returned is so big the JVM cannot handle it). Anyway, the read value from readInt() is totally different from what was written in the message. I tried to force the machine endianess but it did not help.

Any idea?

*code comments are in portuguese, but it´s a simple program...
Websphere MQ 6.0 running under Intel 32 Platform win WinXP.

Code:

public HandlingMessagesSample1(){

try{

MQQueueManager queueManager = new MQQueueManager("javaexamples");

MQQueue queue = queueManager.accessQueue("testqueue", MQC.MQOO_OUTPUT | MQC.MQOO_INPUT_AS_Q_DEF, "javaexamples", "dynamicQName", "altUserId");
      
//Construindo uma mensagem contendo containing a minha idade seguida pelo nome
MQMessage myMessage = new MQMessage();
         
myMessage.encoding =  MQC.MQENC_INTEGER_REVERSED | MQC.MQENC_DECIMAL_REVERSED | MQC.MQENC_FLOAT_IEEE_REVERSED;
         
myMessage.writeInt(25);
String name = "Charlie Jordan";
myMessage.writeInt(name.length());
myMessage.writeBytes(name);
      
//Usando as opções default para colocar a mensagem...
MQPutMessageOptions pmo = new MQPutMessageOptions();
      
//colocando a mensagem no queue
queue.put(myMessage,pmo);
      
//Tirando a mensagem do queue
MQMessage theMessage = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
queue.get(theMessage, gmo); 
      
//Extraindo os dados da mensagem
int age = theMessage.readInt();
int strLen = theMessage.readInt();
byte[] strData = new byte[strLen];
theMessage.readFully(strData, 0, strLen);
name = new String(strData, 0);
      
System.out.println(name);
}catch(Exception ex){
ex.printStackTrace();
}
}
Back to top
View user's profile Send private message
vennela
PostPosted: Mon Sep 25, 2006 10:32 am    Post subject: Reply with quote

Jedi Knight

Joined: 11 Aug 2002
Posts: 4055
Location: Hyderabad, India

Code:
myMessage.writeInt(25);
String name = "Charlie Jordan";
myMessage.writeInt(name.length());
myMessage.writeBytes(name);


What happens if you do just

Code:
myMessage.writeInt(25);

and comment the rest of the lines?
Back to top
View user's profile Send private message Send e-mail Visit poster's website
HenriqueS
PostPosted: Mon Sep 25, 2006 11:36 am    Post subject: Reply with quote

Master

Joined: 22 Sep 2006
Posts: 235

writeInt(25)

readInt(var)

System.println.out gives 1633771873 !!!

That´s what I get also during debug...
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Mon Sep 25, 2006 11:42 am    Post subject: Re: MQMessage.writeInt and readInt strange behavor Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

You do this:
HenriqueS wrote:
myMessage.encoding = MQC.MQENC_INTEGER_REVERSED | MQC.MQENC_DECIMAL_REVERSED | MQC.MQENC_FLOAT_IEEE_REVERSED;


Once.

You need to do it twice.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
HenriqueS
PostPosted: Mon Sep 25, 2006 1:03 pm    Post subject: Re: MQMessage.writeInt and readInt strange behavor Reply with quote

Master

Joined: 22 Sep 2006
Posts: 235

Thnaks a lot, it worked!

jefflowrey wrote:
You do this:
HenriqueS wrote:
myMessage.encoding = MQC.MQENC_INTEGER_REVERSED | MQC.MQENC_DECIMAL_REVERSED | MQC.MQENC_FLOAT_IEEE_REVERSED;


Once.

You need to do it twice.
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Mon Sep 25, 2006 1:19 pm    Post subject: Re: MQMessage.writeInt and readInt strange behavor Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

jefflowrey wrote:
You need to do it twice.


The reason, of course, is because you do
Code:
//Tirando a mensagem do queue
MQMessage theMessage = new MQMessage();


New message = default Encoding = not what you wrote with.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » MQMessage.writeInt and readInt strange behavor
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.