Menu

HA-JDBC Setup - Lookup Error

Help
Oni
2012-09-06
2012-09-28
  • Oni

    Oni - 2012-09-06

    I am trying to setup HA-JDBC or some testing.
    I am using Tomcat 6, java 1.6.
    The ff are added in the web app lib:
    ha-jdbc-2.0.16-rc-1-jdk1.6.jar
    jgroups-2.6.10.jar
    jibx-run-1.2.1.jar
    log4j-1.2.15.jar
    ojdbc6.jar
    quartz-1.6.5.jar
    slf4j-api-1.5.7.jar
    slf4j-log4j12-1.5.7.jar

    created the ha-jdbc.xml file:

    <ha-jdbc>
      <sync id="full" class="net.sf.hajdbc.sync.FullSynchronizationStrategy">
        <property name="fetchSize">1000</property>
        <property name="maxBatchSize">100</property>
      </sync>
      <cluster balancer="simple" default-sync="full" dialect="oracle" meta-data-cache="eager" transaction-mode="serial">
        <datasource id="database1">
          <name>java:comp/env/jdbc/database1</name>
        </datasource>
        <datasource id="database2">
          <name>java:comp/env/jdbc/database2</name>
        </datasource>
      </cluster>
    </ha-jdbc>
    

    Added the resource elements under context in server.xml:

          <Context docBase="HAJDBC" path="/HAJDBC" reloadable="true" source="org.eclipse.jst.jee.server:HAJDBC">
             <Resource driverClassName="oracle.jdbc.driver.OracleDriver" name="jdbc/database1" password="PWD" type="javax.sql.DataSource" url="jdbc:oracle:thin:@..." username="USER"/>
    
      <Resource driverClassName="oracle.jdbc.driver.OracleDriver" name="jdbc/database2" password="PWD" type="javax.sql.DataSource" url="jdbc:oracle:thin:@..." username="USER"/>
    
      <Resource cluster="cluster1" config="file:///D:/Progs/workspace/HAJDBC/src/ha-jdbc.xml" factory="net.sf.hajdbc.sql.DataSourceFactory" name="jdbc/cluster" type="javax.sql.DataSource"/>
          </Context>
    

    Added the ff in web.xml:

      <resource-env-ref>
        <resource-env-ref-name>jdbc/database1</resource-env-ref-name>
        <resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
      </resource-env-ref>
      <resource-env-ref>
        <resource-env-ref-name>jdbc/database2</resource-env-ref-name>
        <resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
      </resource-env-ref>
      <resource-env-ref>
        <resource-env-ref-name>jdbc/cluster</resource-env-ref-name>
        <resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
      </resource-env-ref>
    

    During server startup, I encounter:

    Sep 6, 2012 3:49:24 PM org.apache.naming.NamingContext lookup
    WARNING: Unexpected exception resolving reference
    javax.management.RuntimeMBeanException: RuntimeException thrown in preRegister
    method
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.preRegisterInvoke(Unk
    nown Source)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(
    Unknown Source)
    at
    com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(Unknown
    Source)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(Unknown
    Source)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(Unknown Source)
    at net.sf.hajdbc.DatabaseClusterFactory.getDatabaseCluster(DatabaseClusterFact
    ory.java:118)
    at net.sf.hajdbc.sql.DataSourceFactory.getDatabaseCluster(DataSourceFactory.ja
    va:47)
    at net.sf.hajdbc.sql.CommonDataSourceObjectFactory.createProxy(CommonDataSourc
    eObjectFactory.java:99)
    at net.sf.hajdbc.sql.CommonDataSourceObjectFactory.getObjectInstance(CommonDat
    aSourceObjectFactory.java:91)
    at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory
    .java:140)
    at javax.naming.spi.NamingManager.getObjectInstance(Unknown Source)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:793)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
    at org.apache.catalina.core.NamingContextListener.addResource(NamingContextLis
    tener.java:1020)
    at org.apache.catalina.core.NamingContextListener.createNamingContext(NamingCo
    ntextListener.java:629)
    at org.apache.catalina.core.NamingContextListener.lifecycleEvent(NamingContext
    Listener.java:237)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSuppo
    rt.java:119)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4540)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
    at org.apache.catalina.core.StandardService.start(StandardService.java:519)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
    Caused by: java.lang.IllegalStateException:
    java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException:
    Failed to perform naming lookup of java:comp/env/jdbc/database1
    at net.sf.hajdbc.sql.AbstractDatabaseCluster.getAliveMap(AbstractDatabaseClust
    er.java:215)
    at net.sf.hajdbc.sql.AbstractDatabaseCluster.start(AbstractDatabaseCluster.jav
    a:697)
    at net.sf.hajdbc.sql.AbstractDatabaseCluster.preRegister(AbstractDatabaseClust
    er.java:1052)
    at com.sun.jmx.mbeanserver.MBeanSupport.preRegister(Unknown Source)
    ... 33 more
    Caused by: java.util.concurrent.ExecutionException:
    java.lang.IllegalArgumentException: Failed to perform naming lookup of
    java:comp/env/jdbc/database1
    at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
    at java.util.concurrent.FutureTask.get(Unknown Source)
    at net.sf.hajdbc.sql.AbstractDatabaseCluster.getAliveMap(AbstractDatabaseClust
    er.java:210)
    ... 36 more
    Caused by: java.lang.IllegalArgumentException: Failed to perform naming lookup
    of java:comp/env/jdbc/database1
    at net.sf.hajdbc.sql.CommonDataSourceDatabase.createDataSource(CommonDataSourc
    eDatabase.java:102)
    at net.sf.hajdbc.sql.CommonDataSourceDatabase.createConnectionFactory(CommonDa
    taSourceDatabase.java:88)
    at net.sf.hajdbc.sql.AbstractDatabaseCluster.test(AbstractDatabaseCluster.java
    :248)
    at net.sf.hajdbc.sql.AbstractDatabaseCluster.isAlive(AbstractDatabaseCluster.j
    ava:230)
    at net.sf.hajdbc.sql.AbstractDatabaseCluster$2.call(AbstractDatabaseCluster.ja
    va:192)
    at net.sf.hajdbc.sql.AbstractDatabaseCluster$2.call(AbstractDatabaseCluster.ja
    va:189)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: javax.naming.NameNotFoundException: Name comp is not bound in this
    Context
    at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:152)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at net.sf.hajdbc.sql.CommonDataSourceDatabase.createDataSource(CommonDataSourc
    eDatabase.java:98)
    ... 10 more
    Sep 6, 2012 3:49:24 PM org.apache.catalina.core.NamingContextListener
    addResource
    WARNING: Failed to register in JMX: javax.naming.NamingException:
    RuntimeException thrown in preRegister method

    Please advise if I am missing something. Already tried using
    Resource/ResourceLink for the lookup error but the error persists. Thanks.

     
  • Oni

    Oni - 2012-09-07

    I tested that if I remove the "jdbc/cluster" resource and the server is
    started up successfully, I can access "java:/comp/jdbc/database1" resource in
    a test page.

    Please help advise. Thanks :D

     
  • Paul Ferraro

    Paul Ferraro - 2012-09-12

    The above configuration is a problem because the comp/env namespace doesn't
    yet exist when the ha-jdbc datasource resource is created. Instead, try this:

    • Remove the jdbc/database1 and jdbc/database2 <Resource/> elements from context.xml.
    • Remove the jdbc/database1 and jdbc/database2 <resource-env-ref/> elements from web.xml
    • Change your ha-jdbc.xml database definitions to the following:

    <datasource id="database1">
    <name>oracle.jdbc.pool.OracleDataSource</name>
    <property name="serverName">...</property>
    <property name="portNumber">...</property>
    <property name="databaseName">...</property>
    </datasource>
    <datasource id="database2">
    <name>oracle.jdbc.pool.OracleDataSource</name>
    <property name="serverName">...</property>
    <property name="portNumber">...</property>
    <property name="databaseName">...</property>
    </datasource>

     

Log in to post a comment.