JNDI problem in JBoss


General J2EE: JNDI problem in JBoss

  1. JNDI problem in JBoss (15 messages)


    I am trying use a SQL Server Data Source object through JBoss server but getting so many errors.

    I think I have all the required jar files in CLASSPATH.

    I have copied the mssql-ds.xml to JBOSS_DIST\server\default\deploy directory and modified it in the following way:


    I also had standardjaws.xml modified and copied to E:\jboss-3.2.4\server\default\conf directory.

    while starting up the server shows the following confirmation:

    14:11:00,780 INFO [MSSQLDS] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:service=LocalTxCM,name=MSSQLDS to JNDI name 'java:/MSSQLDS'

    But, when I execute the following client code on the same machine, it is giveing runtime error:
    **after setting the env props into HashTable ht..

    Context ic=new InitialContext(ht);
    DataSource ds=(DataSource)ic.lookup("java:comp/env/jdbc/MSSQLDS");


    Exception in thread "main" javax.naming.NameNotFoundException: comp not bound
    at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
    at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
    at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
    at org.jnp.server.NamingServer.lookup(NamingServer.java:253)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
    at sun.rmi.transport.Transport$1.run(Transport.java:148)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
    at java.lang.Thread.run(Thread.java:534)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
    at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:528)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:507)
    at javax.naming.InitialContext.lookup(InitialContext.java:347)
    at TestJdbcJBoss.main(TestJdbcJBoss.java:21)

    *** I have also tried the above look up statement with java:/MSSQLDS, java:/env/MSSQLDS and all the possible combinations.

    It is not detecting whatever that comes after "java: "

    I am really tiered with this error...Writing here with a ray of hope..plz help me.

    Threaded Messages (15)

  2. JNDI problem in JBoss[ Go to top ]

    what jndi.properties file is used by jvm that runs your client? you should use one that is in $JBOSS_HOME/server/default/conf

    also, if client code is running in webapp deployed in JBoss, you should use put appropriate sestions in jboss-web.xml and web.xml files in order to use that JNDI resource
  3. JNDI problem in JBoss[ Go to top ]

    Hi Gennady,

    Thank you so much for your quick reply.

    I am not using any properties files, but directly putting the required fields in the following way.

    Hashtable ht=new Hashtable();
    InitialContext ic=new InitialContext(ht);
    System.out.println("success");/*I am getting success as output here*/
    DataSource ds=(DataSource)ic.lookup("java:comp/env/jdbc/MSSQLDS");
    /*this is where it's failing*/

    I am not using any web server and this is a simple java client program.Please also confirm onething that, can we access DataSource Object from a stand alone program? Or Must it be used only by the internal components of JBoss like EJBs?

    Will be waiting for your reply...

    Thanks again.
    Best Regards,

    God is real unless declared integer....
  4. Are you sure?

    You should provide CLASS name, not an interface for java.naming.factory.initial enviroment property...

    Code you supplied in last post falls on instantiating initial context factory, because interface can not be instantiated ;)

    So, if it falls in some other place in your case, it means that jvm uses some other properties, not the ones you have supplied.

    Double check all configuration files, and, IMHO, you should keep JNDI configuration in jndi.properties (just because you dont need to recompile code for changing JNDI provider).

    Let me now if you have solved your problem.

  5. Jndi issue[ Go to top ]

    Hi Gennady,

    Sorry for late response.I was on vacation. As per the
    JBOSS specification, there r 2 ways of entering into the context of the JBOSS naming service. One is using the properties file n other is the one I used above.

    With the same naming code, I am able to access the EJBs that I have deployed in JBOSS.

    At some anonymous website, I read that only the components that are listed under global name space are accessible by the programs that are running in a different JVM or different context.

    Interestingly, when I deploy EJBs in JBOSS, they r falling under global JNDI space and are accessible from stand alone client programs. But, the datasources are falling under java:comp name space that are not accessible from outside. However, I could successfully use the datasources in EJB code to database operations.

    I have only tried this with MS SQLSERVER datasource. I have no idea of other datasource objects.

    Any research and sharing of knowledge in this regard is greatly appreciated.

    Thank you so much for all your interest and time.

    Have a good time.
  6. Jndi issue[ Go to top ]

    Hi Kala, how did you solve the problem you had on naming exception - jdbc not found with jboss and mysql ... kindly explain..
  7. first[ Go to top ]

    Jboss DataSources are not bound to java:comp
    they are bound to java:/datasource , you saw it yourself


    14:11:00,780 INFO [MSSQLDS] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:service=LocalTxCM,name=MSSQLDS to JNDI name -->'java:/MSSQLDS'<--

  8. unless[ Go to top ]

    unless you added it as a resource in the bean's descriptors
  9. HI i m facing the same problem[ Go to top ]

    Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); env.put(Context.PROVIDER_URL,"localhost"); env.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces"); Context context = new InitialContext(env); if(context!=null) System.out.println("context: success"); CartRemote cart = (CartRemote)context.lookup("CartBean"); if(cart!=null) System.out.println("cart: success"); This is a simple java client program output is printed as: context:success but after that run-main: context: success javax.naming.NameNotFoundException: CartBean not bound at org.jnp.server.NamingServer.getBinding(NamingServer.java:529) at org.jnp.server.NamingServer.getBinding(NamingServer.java:537) at org.jnp.server.NamingServer.getObject(NamingServer.java:543) at org.jnp.server.NamingServer.lookup(NamingServer.java:296) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587) at javax.naming.InitialContext.lookup(InitialContext.java:392) at ejb_stateful.CartClient.main(CartClient.java:32) BUILD SUCCESSFUL (total time: 0 seconds) Please give me the solution???????
  10. Re: HI i m facing the same problem[ Go to top ]

    jboss jndiview Global JNDI Namespace +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory) +- TopicConnectionFactory (class: org.jboss.naming.LinkRefPair) +- EventDispatcher (class: org.jboss.ws.eventing.mgmt.DispatcherDelegate) +- UserTransactionSessionFactory (proxy: $Proxy42 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory) +- UIL2ConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef) +- UIL2XAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef) +- QueueConnectionFactory (class: org.jboss.naming.LinkRefPair) +- topic (class: org.jnp.interfaces.NamingContext) | +- testDurableTopic (class: org.jboss.mq.SpyTopic) | +- testTopic (class: org.jboss.mq.SpyTopic) | +- securedTopic (class: org.jboss.mq.SpyTopic) +- queue (class: org.jnp.interfaces.NamingContext) | +- A (class: org.jboss.mq.SpyQueue) | +- testQueue (class: org.jboss.mq.SpyQueue) | +- ex (class: org.jboss.mq.SpyQueue) | +- DLQ (class: org.jboss.mq.SpyQueue) | +- D (class: org.jboss.mq.SpyQueue) | +- C (class: org.jboss.mq.SpyQueue) | +- B (class: org.jboss.mq.SpyQueue) +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory) +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction) +- jmx (class: org.jnp.interfaces.NamingContext) | +- invoker (class: org.jnp.interfaces.NamingContext) | | +- RMIAdaptor (proxy: $Proxy36 implements interface org.jboss.jmx.adaptor.rmi.RMIAdaptor,interface org.jboss.jmx.adaptor.rmi.RMIAdaptorExt) | +- rmi (class: org.jnp.interfaces.NamingContext) | | +- RMIAdaptor[link -> jmx/invoker/RMIAdaptor] (class: javax.naming.LinkRef) +- UILXAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef) +- UILConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef) we can ses it "TopicConnectionFactory" but when i code like following public static void main(String[] args)throws javax.naming.NamingException { Context ctx=null; TopicConnectionFactory conFactory=null; TopicConnection con=null; TopicSession session=null; Topic topic=null; try { Properties p = new Properties( ); p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); p.put(Context.URL_PKG_PREFIXES, " org.jboss.naming:org.jnp.interfaces"); p.put(Context.PROVIDER_URL, "jnp://localhost:1099"); ctx= new javax.naming.InitialContext(p); System.out.println("ctx:"+ctx); conFactory=(TopicConnectionFactory)ctx.lookup("TopicConnectionFactory"); System.out.println("Factory:"+conFactory); Enumeration enumeration = ctx.listBindings(""); for(;enumeration.hasMoreElements();) System.out.println(enumeration.nextElement().toString()); conFactory=(TopicConnectionFactory)ctx.lookup("ConnectionFactory"); topic=(Topic)ctx.lookup("topic/testTopic"); con=conFactory.createTopicConnection(); session=con.createTopicSession(false,Session.AUTO_ACKNOWLEDGE); TopicPublisher pub=session.createPublisher(topic); TextMessage msg=session.createTextMessage("first mestaage at :"+new Date() ); pub.send(msg); } catch(Exception e) { System.out.println(e.getMessage()); } finally { if (con != null) { try { con.close(); } catch (JMSException e) {} } } } output: ctx:[email protected] null when u replace "TopicConnectionFactory" by "topic/testTopic" output: ctx:[email protected] javax.naming.Reference u can get refernce both "TopicConnectionFactory" and "topic/testTopic" are in Global JNDI Namespace list how can i get TopicConnectionFactory reference? plz help me, thanks
  11. JNDI problem in JBoss[ Go to top ]

    Jboss just bind the datasourc in local jndi namespace, so
    you cannot retrieve it out of jboss jvm. If you want that,
    you should bind the datasource to the global namespace :
      In XX-ds.xml, under <jndi-name>, add this:

    test again ! :)

    btw, you must use jboss4.0
  12. thank you vic liu ![ Go to top ]

    vic liu! you kindly solved my problem:
    local/global namespaces.. of jboss
    i just siged-up here to
  13. same problem solved thanks to vic liu[ Go to top ]

    Not sure why it's like that, but vic liu's advice solved it for me. I'm accessing the oracle DS through the JNDI, but doing so from the SAME JVM, so I don't really see why the global namespace is necessary ... well, it worked, so it's good enough for me.
  14. A BIG THANK YOU :)[ Go to top ]

    Thanks a lot vic liu.. just signed in to thank you:)
  15. Similar problem[ Go to top ]

    I have a similar problem with a module under Jboss.
    I have a remote Jboss server, which uses an oracle-services.xml pool to connect to a database locally.
    Now, I want to access to that same database remotely, so I copied the oracle-services.xml file to the jboss/default/deploy directory, but it gives me the following message:
    17:27:02,639 WARN [ServiceController] Problem starting service jboss.jca:service=LocalTxCM,name=hsqldbDS
    org.jboss.deployment.DeploymentException: Could not bind ConnectionFactory into jndi: java:/DefaultDS

    I think I haven´t defined the address to look for the database (hsqldbDS is also set to localhost). Which tag should I modify?

    Thanks a lot!
  16. I want to discuss about my changes. I got that error when I encrypted the password for DB and changed at mssql-ds.xml file.

        <connection-url>jdbc:sqlserver://dbserver:1433;DatabaseName=dbname</c onnection-url> 

    <!--Replace with security domain below -->

            <!-- sql to call when connection is created
            <new-connection-sql>some arbitrary sql</new-connection-sql>        --> 

            <!-- sql to call on an existing pooled connection when it is obtained from pool
            <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>

          <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
             <type-mapping>MS SQLSERVER2000</type-mapping>


    And I changed the login-config.xml file below steps:

    <application-policy name="EncryptDBPassword">


                <login-module code="org.jboss.resource.security.SecureIdentityLoginModule" flag="required">

                    <module-option name="username">user name</module-option>

                    <module-option name="password">5dfc52b51bd355532e231e5701be9001</module-option>

                    <module-option name="managedConnectionFactoryName">jboss.jca:name=DefaultDS,service=LocalTxCM</module-option>




    Error in server.log.1.

         1. [org.jboss.resource.connectionmanager.ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=DefaultDS' to JNDI name 'java:DefaultDS' …

    [org.jboss.security.auth.spi.UsersRolesLoginModule] Failed to load users/passwords/role files


    1. 2. [org.jboss.ejb.plugins.jms.JMSContainerInvoker] JMS provider failure detected: 



    When I restarted the JBoss server, I got the error same with no 2 and others below errors.


    1. 2010-08-24 10:15:00,176 INFO  [org.jboss.resource.connectionmanager.ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=DefaultDS' to JNDI name 'java:DefaultDS'2010-08-24 10:15:00,208 ERROR [org.jboss.security.auth.spi.UsersRolesLoginModule] Failed to load users/passwords/role files state: FAILED


    1. [org.jboss.system.ServiceController] Problem starting service jboss.mq:service=StateManagerjava.lang.SecurityException: Invalid authentication attempt, principal=null


    1. ERROR [org.jboss.security.auth.spi.UsersRolesLoginModule] Failed to load users/passwords/role files

    java.io.IOException: No properties file: users.properties or defaults: defaultUsers.properties found

    What is mentioned for defaultUsers.properties file?

    1. ERROR [org.jboss.deployment.MainDeployer] Could not create deployment: file:/D:/Adobe/LiveCycle8/jboss/server/all/deploy/adobe-ds.xml org.jboss.deployment.DeploymentException: Trying to install an already registered mbean: jboss.jca:service=LocalTxCM,name=IDP_DS

    Same error with DefaultDS datasource I think.

    1. ERROR [org.jboss.deployment.MainDeployer] Could not create deployment: file:/D:/Adobe/LiveCycle8/jboss/server/all/deploy/mssql-ds.xml org.jboss.deployment.DeploymentException: Trying to install an already registered mbean: jboss.jca:service=LocalTxCM,name=DefaultDS