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 » My setStringProperty returns null??

Post new topic  Reply to topic
 My setStringProperty returns null?? « View previous topic :: View next topic » 
Author Message
fredand44
PostPosted: Tue Mar 25, 2008 4:32 am    Post subject: My setStringProperty returns null?? Reply with quote

Acolyte

Joined: 14 Feb 2006
Posts: 63

Hello!

I try to set a param with the method setStringProperty("x", "y").
But when I try to read it with getStringProperty("x), I just get "null".
I really hope that some one can help me out with this problem.

I send a JMS message to a local queue at my MQ with the following code:

public static void send() throws Exception
{
System.out.println("Start");
Properties properties = new Properties();
properties.setProperty("java.naming.factory.initial", "com.sun.jndi.fscontext.RefFSContextFactory");
properties.setProperty("java.naming.provider.url", "file:C://Fredrik//Eclipse_workspace//distribution//resources");
Context ctxNaming = new InitialContext(properties);
QueueConnectionFactory factory = (QueueConnectionFactory) ctxNaming.lookup("queue.connection.factory");
QueueConnection connection = factory.createQueueConnection();
connection.start();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) ctxNaming.lookup("MYQUEUE");
QueueSender sender = session.createSender(queue);
BytesMessage responseMessage = session.createBytesMessage();
responseMessage.writeBytes("hubba".getBytes());

responseMessage.setStringProperty("testkey", "testvalue");
System.out.println("\n test: " + responseMessage.getStringProperty("testkey") );

sender.send(responseMessage);
session.close();
connection.close();
System.out.println("Stop");
}

It looks like the param get set since:
System.out.println("\n test: " + responseMessage.getStringProperty("testkey") );
...prints out:
test: testvalue

But when I read the message with the following code:
public static void read() throws Exception
{
System.out.println("Start");
Properties properties = new Properties();
properties.setProperty("java.naming.factory.initial", "com.sun.jndi.fscontext.RefFSContextFactory");
properties.setProperty("java.naming.provider.url", "file:C://Fredrik//Eclipse_workspace//distribution//resources");
Context ctxNaming = new InitialContext(properties);
QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) ctxNaming.lookup("queue.connection.factory");
QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();
queueConnection.start();
QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (javax.jms.Queue) ctxNaming.lookup("MYQUEUE");
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
Message message = queueReceiver.receiveNoWait();

if(message instanceof TextMessage)
{
logger.debug("\n"+((TextMessage)message).getText() );
}
if(message instanceof BytesMessage)
{
System.out.println("\n test: " + message.getStringProperty("testkey") );
System.out.println("\n test: " + ((BytesMessage)message).getStringProperty("testkey") );
}
else
{
logger.debug("\n"+message.toString());
}

queueSession.close();
queueConnection.close();
System.out.println("Stop");
}

I just get:
...prints out:
test: null.

I really can not figure out why?

So if any one got an idea or clue, please let me know.

Best regards
Fredrik
Back to top
View user's profile Send private message
fredand44
PostPosted: Tue Mar 25, 2008 11:40 am    Post subject: I think I got it!! Reply with quote

Acolyte

Joined: 14 Feb 2006
Posts: 63

Hello!

I do not nearly believe my self, but I think I found the error.

When I set up the jndi I set TARGCLIENT(MQ).

I found out that it probably should be TARGCLIENT(JMS)

Then it looks that I can read all setXXXProperties.

Best regards
Fredrik
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Tue Mar 25, 2008 11:57 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Now you see why it's bad to double-post the same question.

You have to update the answer twice!
_________________
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 » My setStringProperty returns null??
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.