Why does calling close () in the InitialContext interrupt JNDI for all future searches (Glassfish)?

Second JNDI search in the code below, it is not performed with the exception of when run in a standalone application against Glassfish (which has been configured to provide QueueConnectionFactoryand DataSourcethrough JNDI). However, the code works fine when deleting a line jndiContext.close().

In real code close(), Spring's call is made JndiObjectFactoryBean, so I cannot remove it easily.

Is this a bug in Glassfish, or am I doing something wrong (e.g. wrong configuration or wrong coding)?

import javax.naming.Context;
import javax.naming.InitialContext;

public class TestInitCtx {
    private final static String QUEUE_CONNECTION_FACTORY_JNDI_NAME = "QCF";
    private final static String DATA_SOURCE_JNDI_NAME = "DS";

    public static void main(String[] args) throws Exception {
        Context jndiContext = new InitialContext();
        jndiContext.lookup(QUEUE_CONNECTION_FACTORY_JNDI_NAME);

        // In Glassfish, this line causes the second lookup
        // to throw a com.sun.enterprise.connectors.ConnectorRuntimeException
        // (wrapping a NullPointerException)
        jndiContext.close();

        jndiContext = new InitialContext();
        jndiContext.lookup(DATA_SOURCE_JNDI_NAME);          
    }
}

+3
source share
1 answer

JNDI InitialContext. sun, , , JNDI factory, , .

0

Source: https://habr.com/ru/post/1716282/


All Articles