Distinguishing QueueSession from TopicSession After WebLogic's TopicSession.createTopicSession() Call

My Question:  

How do I distinguish a QueueSession from a TopicSession, when I have obtained the session reference via a call to TopicSession.createTopicSession() or QueueSession.createQueueSession() at some prior point in the code?   Can anyone describe WebLogic's specific implementation of the Destination/Topic/Queue and Session/TopicSession/QueueSession classes, that accounts for 'instanceof' returning 'true' for BOTH QueueSession and TopicSession, and for both Queue and Topic?  

Why I'm asking:

Some legacy code I'm working on has had a new Topic configured, and a new message is being sent
on that topic from the server, but it is not received by the client applet. I've traced the problem to a low-level JMS-related function in the application's server-side code, which instantiates a QueueSender instead of a TopicPublisher where it should not, and then sends the message via that incorrect means.  

This mistake occurs because a JMSSession object reference is passed into the function as a parameter, and the function immediately checks if it's a reference to a QueueSession, in particular.  That check unexpectedly succeeds even when the passed-in object reference is to a TopicSession, thus causing the function to *always* instantiate the QueueSender.  

Again, to be clear -- if BOTH the following instanceof tests are present, BOTH return true:
if (theSessionParameter instanceof QueueSession)
if (theSessionParameter instanceof TopicSession)
Presumably, this occurs because the passed-in object is actually of type weblogic.jms.client.JMSSession, which is apparently generic enough to pass both tests.

Some pertinent points:

1) The topic/destination reference that is passed in as a parameter was first obtained via a  
    TopicSession.createTopicSession() call, which returns a weblogic.jms.client.JMSSession reference,
    and then that JMSSession reference is cast specifically to a TopicSession reference.
2) The topic/destination to which the message is sent is (to all appearances) correctly configured
    as a JMSTopic and *not* as a JMSQueue in config.xml and elsewhere, so that should not
    introduce any conflict or confusion when it is sent.  (BTW, after a JNDI lookup() call for the    
    topic/destination name, I've noticed that existing 'instanceof' checks in the code that check for a      
    Queue versus a Topic similarly BOTH succeed for the returned object, which is of type
    weblogic.jms.common.DestinationImpl.  So some similar mechanism is operating there and
    I'll no doubt have to make some related changes in that pre-existing code, as well.

RosieDarkRetired Senior Software EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RosieDarkRetired Senior Software EngineerAuthor Commented:
I've found a partial answer to my own question.  I'm posting it for the benefit of the rest of y'all:

With Regard to Distinguishing a Queue from a Topic, when one has a weblogic.jms.common.DestinationImpl object:

Yes, my speculation was correct, per BEA, that the weblogic.jms.common.DestinationImpl class implements both javax.jms.Queue and javax.jms.Topic.  And yes, this creates a problem distinguishing them, so BEA provides an undocumented work-around API call to replace the
use of the instanceof operator.  (BEA says that normally only the javadoc'd methods are intended
for public use, but in this case they make an exception.)

Replace your instanceof operation with:

But be forewarned ... "The next release will deprecate the work-around in favor of an extension interface, which will be very similar - something like:


With Regard to Distinguishing a QueueSession from a TopicSession, when one has a weblogic.jms.client.JMSSession object:

Still searching for the answer; probably something equivalent to what's been provided above for Destinations.
PAQed with points refunded (250)

Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java App Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.