|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
My setStringProperty returns null?? |
« View previous topic :: View next topic » |
Author |
Message
|
fredand44 |
Posted: Tue Mar 25, 2008 4:32 am Post subject: My setStringProperty returns null?? |
|
|
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 |
|
 |
fredand44 |
Posted: Tue Mar 25, 2008 11:40 am Post subject: I think I got it!! |
|
|
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 |
|
 |
jefflowrey |
Posted: Tue Mar 25, 2008 11:57 am Post subject: |
|
|
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 |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|