Unable to resolve JNDI Lookup for Datasource to connect to the Database from a Portlet deployed in WC_Portlet Managed Server : javax.naming.NameNotFoundException (Doc ID 1316402.1)

Last updated on NOVEMBER 04, 2016

Applies to:

Oracle WebCenter Portal - Version 11.1.1.4.0 to 11.1.1.9.161018 [Release 11g]
Information in this document applies to any platform.
Checked for relevance on 04-Jun-2015

Symptoms

When attempting to connect to the database using a data source from a portlet deployed to the WC_Portlet container, the portlet can't connect to the database.
This same application works when deployed to the JDeveloper IntegratedWebLogicServer.


The WC_Portlet.out shows the following error:


<Apr 12, 2011 11:41:37 AM EDT> <Warning> <org.apache.myfaces.trinidadinternal.skin.SkinFactoryImpl> <BEA-000000> <Can't find a skin that matches family fusionFx and renderkit portlet, so we will use the simple skin>
in getConnection method
javax.naming.NameNotFoundException: Unable to resolve 'jdbc.ABC_DS'. Resolved 'jdbc' [Root exception is javax.naming.NameNotFoundException: Unable to resolve 'jdbc.ABC_DS'. Resolved 'jdbc']; remaining name 'ABC_DS'
at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:234)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:348)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:259)
at weblogic.jndi.internal.ServerNamingNode_1034_WLStub.lookup(Unknown Source)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:423)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:411)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
...


Caused by: javax.naming.NameNotFoundException: Unable to resolve 'jdbc.ABC_DS'. Resolved 'jdbc'
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1139)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:252)
at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:182)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:206)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:214)
at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:667)
at weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:230)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:522)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:146)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:518)



Steps To Reproduce:

The issue can be reproduced with the following steps:

  1. Create a Producer with a Portlet that connects to the database using a Data Source.
    For example:

    public class DBConnectionProvider {
       public DBConnectionProvider() {
          super();
       }

       public static Connection getConnection() throws NamingException,
              SQLException {

         System.out.println("in getConnection method");
         Context ctx = null;
         Hashtable ht = new Hashtable();
         ht.put(Context.INITIAL_CONTEXT_FACTORY,
         "weblogic.jndi.WLInitialContextFactory");
         // Use the following url for webcenter domain
         ht.put(Context.PROVIDER_URL, "t3://server:7001");

         // Use the following url for JDeveloper IntegratedWebLogicServer
         // ht.put(Context.PROVIDER_URL, "t3://localhost:7101");


         Connection conn = null;
         String jndilocation ="jdbc/ABC_DS";
         ctx = new InitialContext(ht);
         javax.sql.DataSource ds
             = (javax.sql.DataSource) ctx.lookup (jndilocation);
         conn = ds.getConnection();


         System.out.println("exiting getConnection method");
         return conn;
       }
    }


  2. Create the data source with jdbc/ABC_DS jndi name in the IntegratedWebLogicServer from JDeveloper.

  3. Deploy the producer to the IntegratedWebLogicServer.
    Ensure the Portlet is using the following Context.PROVIDER_URL:

    // Use the following url for JDeveloper IntegratedWebLogicServer
    ht.put(Context.PROVIDER_URL, "t3://localhost:7101");


  4. Register the producer in a custom WebCenter consumer application.

  5. Add the Portlet to a page in the custom WebCenter consumer application.

  6. Run the application in the IntegratedWebLogicServer.
    This will run without error.

  7. Create a data source with jdbc/ABS_DS name on a WebCenter domain and target the data source to the WC_Portlet managed server.

  8. Deploy the same producer to the WC_Portlet managed server.
    Ensure the Portlet is using the following Context.PROVIDER_URL:

    // Use the following url for webcenter domain
    ht.put(Context.PROVIDER_URL, "t3://server:7001");

    Where server is the server name where the WebCenter domain is running.

  9. Call the Portlet from WebCenter Spaces or a custom WebCenter consumer application.
    You will see the Portlet can't connect to the database.

    The WC_Portlet.out file should show the error mentioned above.

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms