javax.naming.NameNotFoundException: in context "java:comp/env" - Websphere

This is a discussion on javax.naming.NameNotFoundException: in context "java:comp/env" - Websphere ; I have developed a servlet based application (war) on tomcat, which I am trying to port to WAS. I am getting following Exception: java.sql.SQLException: Error looking up data source for name: jdbc/MySQLDB Caused by: javax.naming.NameNotFoundException: Name jdbc not found in ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: javax.naming.NameNotFoundException: in context "java:comp/env"

  1. javax.naming.NameNotFoundException: in context "java:comp/env"

    I have developed a servlet based application (war) on tomcat, which I am trying to port to WAS. I am getting following Exception:

    java.sql.SQLException: Error looking up data source for name: jdbc/MySQLDB
    Caused by: javax.naming.NameNotFoundException: Name jdbc not found in context "java:comp/env".
    at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInt ernal(NameSpace.java:1767)
    at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal( NameSpace.java:1083)
    at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpac e.java:991)
    at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(Ur lContextImpl.java:1263)
    at com.ibm.ws.naming.java.javaURLContextImpl.lookup(j avaURLContextImpl.java:384)
    at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(Ur lContextImpl.java:1307)

    Here is the details about application:

    Flow OF Execution is like 1. JMS Broker Servlet Context Listener starts the ActiveMQ 2. JMS client gets initialized
    from StartUpServlet 3. Servlet trying to lookup DataSource throws java.sql.SQLException: Error looking up data
    source for name: jdbc/MySQLDB. If StartUpServlet gets commented out from web.xml then lookup for DataSource works fine.
    But I need both of them to work together.

    WEB-INF/web.xml
    ---------------
    com.myservlet.StartJMSBrokerServletContextListener
    ........................................

    StartUpServlet
    1

    ........................................

    StartUpServlet.java
    -------------------
    public class StartUpServlet extends GenericServlet
    {
    private Context jndiContext;

    public void init() throws ServletException
    {
    Properties props = new Properties();
    props.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.apache.activemq.jndi.ActiveMQInitialContextFac tory");
    props.setProperty(Context.PROVIDER_URL, "tcp://localhost:61616");
    jndiContext = new InitialContext(props);

    QueueConnectionFactory queueConnectionFactory =
    (QueueConnectionFactory) jndiContext.lookup("queueConnectionFactory");
    QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();
    Queue queue = (Queue) jndiContext.lookup("MyQueue");

    ........................................
    }
    }
    META-INF/context.xml
    --------------------




    DataManager.java
    ---------------
    Context context = (Context) new InitialContext().lookup("java:comp/env");
    javax.sql.DataSource ds =(javax.sql.DataSource) context.lookup("jdbc/MySQLDB");
    Connection sqlConnection = ds.getConnection() ;
    statement = sqlConnection.prepareStatement(queryString);;


    WEB-INF/Classes/jndi.properties
    -------------------------------
    java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFac tory
    java.naming.provider.url = tcp://localhost:61616
    onnectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactory
    queue.MyQueue = MyQueue
    queue.MyResponseQueue = MyResponseQueue

  2. Re: javax.naming.NameNotFoundException: in context "java:comp/env"

    I didn't know websphere supports context.xml?. You should be able to put the database resource reference in your web.xml such as:

    My SQLDB
    jdbc/MySQLDB
    javax.sql.DataSource
    Container


    Then create the datasource within was. When you deploy point the resource reference to the datasource in was, or you can have a binding file.

    Roy

  3. Re: javax.naming.NameNotFoundException: in context "java:comp/env"

    It is taking context.xml in to account, when I am commenting out StarUpServlet which is making jndi lookup for queueConnectionFactory. Some how this seems to be breaking datasource lookup.

  4. Re: javax.naming.NameNotFoundException: in context "java:comp/env"

    Long shot -- can you start with getting rid of the jndi.properties file.
    To start with, you should be able to add those properties like connectionFactoryNames, queue.MyQueue
    and queue.MyResponseQueue to the props you send to new InitialContext in StartupServlet.java.


    Ideally, I'd suggest defining a Generic JMS provider for ActiveMQ in the admin console and use the
    custom properties of that provider to set the connectionFactoryNames etc and then define
    corresponding cfs and queues for that provider.
    That way, the InitialContextFactory in StartupServlet would not need the properties to be passed in.



    Cheers,
    Vinod


    jigamove@yahoo.com wrote:
    > It is taking context.xml in to account, when I am commenting out StarUpServlet which is making jndi lookup for queueConnectionFactory. Some how this seems to be breaking datasource lookup.


+ Reply to Thread