This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I haven't posted on JavaRanch in quite a while, but I'm struggling with an issue that has me stumped.
My team is in the process of migrating an application from WebLogic to JBoss 6. The bulk of the work is done, but JMS is still giving us some pains. We have code that looks up a TIBCO EMS connection factory via JNDI. The factory is set up as per the specifications in section 1 of this page. In some places, we try to access queues and in other places we try to access topics. Unfortunately, I cannot post the actual code, since it is sitting on my machine at the office. Nonetheless, I figured that I'd try my luck posting here.
We look up the TIBCO connection factory via JNDI, and cast it to the appropriate type (QueueConnectionFactory or TopicConnectionFactory). This lookup always succeeds, regardless of what we cast the resulting object to (my understanding is that the factory should implement both the QueueConnectionFactory and TopicConnectionFactory interfaces). We then create a QueueConnection/TopicConnection and the relevant type of session using the factory. Then, we send/publish a message to the relevant queue or topic. The code is very similar to the below (my apologies, but like I said, I don't have the actual code available right now).
The (very odd) issue that the method that is called first always seems to work (regardless of whether it uses a queue or a topic), whereas the second method always fails. If the order of the method is switched around, whichever one is called first still works, while the second one then fails. The cause of this, based on the JBoss logs, seems to be that JBoss gives us a factory for the first lookup and then keeps the type of the factory when the second lookup is done. So, even though the factory that we look up should provide both a queue connection factory and a topic connection factory, the session that is returns is only valid for whichever is created first. It throws an exception (just like the code, I don't have the full stack trace handy right now, but I think it's an InvalidDestinationException or an IllegalArgumentException) with either "topic session" or "queue session" as the message. The method calls are made from a session bean that is invoked from a servlet. The issue occurs when the session beans calls both methodA() and methodB() from the method called by the servlet (i.e. in the same container transaction). Please correct me if anything I'm saying comes across as nonsense.
Any thoughts on why this would happen? My JNDI knowledge isn't perfect, so I'm not sure if it is JNDI related. Are objects cached when you look them up via JNDI? I want to try and see if I can use the TIBCO specific context to look up the individual queue and topic connection factories directly. In the meantime, I was hoping that someone will be able to shed some light on the issue.
"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." - George Bernard Shaw
I should also point out the the application is deployed as an EAR file. The EAR contains, among other things, the JAR with the session bean in it and a WAR containing the servlet. If I copy and paste both of these methods into a servlet and execute them from there, it works perfectly - I can only see the issue happening in a session bean.