0 Replies Latest reply on Aug 15, 2007 6:45 AM by shankha Bhattacharya

    DataSource Conn problem with MSSQLSERVER in JBOSS

    shankha Bhattacharya Newbie

      Hi,
      I am facing a strange problem to deploy my application in jboss-4.2.1.GA server.

      When I start the server it will be expected to connect to the Data source in SQL server 2000.
      But It throws following exceptions.

      15:31:17,412 INFO [STDOUT] 15:31:17,287 ERROR [[/uc]] StandardWrapper.Throwable
      java.lang.ExceptionInInitializerError
      at com.cognizant.DAO.MSSQL.MSSQLDBConnection.(MSSQLDBConnection.java:49)
      at com.cognizant.DAO.MSSQL.MSSQLConfigUnitsDAO.retrieveBRP(MSSQLConfigUnitsDAO.java:372)
      at com.cognizant.unitcontroller.ConfigLoader.loadConfigUnit(ConfigLoader.java:160)

      ---
      ---
      --

      Basically I got the exception when I want to connect to the Data source in my code.

      To configure SQL server 2000 with JBOSS 4.2.1.GA i follow the following steps.


      1) In the web.xml File I add the following code.


      <resource-ref>
       <description>DB Connection</description>
       <res-ref-name>MSSQLDS</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
      </resource-ref>


      2) In the jboss-web.xml file entries are
      <resource-ref>
       <res-ref-name>MSSQLDS</res-ref-name>
       <jndi-name>java:MSSQLDS</jndi-name>
       </resource-ref>


      3) My JNDI Look up name of the Data source in the java code is
      appDataSource=java:/MSSQLDS



      Now I modified some of the files in the App server also.They are listed below.

      1) In the C:\jboss-4.2.1.GA\jboss-4.2.1.GA\server\default\deploy folder
      I update the mssql-ds.xml file with the following modifications.

      <datasources>

      <local-tx-datasource>
      <jndi-name>MSSQLDS</jndi-name>
      <!--use-java-context>false</use-java-context-->
      <connection-url>jdbc:microsoft:sqlserver://LAPTOPIB132;DatabaseName=rfid_ucprn</connection-url>
      <!--connection-url>jdbc:microsoft:sqlserver://10.236.70.221:1433;DatabaseName=rfid_ucprn</connection-url-->
      <driver-class>com.microsoft.jdbc.sqlserver.SQLServerDriver</driver-class>
      <user-name>sa</user-name>
      <password>admin</password>

      <min-pool-size>5</min-pool-size>
      <max-pool-size>20</max-pool-size>
      <idle-timeout-minutes>10</idle-timeout-minutes>
      <!-- sql to call when connection is created-->
      <new-connection-sql>SELECT * FROM UserAuth</new-connection-sql>


      <!-- sql to call on an existing pooled connection when it is obtained from pool-->
      <check-valid-connection-sql>SELECT BRPName,BRPMcName,BRPServerPort,BRPRemotePort from BRP</check-valid-connection-sql>


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

      </datasources>


      2)In the C:\jboss-4.2.1.GA\jboss-4.2.1.GA\server\default\conf folder I modified following Files. They are Listed Below.

      A)
      login-config.xml

      <application-policy name = "MSSQLDbRealm">
       <authentication>
       <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule"
       flag = "required">
       <module-option name = "principal">sa</module-option>
       <module-option name = "userName">sa</module-option>
       <module-option name = "password">admin</module-option>
       <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=MSSQLDS</module-option>
       </login-module>
       </authentication>
       </application-policy>



      B)
      standardjaws.xml

      <jaws>
       <datasource>java:/MSSQLDS</datasource>
       <type-mapping>MS SQLSERVER2000</type-mapping>
       <debug>false</debug>
      
       ....
       ....
       </jaws>


      C)
      standardjbosscmp-jdbc.xml

      <jbosscmp-jdbc>
      
       <defaults>
      
       <!--datasource>java:/DefaultDS</datasource-->
       <datasource>java:/MSSQLDS</datasource>
       <datasource-mapping>MS SQLSERVER2000</datasource-mapping>
      
       .....
       ......
      
      
      


      3) I also put all the necessary drivers in the appropriate locations as it is needed to create connection to the Data source.

      Driver locations : C:\jboss-4.2.1.GA\jboss-4.2.1.GA\server\default\lib
      
      msbase.jar,mssqlserver.jar,msutil.jar.


      ================================================
      Now I got the exception when I basically deploying the war file(by start the app server)
      Though I am able to connect to the Data base with Normal java-JDBC program with the same drivers.

      ==============================================

      In the http://localhost:8080/jmx-console/ in the service=JNDIView
      
      I observe following things.
      
      MSSQLDS
      org.jboss.resource.adapter.jdbc.WrapperDataSource
      
      MSSQLDS
      java:MSSQLDS
      javax.naming.LinkRef
      
      when I "Invoke Output JNDI info in XML format" button.


      ==============================================
      when I start the server with all these above mentioned configuration i got the following Exception.

      15:30:49,584 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=ConnectionFactoryBinding,name=JmsXA' to JNDI name 'java:JmsXA'
      15:30:50,037 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=MSSQLDS' to JNDI name 'java:MSSQLDS'
      15:30:50,381 INFO [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=.../deploy/jmx-console.war/
      15:31:15,099 INFO [TomcatDeployer] deploy, ctxPath=/uc, warUrl=.../tmp/deploy/tmp295uc-exp.war/
      15:31:15,365 INFO [WebappClassLoader] validateJarFile(C:\jboss-4.2.1.GA\jboss-4.2.1.GA\server\default\.\tmp\deploy\tmp295uc-exp.war\WEB-INF\lib\j2ee.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
      15:31:17,412 INFO [STDOUT] 15:31:17,287 ERROR [[/uc]] StandardWrapper.Throwable
      java.lang.ExceptionInInitializerError
      at com.cognizant.DAO.MSSQL.MSSQLDBConnection.<init>(MSSQLDBConnection.java:49)
      at com.cognizant.DAO.MSSQL.MSSQLConfigUnitsDAO.retrieveBRP(MSSQLConfigUnitsDAO.java:372)
      at com.cognizant.unitcontroller.ConfigLoader.loadConfigUnit(ConfigLoader.java:160)
      at com.cognizant.unitcontroller.ConfigLoader.init(ConfigLoader.java:62)
      at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
      at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
      at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4069)
      at org.apache.catalina.core.StandardContext.start(StandardContext.java:4373)
      at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:761)
      at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:741)
      at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:553)
      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.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
      at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
      at org.apache.catalina.core.StandardContext.init(StandardContext.java:5310)
      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.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
      at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
      at org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDeployer.java:301)
      at org.jboss.web.tomcat.service.TomcatDeployer.performDeploy(TomcatDeployer.java:104)
      at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:375)
      at org.jboss.web.WebModule.startModule(WebModule.java:83)
      at org.jboss.web.WebModule.startService(WebModule.java:61)
      at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
      at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
      at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
      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:155)
      at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
      at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
      at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
      at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
      at $Proxy0.start(Unknown Source)
      at org.jboss.system.ServiceController.start(ServiceController.java:417)
      at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
      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:155)
      at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
      at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
      at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
      at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
      at $Proxy45.start(Unknown Source)
      at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:466)
      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:155)
      at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
      at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
      at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
      at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
      at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
      at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
      at org.jboss.ws.integration.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:93)
      at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
      at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
      at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
      at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
      at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
      at $Proxy46.start(Unknown Source)
      at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
      at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
      at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
      at sun.reflect.GeneratedMethodAccessor18.invoke(Unknown Source)
      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:155)
      at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
      at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
      at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
      at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
      at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
      at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
      at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
      at $Proxy9.deploy(Unknown Source)
      at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
      at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:634)
      at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)


      The lookup code for data source is like below

      public DataSource getApplicationDataSource() {

      try {
       Hashtable env = new Hashtable();
      
       env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
       env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
       Context context = new InitialContext(env);
      
       dataSource = (DataSource) context.lookup("java:/MSSQLDS");
      
      
       } catch ( NamingException ex) {
       ex.printStackTrace();
       }
      
       return dataSource;
       }


      Sample of the Calling Code.

      DataSource ds = this.getApplicationDataSource();
       con = ds.getConnection();
       if(con!=null){
       dm = con.getMetaData();
       System.out.println("Driver Information");
       System.out.println("\tDriver Name: "+ dm.getDriverName());


      ===============================================

      Even If I try to use this Data source from a Stadalone Java program i got the
      javax.naming.NameNotFoundException: MSSQLDS 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)


      Please help me ...

      /shankha