Solved

Websphere Remote Jndi Lookup - ClassCastException javax.naming.Reference cannot be cast to javax.jms.QueueConnectionFactory

Posted on 2009-07-01
6
7,785 Views
Last Modified: 2013-12-11
Hi,

Someone has asked a similar question to this previously, but they didn't really reveal how they solved it.

I'm doing a Remote JNDI Lookup for a QueueConnectionFactory. The QueueConnectionFactory and the ear I'm working with are deployed on Websphere. Im also using Websphere MQ. I'm pretty sure my InitialContext is set up correctly. It retrieves my queues without problem.

However, when I do a lookup of the QueueConnectionFactory, my attempt to cast the object returns a ClassCastException.

Exception in thread "main" java.lang.ClassCastException: javax.naming.Reference cannot be cast to javax.jms.QueueConnectionFactory at queue.RemoteExecutionServerRunner.setUpWASQueue(RemoteExecutionServerRunner.java:101)
at queue.ExecutionServerTest.main(ExecutionServerTest.java:23)

Googling around leads me to things its something to do with the classpath.

Any help would be greatly appreciated.

Thank you
jndiContext = getJndiContext();
 
connectionFactory = (QueueConnectionFactory)   jndiContext.lookup("jms/BRESQueueConnectionFactory");
sendQueue = (Queue) jndiContext.lookup("queue/BRESQueueIn");
replyQueue = (Queue) jndiContext.lookup("queue/BRESQueueOut");
 
 
private Context getJndiContext() {
		
	Context ctx = null;
		
	try {
		Properties properties = new Properties();
		properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
		properties.setProperty(Context.PROVIDER_URL, "corbaloc:iiop:idassysapp2:2811");
		properties.setProperty(Context.URL_PKG_PREFIXES,"com.ibm.ws.naming");
		
		properties.setProperty("com.ibm.CORBA.ORBInit", "com.ibm.ws.sib.client.ORB");
		
		ctx = new InitialContext(properties);
			
	} catch (NamingException e) {
		e.printStackTrace();
	}
		
	return ctx;
}

Open in new window

0
Comment
Question by:fuzzydunlop
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 4

Assisted Solution

by:Tuno85
Tuno85 earned 500 total points
ID: 24752614
I would suggest using InitialContext as return type.

Make sure you have the IBM JDK libraries on the classpath.

And eventually check this link:

http://www.ibm.com/developerworks/forums/thread.jspa?messageID=14008677
0
 

Author Comment

by:fuzzydunlop
ID: 24752657
Hi Tuno,

Thanks for the response.

I have three IBM jars on my application build path.

sibc.jms.jar
sibc.jndi.jar
sibc.orb.jar

Are these enough? I've tried adding all the jars from my Websphere 6 installation directory to the build path but that doesn't seem to solve it.

Thanks
0
 
LVL 4

Assisted Solution

by:Tuno85
Tuno85 earned 500 total points
ID: 24752933
How do you execute this. On the server or unit test?

Do you use the IBM JVM?

Did you try InitialContext as return type?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:fuzzydunlop
ID: 24753720
I've written a standalone application, accessing Websphere remotely. My class is executed within a main method.

I did try the InitialContext as a return type, the error still occurs. I'm using the Sun JVM.
0
 
LVL 4

Accepted Solution

by:
Tuno85 earned 500 total points
ID: 24760591
I am looking at the similar code I am using. Nothing wrong. Should be working.

Try using the IBM JVM, maybe that this works. Although same mechanism should be working with Sun JVM.

I was also looking around and also found this:

http://forums.sun.com/thread.jspa?threadID=5225537
0
 

Author Comment

by:fuzzydunlop
ID: 24761175
Hi,

Thanks for the link. I have allowed access to the Internal Server Classes on the Websphere Application Server.

I have managed to figure it out. It's not a very elegant solution but it works. This probably ties in with using the IBM JVM, but I imported a host of Jars from the Application Server into my client application. The directories were:

${WAS_HOME}\AppServer\lib
${WAS_HOME}\AppServer\plugins

Having these jars on my application classpath seemed to fix the problem.

Hope this helps anyone who comes across this problem. Thanks for the help Tuno.
0

Featured Post

Save the day with this special offer from ATEN!

Save 30% on the CV211 using promo code EXPERTS30 now through April 30th. The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
countHi2 challenge 7 62
where is session ID cache stored 1 59
looking for unix program to search some keywords in side EAR WAR and JAR files 10 111
going to wrong jsp page 2 50
Configure Web Service (server application) I. Configure security for Web Services methods First, we need to protect Session bean which implements the service: 1. Open EJB deployment descriptor (ejb-jar.xml) in the EJB project that contains you…
This exercise is about for the following scenario: Dmgr and One node with 2 application server. Each application server contains it owns application. Application server name as follows server1 contains app1 server2 contains app1 Prereq…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question