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

Posted on 2004-11-15
Last Modified: 2013-12-10
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.

Question by:RosieDark

    Author Comment

    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.

    Accepted Solution

    PAQed with points refunded (250)

    Community Support Moderator

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    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…
    There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now