9 Replies Latest reply: Apr 21, 2013 1:05 AM by 924141 RSS

    Using Application Module outside ADF Application context

    924141
      I am trying to run application module using a standalone java class. Trying to use Application Module outside ADF Application context.

      I have created a jar file on my standalone java class, and added my ADF application jar files to the classpath while running my standalone java file as a Jar file.

      I could connect to the application module and I am able to get the response from my application module.
      Below is the code I used to invoke my application module method from my standalone java class.
           public static void main(String[] args) {
      
                System.out.println("Testing .....");
               String jdbcURL = "jdbc:oracle:thin:@localhost:1521:XE";
      
               Hashtable env = new Hashtable();
      
               env.put(Context.INITIAL_CONTEXT_FACTORY, JboContext.JBO_CONTEXT_FACTORY);
               env.put(JboContext.DEPLOY_PLATFORM, JboContext.PLATFORM_LOCAL);
      
               try {
                   Context ic = new InitialContext(env);
      
                   String defName = "com.org.model.BatchJobAppModule";
      
                   ApplicationModuleHome home = (ApplicationModuleHome)ic.lookup(defName);
                   ApplicationModule mbApplicationModule= (ApplicationModule)home.create();
                   mbApplicationModule.getTransaction().connect(jdbcURL, "HR", "HR");
                      ((BatchJobAppModuleImpl)mbApplicationModule).connectToDatabase();
                   
      
               } catch (NamingException ne) {
                   // TODO: Add catch code
                   ne.printStackTrace();
               }
      
           }
      {code}
      
      
      I am getting following messages.
      
      {code: warning}
      
      oracle.adf.share.ADFContext getCurrent
      WARNING: Automatically initializing a DefaultContext for getCurrent.
      Caller should ensure that a DefaultContext is proper for this use.
      Memory leaks and/or unexpected behaviour may occur if the automatic initialization is performed improperly.
      This message may be avoided by performing initADFContext before using getCurrent().
      To see the stack trace for thread that is initializing this, set the logging level of oracle.adf.share.ADFContext to FINEST
      
      Dec 14, 2012 10:16:37 PM oracle.security.jps.internal.config.xml.XmlConfigurationFactory initDefaultConfiguration
      SEVERE: java.io.FileNotFoundException: D:\satya\testPackage\.\config\jps-config.xml (The system cannot find the path specified)
      
      {code}
      
      
      I have another question regarding connecting to database.
      
      How to get connection from a datasource, to avoid supplying database credentials which will vary from one environment to another.
      
      Please let me know if any one has pointers.
      Thanks in advance.
      
      Regards,
      Satya
      
      Edited by: 921138 on Dec 14, 2012 9:20 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
        • 1. Re: Using Application Module outside ADF Application context
          452071
          Hi Satya,

          You could get some guidance by going into JDeveloper and on a java class type bc4jclient and ALT + Enter and you can get the general structure to create a client that access the BC layer. As a general rule of thumb you should not input the DB credentials directly the DB connection is handled by the AM itself.

          Juan Camilo
          • 2. Re: Using Application Module outside ADF Application context
            924141
            I agree with you, Juan that we shouldn't directly use credentials to get database connection in my java file. Can you please provide any sample code, if its readily available with you.

            Thats why I was looking for the options of jdbc data source to get database connection.

            Thanks,
            Satya
            • 3. Re: Using Application Module outside ADF Application context
              452071
              Perhaps, somthing like this can illustrate what you are trying to implement:
              http://techiecook.wordpress.com/2010/10/08/creating-root-application-module-instance-oracle-adf/ and here http://docs.oracle.com/cd/E23943_01/web.1111/b31974/bcservices.htm#CHDDDBFC

              Juan C.
              • 4. Re: Using Application Module outside ADF Application context
                924141
                Hi,

                This is my java file which I was running.
                package com.org;
                
                import com.org.model.BatchJobAppModuleImpl;
                
                import java.util.Hashtable;
                
                import javax.naming.Context;
                
                import javax.naming.InitialContext;
                import javax.naming.NamingException;
                
                import oracle.jbo.ApplicationModule;
                import oracle.jbo.ApplicationModuleHome;
                import oracle.jbo.JboContext;
                import oracle.jbo.Row;
                import oracle.jbo.ViewObject;
                import oracle.jbo.client.Configuration;
                import oracle.jbo.server.ApplicationModuleImpl;
                import oracle.jbo.server.ViewObjectImpl;
                
                public class TestMyClass {
                
                     public static void main(String[] args) {
                
                          System.out.println("Testing .....");
                      
                             String amDef = "com.org.model.BatchJobAppModule";
                             String config = "BatchJobAppModuleLocal";
                             ApplicationModule am =
                             Configuration.createRootApplicationModule(amDef, config);
                             
                             ViewObject vo= am.findViewObject("EmployeesView1");
                             vo.executeQuery();
                             while(vo.hasNext()){
                                 Row r= vo.next();
                //                    
                                    System.out.println(" >>>>> employee id: "+r.getAttribute("EmployeeId"));
                                }
                              Configuration.releaseRootApplicationModule(am, true);
                                
                                
                         } catch (Exception ne) {
                             // TODO: Add catch code
                             ne.printStackTrace();
                         }
                
                     }
                
                }
                {code}
                
                when I execute this class I am getting the following error.
                
                 MDS-00013: no metadata found for metadata object "/META-INF/connections.xml"
                e.jbo.DMLException: JBO-27200: JNDI failure. Unable to lookup Data Source at context jdbc/localDbDS
                   at oracle.jbo.server.DBTransactionImpl.lookupDataSource(DBTransactionImpl.java:1476)
                   at oracle.jbo.server.DBTransactionImpl2.connectToDataSource(DBTransactionImpl2.java:332)
                   at oracle.jbo.common.ampool.DefaultConnectionStrategy.connect(DefaultConnectionStrategy.java:203)
                   at oracle.jbo.server.ApplicationPoolMessageHandler.doPoolConnect(ApplicationPoolMessageHandler.java:594)
                   at oracle.jbo.server.ApplicationPoolMessageHandler.doPoolMessage(ApplicationPoolMessageHandler.java:422)
                   at oracle.jbo.server.ApplicationModuleImpl.doPoolMessage(ApplicationModuleImpl.java:8995)
                   at oracle.jbo.common.ampool.ApplicationPoolImpl.sendPoolMessage(ApplicationPoolImpl.java:4603)
                   at oracle.jbo.common.ampool.ApplicationPoolImpl.prepareApplicationModule(ApplicationPoolImpl.java:2533)
                   at oracle.jbo.common.ampool.ApplicationPoolImpl.doCheckout(ApplicationPoolImpl.java:2343)
                   at oracle.jbo.common.ampool.ApplicationPoolImpl.useApplicationModule(ApplicationPoolImpl.java:3242)
                   at oracle.jbo.common.ampool.SessionCookieImpl.useApplicationModule(SessionCookieImpl.java:572)
                   at oracle.jbo.common.ampool.SessionCookieImpl.useApplicationModule(SessionCookieImpl.java:505)
                   at oracle.jbo.common.ampool.SessionCookieImpl.useApplicationModule(SessionCookieImpl.java:500)
                   at oracle.jbo.client.Configuration.getApplicationModule(Configuration.java:1606)
                   at oracle.jbo.client.Configuration.createRootApplicationModule(Configuration.java:1511)
                   at oracle.jbo.client.Configuration.createRootApplicationModule(Configuration.java:1482)
                   at com.org.TestMyClass.main(TestMyClass.java:54)
                d by: javax.naming.NameNotFoundException: DataSourceContext could not locate a DataSource for the name:  jdbc/localDbDS
                   at oracle.jbo.server.DataSourceContext.lookup(DataSourceContext.java:109)
                   at javax.naming.InitialContext.lookup(InitialContext.java:392)
                   at oracle.jbo.server.DBTransactionImpl.lookupDataSource(DBTransactionImpl.java:1462)
                
                Edited by: 921138 on Apr 18, 2013 8:12 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                • 5. Re: Using Application Module outside ADF Application context
                  Shay Shmeltzer-Oracle
                  Two things to try:
                  1 Package your ADF BC layer as an ADF Library (not as a simple JAR).
                  2 Set the AM configuration so the connection uses direct JDBC connection and not a JDBC data source.
                  • 6. Re: Using Application Module outside ADF Application context
                    924141
                    Thanks Shay for your response.

                    When I run the standalone java class from jDeveloper 11.1.1.5.0, I am able to get application module and also able to get the out put from application module method. While running the java class jdev is exectung the class with javaw command. I tried to execute the same from commnd prompt, it didn't print anything on the command prompt. So I tried to execute java command with "java followed by class path" as below.
                    set JAVA_HOME=C:\Oracle\Middleware\jdk160_24\jre
                    set PATH=%JAVA_HOME%\bin;%PATH%
                    
                    java -classpath E:\poc\TestBatchJobClient\Project1\deploy\First.jar;E:\poc\BatchJobApp\Model\deploy\adf-share-base.jar;E:\poc\BatchJobApp\Model\deploy\adfm.jar;E:\poc\BatchJobApp\Model\deploy\BatchJobApp_Model.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.adf.share_11.1.1\adf-share-support.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.adf.share.ca_11.1.1\adf-share-ca.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.adf.share.ca_11.1.1\adf-share-base.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.adf.share_11.1.1\adflogginghandler.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.adf.share_11.1.1\adfsharembean.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.jmx_11.1.1\jmxframework.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.jmx_11.1.1\jmxspi.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.idm_11.1.1\identitystore.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.adf.model_11.1.1\adfm.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.adf.model_11.1.1\bc4j-mbeans.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.adf.model_11.1.1\bc4jwizard.jar;C:\Oracle\Middleware\oracle_common\modules\groovy-all-1.6.3.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.xdk_11.1.0\xmlparserv2.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.adf.model_11.1.1\db-ca.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.adf.model_11.1.1\jdev-cm.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.ldap_11.1.1\ojmisc.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.adf.share_11.1.1\commons-el.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.adf.share_11.1.1\jsp-el-api.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.adf.share_11.1.1\oracle-el.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.javatools_11.1.1\resourcebundle.jar;C:\Oracle\Middleware\modules\javax.activation_1.1.0.0_1-1.jar;C:\Oracle\Middleware\modules\javax.mail_1.1.0.0_1-4-1.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.mds_11.1.1\oramds.jar;C:\Oracle\Middleware\modules\javax.servlet_1.0.0.0_2-5.jar;C:\Oracle\Middleware\modules\javax.jsp_1.2.0.0_2-1.jar;C:\Oracle\Middleware\jdeveloper\ide\macros\..\..\..\wlserver_10.3\server\lib\ojdbc6.jar;C:\Oracle\Middleware\oracle_common\jlib\commons-cli-1.0.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.bali.share_11.1.1\share.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.xmlef_11.1.1\xmlef.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.dms_11.1.1\dms.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.xdk_11.1.0\xml.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.javacache_11.1.1\cache.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.ucp_11.1.0.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.odl_11.1.1\ojdl.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.javatools_11.1.1\javatools-nodeps.jar;C:\Oracle\Middleware\modules\javax.management_1.2.1.jar;C:\Oracle\Middleware\modules\javax.management.j2ee_1.0.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.mds_11.1.1\mdsrt.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.ldap_11.1.1\ldapjclnt11.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.jps_11.1.1\jps-api.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.jps_11.1.1\jps-common.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.jps_11.1.1\jps-ee.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.jps_11.1.1\jps-internal.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.jps_11.1.1\jps-unsupported-api.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.jps_11.1.1\jps-manifest.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.jps_11.1.1\jacc-spi.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.pki_11.1.1\oraclepki.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.osdt_11.1.1\osdt_core.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.osdt_11.1.1\osdt_cert.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.osdt_11.1.1\osdt_xmlsec.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.osdt_11.1.1\osdt_ws_sx.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.iau_11.1.1\fmw_audit.jar;C:\Oracle\Middleware\modules\javax.security.jacc_1.0.0.0_1-1.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.adf.security_11.1.1\adf-share-security.jar -Djavax.net.ssl.trustStore=C:\Oracle\Middleware\wlserver_10.3\server\lib\DemoTrust.jks com.org.TestMyClass
                    
                    {code}
                    
                    I got the same old error.
                    
                    Regards,
                    Satya                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
                    • 7. Re: Using Application Module outside ADF Application context
                      924141
                      Followup to the previous post...

                      The console output is...
                      Apr 20, 2013 4:20:56 PM oracle.adf.share.ADFContext getCurrent
                      WARNING: Automatically initializing a DefaultContext for getCurrent.
                      Caller should ensure that a DefaultContext is proper for this use.
                      Memory leaks and/or unexpected behaviour may occur if the automatic initialization is performed improperly.
                      This message may be avoided by performing initADFContext before using getCurrent().
                      To see the stack trace for thread that is initializing this, set the logging level of oracle.adf.share.ADFContext to FINEST
                      
                      Apr 20, 2013 4:20:56 PM oracle.security.jps.internal.config.xml.XmlConfigurationFactory initDefaultConfiguration
                      SEVERE: java.io.FileNotFoundException: C:\Users\sb38018\.\config\jps-config.xml (The system cannot find the path specified)
                      
                      Apr 20, 2013 4:20:58 PM oracle.adf.share.jndi.MDSBackingStore documentExists
                      INFO: MDS-00013: no metadata found for metadata object "/META-INF/connections.xml"
                      Exception in thread "main" oracle.jbo.JboException: JBO-29000: Unexpected exception caught: oracle.jbo.ConfigException, msg
                      =JBO-33003: Connection name localDb is not defined.
                              at oracle.jbo.common.ampool.PoolMgr.findPool(PoolMgr.java:529)
                              at oracle.jbo.client.Configuration.createRootApplicationModule(Configuration.java:1505)
                              at oracle.jbo.client.Configuration.createRootApplicationModule(Configuration.java:1482)
                              at com.org.TestMyClass.main(TestMyClass.java:57)
                      Caused by: oracle.jbo.ConfigException: JBO-33003: Connection name localDb is not defined.
                              at oracle.jbo.client.Configuration.initializeFromConnectionName(Configuration.java:1199)
                              at oracle.jbo.client.Configuration.getConfiguration(Configuration.java:648)
                              at oracle.jbo.common.ampool.PoolMgr.loadConfiguration(PoolMgr.java:605)
                              at oracle.jbo.common.ampool.PoolMgr.findPool(PoolMgr.java:526)
                              ... 3 more
                      ## Detail 0 ##
                      oracle.jbo.ConfigException: JBO-33003: Connection name localDb is not defined.
                              at oracle.jbo.client.Configuration.initializeFromConnectionName(Configuration.java:1199)
                              at oracle.jbo.client.Configuration.getConfiguration(Configuration.java:648)
                              at oracle.jbo.common.ampool.PoolMgr.loadConfiguration(PoolMgr.java:605)
                              at oracle.jbo.common.ampool.PoolMgr.findPool(PoolMgr.java:526)
                              at oracle.jbo.client.Configuration.createRootApplicationModule(Configuration.java:1505)
                              at oracle.jbo.client.Configuration.createRootApplicationModule(Configuration.java:1482)
                              at com.org.TestMyClass.main(TestMyClass.java:57)
                      
                      {code}
                      
                      Please advice.
                      I am able to connect using otherway, as I mentioned in my very first post of the thread. Is it a good practise?
                      Thanks,
                      Satya                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
                      • 8. Re: Using Application Module outside ADF Application context
                        dvohra21
                        Connection name localDb is not defined

                        Right click your Application Module in your model project -->click on Configurations-->check out for JDBCName .
                        Is the connection name localDb?
                        • 9. Re: Using Application Module outside ADF Application context
                          924141
                          Thanks for the response.

                          Yes, the connection name is localDB, still I am getting the same error, not sure why.

                          Any help is greatly appreciated.

                          Thanks,
                          Satya