I'm using a JMS server deployed on top of a Weblogic server. I have a few topics on the JMS server, which I have a client program serving as a topic publisher/subscriber. The question is this: if the Weblogic server goes down and then later comes back up, how do I reconnect to the topic again from my client program? First of all, I set an exception listener in my client program, but it doesn't seem to get invoked even if the JMS server went down. Secondly, even if I detected the failure somehow, when the JMS server went back online, I wasn't able to reconnect to it from my client program even if I duplicated the entire JMS setup mechanism again (look up topic, create factory, connection, publisher, ...) It is giving me errors saying that the connection is closed. Can someone tell me what I'm doing wrong?

Here are my code to reestablish the connection:

       if (publisher != null)
        {
            try
            {
                publisher.close();
            }
            catch (JMSException e)
            {
            }
        }

        if (session != null)
        {
            try
            {
                session.close();
            }
            catch (JMSException e)
            {
            }
        }
        if (connection != null)
        {
            try
            {
                connection.close();
            }
            catch (JMSException e)
            {
            }
        }

        if (context != null)
        {
            try
            {
                context.close();
            }
            catch (NamingException e)
            {
            }
        }

        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY, ...);
        env.put(Context.PROVIDER_URL, ...);
        context = new InitialContext(env);
        factory = (TopicConnectionFactory)context
            .lookup(...);
        topic = (Topic)context.lookup(...);
        connection = factory.createTopicConnection();
        session = connection.createTopicSession(false,
                        Session.AUTO_ACKNOWLEDGE);
        publisher = session.createPublisher(topic);
        connection.start();