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 SimpleQueueReceiver giving Exception

Post new topic  Reply to topic
 JMS SimpleQueueReceiver giving Exception « View previous topic :: View next topic » 
Author Message
sharan_nag
PostPosted: Thu Oct 26, 2006 2:40 am    Post subject: JMS SimpleQueueReceiver giving Exception Reply with quote

Newbie

Joined: 25 Oct 2006
Posts: 7

Hi,
I have written a code to read message from the Queue. I am working in HP-UX environment. My Java code is as follows.

import javax.jms.*;
import javax.naming.*;
import java.util.Properties;
import com.ibm.mq.*;
public class SimpleQueueReceiver
{

public static void main(String[] args)
{
String queueName = null;
Context jndiContext = null;
QueueConnectionFactory queueConnectionFactory = null;
QueueConnection queueConnection = null;
QueueSession queueSession = null;
Queue queue = null;
QueueReceiver queueReceiver = null;
TextMessage message = null;

queueName = new String(args[0]);
System.out.println("Queue name is " + queueName);

//Create a JNDI API InitialContext object if none exists yet.
try
{
Properties prop = new Properties();
prop.put(Context.PROVIDER_URL,"file:/opt/mqm/java");
prop.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory");
jndiContext = new InitialContext(prop);
}
catch (NamingException e)
{
System.out.println("Could not create JNDI API context: " + e.toString());
System.exit(1);
}
System.out.println("Created the JNDI API context");

try
{
queueConnectionFactory=(QueueConnectionFactory)jndiContext.lookup("QueueConnectionFactory");
queue=(Queue)jndiContext.lookup(queueName);
}
catch (NamingException e)
{
System.out.println("JNDI API lookup failed: " +e.toString());
System.exit(1);
}
System.out.println("JNDI API lookup successful");

try
{
queueConnection = queueConnectionFactory.createQueueConnection("user","password");
//queueConnection = queueConnectionFactory.createQueueConnection();
System.out.println("QueueConnection created successfully");
queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
System.out.println("QueueSession created successfully");
//queueSession = queueConnection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
queueReceiver = queueSession.createReceiver(queue);
System.out.println("Queue Receiver created successfully");
queueConnection.start();
System.out.println("QueueConnection started");
while (true)
{
Message m = queueReceiver.receive(1);
if (m != null)
{
if (m instanceof TextMessage)
{
message = (TextMessage) m;
System.out.println("Reading message: " +message.getText());
}
else
{
break;
}
}
}
}
catch (JMSException e)
{
System.out.println("Exception occurred: " +e.toString());
Exception ex = e.getLinkedException();
if(ex!=null)
System.out.println("Linked Exception is : "+ex);
}
finally
{
if (queueConnection != null)
{
try
{
queueConnection.close();
}
catch (JMSException e) {}
}
}
}
}


I am getting the following exception when i run the above java code.

Exception occurred: javax.jms.JMSSecurityException: MQJMS2008: failed to open MQ queue
Linked Exception : com.ibm.mq.MQException: MQJE001: Completion Code 2, Reason 2035


Can you please suggest me what to do ?
Thanks in advance.

Thanks and Regards,
Sharanu A N
Back to top
View user's profile Send private message Yahoo Messenger
Vitor
PostPosted: Thu Oct 26, 2006 2:45 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

A very straightforward search of either the documentation or this forum would have revealed that 2035 = MQRC_NOT_AUTHORIZED. You have no permissions to read the queue you're using!

RTFM!
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
sharan_nag
PostPosted: Fri Oct 27, 2006 12:59 am    Post subject: JMS SimpleQueueReceiver giving Exception Reply with quote

Newbie

Joined: 25 Oct 2006
Posts: 7

Hi,
The MQ Admin says that the user has all the rights, Read,Browse and Write. Even then it is giving the exception. When I run the java code with Base API, it will run successfully. But the java code with JMS API is giving this problem. Even the C executables are able to read from the Queue. I am able to write into the Queue with JMS API Java code.

Thanks and Regards,
Sharanu A N
Back to top
View user's profile Send private message Yahoo Messenger
Vitor
PostPosted: Fri Oct 27, 2006 1:18 am    Post subject: Re: JMS SimpleQueueReceiver giving Exception Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

I would put it to you that the code is not using the user id you believe it is, or that the user does not have all the rights the admin believes it does.

As indicated in the documentation, and a number of times in this forum, I recommend that you temporailly enable security events to determine the exact combination of factors causing the 2035. Then take action appropriate to your situation.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Fri Oct 27, 2006 3:05 am    Post subject: Reply with quote

Grand High Poobah

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

Remember that you can only use the overloaded form:
qcf.createConnection(user, passwd) if you are using a client connection.

Using a different user than the one running the process with a bindings connection will result in a 2035... (see using java manual)

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
sharan_nag
PostPosted: Tue Oct 31, 2006 4:09 am    Post subject: Reply with quote

Newbie

Joined: 25 Oct 2006
Posts: 7

Hi,
I have tried Writing to the same queue using the same binding file. I am able to write to that queue, but not able to read from the queue. I am able to write and read to and from the same queue using the base java api. Also I am able to the same using the sample executables. But when I use the jms api for reading, it is giving the exception 2035, but writing is working completely fine. I tried all the possibilities, but in vain.

Thanks and Regards,
Sharanu A N
Back to top
View user's profile Send private message Yahoo Messenger
fjb_saper
PostPosted: Tue Oct 31, 2006 4:22 am    Post subject: Reply with quote

Grand High Poobah

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

sharan_nag wrote:
Hi,
I have tried Writing to the same queue using the same binding file. I am able to write to that queue, but not able to read from the queue. I am able to write and read to and from the same queue using the base java api. Also I am able to the same using the sample executables. But when I use the jms api for reading, it is giving the exception 2035, but writing is working completely fine. I tried all the possibilities, but in vain.

Thanks and Regards,
Sharanu A N

Of course writing is find you have put authority? Try creating a browser instead of a receiver. You do not have get authority....
And make sure they add enquire to the authorities. JMS likes to have that for any operations....
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
sharan_nag
PostPosted: Tue Oct 31, 2006 7:12 am    Post subject: Reply with quote

Newbie

Joined: 25 Oct 2006
Posts: 7

Thank you very much fjb_saper and Vitor. After the enquire authority was given, it worked fine...

Thanks a lot.
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » JMS SimpleQueueReceiver giving Exception
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.