3 Replies Latest reply on Jun 28, 2005 1:20 PM by mtedone1

    Problems trying to get a DataSource. It asks for a client

    mtedone1

      Hi, I have got a Simple ServiceLocator which performs a lookup on a datasource and returns such datasource to a session bean (which then uses it to perform straight SQL).

      During the lookup I get the following exception (also if I try to lookup the datasource from a plain java class):


      javax.naming.NamingException: Failed to find j2ee.clientName in jndi env


      This is the Datasource definition:

      <?xml version="1.0" encoding="UTF-8"?>
      
      <!-- $Id: mysql-ds.xml,v 1.3 2004/09/15 14:37:40 loubyansky Exp $ -->
      <!-- Datasource config for MySQL using 3.0.9 available from:
      http://www.mysql.com/downloads/api-jdbc-stable.html
      -->
      
      <datasources>
       <local-tx-datasource>
       <jndi-name>JemosSiteDS</jndi-name>
       <connection-url>jdbc:mysql://localhost:3306/site</connection-url>
       <driver-class>com.mysql.jdbc.Driver</driver-class>
       <user-name>username</user-name>
       <password>password</password>
      
       <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
       <metadata>
       <type-mapping>mySQL</type-mapping>
       </metadata>
       </local-tx-datasource>
      
      </datasources>
      


      And this is the bit of my service locator which performs the lookup (BTW, there are no problems with the JBoss JNDI context, as the other session and entity beans load fine):

      public DataSource getDataSource(int service) throws ServiceLocatorException {
      
       //The return value
       DataSource ds = null;
      
       //Ensures that a datasource hasn't been stored for too long
       Integer serviceKey = new Integer(service);
       checkDatasourceCache(serviceKey);
      
       //If there is a Datasource in the cache for the required
       //service, returns it
       if (dataSourcesCache.containsKey(serviceKey)) {
       ds = (DataSource)dataSourcesCache.get(serviceKey);
      
       //Updates the timestamp for when this service was last used.
       synchronized(dataSourcesTimes) {
       dataSourcesTimes.put(serviceKey, new Date(System.currentTimeMillis()));
       }
       return ds;
       }
      
       //Gets the JBoss properties
       Properties props = getJBossPropertites();
      
       try {
       ic = new InitialContext(props);
       ds = (DataSource)ic.lookup(getServiceName(service));
       synchronized(dataSourcesCache) {
       dataSourcesCache.put(serviceKey, ds);
       dataSourcesTimes.put(serviceKey, new Date(System.currentTimeMillis()));
       }
       LOG.debug("Datasource " + getServiceName(service) + "" +
       " successfully retrieved.");
       } catch (NamingException e) {
       LOG.warn("An error occurred while trying to " +
       "create a JBoss context.", e);
       throw new ServiceLocatorException(e);
       }
       return ds;
       }
      


      This is the value of the constant which I lookup:

      java:/JemosSiteDS

      I looked on the net and see that this problem can be solved by defining a client in the application-client.xml or jboss-client.xml, but I didn't understand how to do it, and why shall I do it. Why shall I declare a client for a Datasource which I want to search through the JNDI name?

        • 1. Re: Problems trying to get a DataSource. It asks for a clien
          darranl

          What are the properties that you are putting into the InitialContext constructor? I know you say that the lookup of your session beans works but unless you have specified otherwise you are probably obtaining them from a different namespace.

          Also when posting errors can you post the stack trace as well, it makes it easier to see what is happening.

          • 2. Re: Problems trying to get a DataSource. It asks for a clien
            mtedone1

             

            "darranl" wrote:
            What are the properties that you are putting into the InitialContext constructor? I know you say that the lookup of your session beans works but unless you have specified otherwise you are probably obtaining them from a different namespace.

            Also when posting errors can you post the stack trace as well, it makes it easier to see what is happening.


            This is the stack trace of the exception that I get:


            javax.naming.NamingException: Failed to find j2ee.clientName in jndi env
            at org.jboss.naming.client.java.javaURLContextFactory.getObjectInstance(javaURLContextFactory.java:66)
            at javax.naming.spi.NamingManager.getURLObject(NamingManager.java:584)
            at javax.naming.spi.NamingManager.getURLContext(NamingManager.java:533)
            at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:279)
            at javax.naming.InitialContext.lookup(InitialContext.java:351)
            at org.jemos.site.patterns.servicelocator.ServiceLocator.getDataSource(ServiceLocator.java:244)
            at org.jemos.site.ejbs.sessions.SiteStatsBean.countHits(SiteStatsBean.java:105)
            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:585)
            at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
            at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:214)
            at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
            at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:113)
            at org.jboss.webservice.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:51)
            at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
            at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:105)
            at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:283)
            at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:149)
            at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:128)
            at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
            at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
            at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
            at org.jboss.ejb.Container.invoke(Container.java:854)
            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:585)
            at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
            at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
            at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
            at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:242)
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:642)
            at org.jboss.invocation.jrmp.server.JRMPInvoker$MBeanServerAction.invoke(JRMPInvoker.java:775)
            at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:382)
            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:585)
            at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
            at sun.rmi.transport.Transport$1.run(Transport.java:153)
            at java.security.AccessController.doPrivileged(Native Method)
            at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
            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:595)
            2005-06-27 23:04:40,500 FATAL [org.jemos.site.ejbs.sessions.SiteStatsBean] ServiceLocator exception occurred while trying to load a datasource
            org.jemos.site.common.exception.ServiceLocatorException: javax.naming.NamingException: Failed to find j2ee.clientName in jndi env
            at org.jemos.site.patterns.servicelocator.ServiceLocator.getDataSource(ServiceLocator.java:254)
            at org.jemos.site.ejbs.sessions.SiteStatsBean.countHits(SiteStatsBean.java:105)
            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:585)
            at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
            at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:214)
            at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
            at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:113)
            at org.jboss.webservice.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:51)
            at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
            at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:105)
            at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:283)
            at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:149)
            at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:128)
            at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
            at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
            at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
            at org.jboss.ejb.Container.invoke(Container.java:854)
            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:585)
            at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
            at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
            at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
            at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:242)
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:642)
            at org.jboss.invocation.jrmp.server.JRMPInvoker$MBeanServerAction.invoke(JRMPInvoker.java:775)
            at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:382)
            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:585)
            at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
            at sun.rmi.transport.Transport$1.run(Transport.java:153)
            at java.security.AccessController.doPrivileged(Native Method)
            at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
            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:595)
            Caused by: javax.naming.NamingException: Failed to find j2ee.clientName in jndi env
            at org.jboss.naming.client.java.javaURLContextFactory.getObjectInstance(javaURLContextFactory.java:66)
            at javax.naming.spi.NamingManager.getURLObject(NamingManager.java:584)
            at javax.naming.spi.NamingManager.getURLContext(NamingManager.java:533)
            at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:279)
            at javax.naming.InitialContext.lookup(InitialContext.java:351)
            at org.jemos.site.patterns.servicelocator.ServiceLocator.getDataSource(ServiceLocator.java:244)
            ... 41 more


            And those are the properties that I'm setting:

            #
            # Contains the properties to create a Jboss Initial Context
            #
            java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
            java.naming.factory.url.pkgs=org.jboss.naming.client
            #--------------------------------------------------------------------
            # J E M O S S I T E
            #--------------------------------------------------------------------
            #
            #This property is set into the java.naming.provider.url property
            #at runtime, so that we have got a unique property file for all projects
            #and the ServiceLocator of each project reads its own property and
            #set the JBoss property
            org.jemos.site=jnp://localhost:1099


            • 3. Re: Problems trying to get a DataSource. It asks for a clien
              mtedone1

              I think I found the problem:

              The java.naming.factory.url.pkgs property should have been set to:

              org.jboss.naming:org.jnp.interfaces
              


              rather than org.jboss.naming.client

              At least I tried now with this new property and it works fine.