Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 367347

Summary: JNDI Datasource not being used with BIRT 3.7.1
Product: z_Archived Reporter: Ramses Gomez <ramgom>
Component: BIRTAssignee: Birt-ReportViewer <Birt-ReportViewer-inbox>
Status: NEW --- QA Contact: Sissi Zhu <szhu>
Severity: major    
Priority: P3 CC: bluesoldier, jasonweathersby
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
datasource config file
none
sample provided by RedHat none

Description Ramses Gomez CLA 2011-12-21 11:03:31 EST
Build Identifier:  20110916-0149

Hi I'm using birt war file inside my application ear file deploying to JBoss AEP 5.1 and I'm getting an error when try to view a report.
I'm using the odaJndiName property to access the datasource and I have all other information removed to make sure only the jndi datasource is being used but I'm getting a null pointer exception. I've been tracing this issue and the problem is birt can not find the jndi name and it tries to use the datasource driver to connect and since there is none defined it crashes.
What is interesting about this is if I use birt 2.6.1 it works with no issue but if I use birt 3.7.1 it fails, both deployed under the same conditions.
I'm using jndi references because we our application is deployed to various application servers.
We have defined in the web.xml file the <resource-ref> and added a jboss-web.xml file defining the <resource-ref> as well.
This is the log:

Dec 21, 2011 11:00:39 AM org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager JDBCDriverManager
FINE: JDBCDriverManager starts up
Dec 21, 2011 11:00:39 AM org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager getConnection
FINE: Request JDBC Connection: driverClass=null; url=null; jndi name url=java:comp/env/jdbc/BamServerDataSource
Dec 21, 2011 11:00:39 AM org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager getJndiDSConnection
FINER: Calling getJndiDSConnection: JNDI name url=java:comp/env/jdbc/BamServerDataSource
Dec 21, 2011 11:00:39 AM JndiDataSource getConnection
FINER: ENTRY java:comp/env/jdbc/BamServerDataSource
Dec 21, 2011 11:00:39 AM org.eclipse.birt.report.data.oda.jdbc.JndiDataSource getConnection
INFO: javax.naming.NameNotFoundException: env not bound
Dec 21, 2011 11:00:39 AM JndiDataSource getConnection
FINER: RETURN null
Dec 21, 2011 11:00:39 AM org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager getJndiDSConnection
INFO: getJndiDSConnection: Unable to get JNDI data source connection; java.sql.SQLException: env not bound
Dec 21, 2011 11:00:39 AM org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager loadDriverExtensions
INFO: Found JDBC driverinfo extension: driverClass=org.apache.derby.jdbc.EmbeddedDriver, connectionFactory=null
Dec 21, 2011 11:00:39 AM org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager loadDriverExtensions
INFO: Found JDBC driverinfo extension: driverClass=org.eclipse.birt.report.data.oda.hive.HiveDriver, connectionFactory=null
Dec 21, 2011 11:00:39 AM org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager loadDriverExtensions
INFO: Found JDBC driverinfo extension: driverClass=org.eclipse.birt.report.data.oda.sampledb.Driver, connectionFactory=org.eclipse.birt.report.data.oda.sampledb.SampleDBJDBCConnectionFactory
Dec 21, 2011 11:00:39 AM org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager doConnect
FINER: Calling DriverManager.getConnection. url=null
Dec 21, 2011 11:00:39 AM org.eclipse.birt.report.engine.api.impl.RunTask doRun
SEVERE: An error happened while running the report. Cause:
java.lang.NullPointerException
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:169)
	at org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.findDriver(JDBCDriverManager.java:746)
	at org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.registerDriver(JDBCDriverManager.java:903)
	at org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.doConnect(JDBCDriverManager.java:257)
	at org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.getConnection(JDBCDriverManager.java:214)
	at org.eclipse.birt.report.data.oda.jdbc.Connection.connectByUrl(Connection.java:237)
	at org.eclipse.birt.report.data.oda.jdbc.Connection.open(Connection.java:162)
	at org.eclipse.datatools.connectivity.oda.consumer.helper.OdaConnection.open(OdaConnection.java:250)
	at org.eclipse.birt.data.engine.odaconsumer.ConnectionManager.openConnection(ConnectionManager.java:165)
	at org.eclipse.birt.data.engine.executor.DataSource.newConnection(DataSource.java:224)
	at org.eclipse.birt.data.engine.executor.DataSource.open(DataSource.java:212)
	at org.eclipse.birt.data.engine.impl.DataSourceRuntime.openOdiDataSource(DataSourceRuntime.java:217)
	at org.eclipse.birt.data.engine.impl.QueryExecutor.openDataSource(QueryExecutor.java:407)
	at org.eclipse.birt.data.engine.impl.QueryExecutor.prepareExecution(QueryExecutor.java:317)
	at org.eclipse.birt.data.engine.impl.PreparedQuery.doPrepare(PreparedQuery.java:455)
	at org.eclipse.birt.data.engine.impl.PreparedDataSourceQuery.produceQueryResults(PreparedDataSourceQuery.java:190)
	at org.eclipse.birt.data.engine.impl.PreparedDataSourceQuery.execute(PreparedDataSourceQuery.java:178)
	at org.eclipse.birt.data.engine.impl.PreparedOdaDSQuery.execute(PreparedOdaDSQuery.java:145)
	at org.eclipse.birt.report.data.adapter.impl.DataRequestSessionImpl.execute(DataRequestSessionImpl.java:620)
	at org.eclipse.birt.report.engine.data.dte.DteDataEngine.doExecuteQuery(DteDataEngine.java:152)
	at org.eclipse.birt.report.engine.data.dte.DataGenerationEngine.doExecuteQuery(DataGenerationEngine.java:80)
	at org.eclipse.birt.report.engine.data.dte.AbstractDataEngine.execute(AbstractDataEngine.java:267)
	at org.eclipse.birt.report.engine.executor.ExecutionContext.executeQuery(ExecutionContext.java:1905)
	at org.eclipse.birt.report.engine.executor.QueryItemExecutor.executeQuery(QueryItemExecutor.java:80)
	at org.eclipse.birt.report.engine.executor.TableItemExecutor.execute(TableItemExecutor.java:62)
	at org.eclipse.birt.report.engine.internal.executor.wrap.WrappedReportItemExecutor.execute(WrappedReportItemExecutor.java:46)
	at org.eclipse.birt.report.engine.internal.executor.emitter.ReportItemEmitterExecutor.execute(ReportItemEmitterExecutor.java:46)
	at org.eclipse.birt.report.engine.internal.executor.dup.SuppressDuplicateItemExecutor.execute(SuppressDuplicateItemExecutor.java:43)
	at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:65)
	at org.eclipse.birt.report.engine.layout.html.HTMLPageLM.layout(HTMLPageLM.java:92)
	at org.eclipse.birt.report.engine.layout.html.HTMLReportLayoutEngine.layout(HTMLReportLayoutEngine.java:100)
	at org.eclipse.birt.report.engine.presentation.ReportDocumentBuilder.build(ReportDocumentBuilder.java:258)
	at org.eclipse.birt.report.engine.api.impl.RunTask.doRun(RunTask.java:260)
	at org.eclipse.birt.report.engine.api.impl.RunTask.run(RunTask.java:85)
	at org.eclipse.birt.report.service.ReportEngineService.runReport(ReportEngineService.java:1317)
	at org.eclipse.birt.report.service.BirtViewerReportService.runReport(BirtViewerReportService.java:158)
	at org.eclipse.birt.report.service.actionhandler.BirtRunReportActionHandler.__execute(BirtRunReportActionHandler.java:81)
	at org.eclipse.birt.report.service.actionhandler.BirtGetPageActionHandler.__checkDocumentExists(BirtGetPageActionHandler.java:58)
	at org.eclipse.birt.report.service.actionhandler.AbstractGetPageActionHandler.prepareParameters(AbstractGetPageActionHandler.java:119)
	at org.eclipse.birt.report.service.actionhandler.AbstractGetPageActionHandler.__execute(AbstractGetPageActionHandler.java:104)
	at org.eclipse.birt.report.service.actionhandler.AbstractBaseActionHandler.execute(AbstractBaseActionHandler.java:90)
	at org.eclipse.birt.report.soapengine.processor.AbstractBaseDocumentProcessor.__executeAction(AbstractBaseDocumentProcessor.java:47)
	at org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.executeAction(AbstractBaseComponentProcessor.java:143)
	at org.eclipse.birt.report.soapengine.processor.BirtDocumentProcessor.handleGetPage(BirtDocumentProcessor.java:87)
	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:597)
	at org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.process(AbstractBaseComponentProcessor.java:112)
	at org.eclipse.birt.report.soapengine.endpoint.BirtSoapBindingImpl.getUpdatedObjects(BirtSoapBindingImpl.java:66)
	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:597)
	at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)
	at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)
	at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
	at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
	at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
	at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
	at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)
	at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
	at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
	at org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.doPost(BirtSoapMessageDispatcherServlet.java:265)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
	at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.service(BirtSoapMessageDispatcherServlet.java:122)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.eclipse.birt.report.filter.ViewerFilter.doFilter(ViewerFilter.java:68)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:183)
	at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:95)
	at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
	at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:451)
	at java.lang.Thread.run(Thread.java:662)
Dec 21, 2011 11:00:39 AM DataEngineImpl shutdown
FINER: ENTRY
Dec 21, 2011 11:00:39 AM org.eclipse.birt.data.engine.impl.DataEngineImpl shutdown
FINE: Data engine shuts down
Dec 21, 2011 11:00:40 AM org.eclipse.birt.data.engine.impl.DataEngineImpl shutdown
FINER: RETURN


Reproducible: Always
Comment 1 Ramses Gomez CLA 2012-01-16 10:35:20 EST
Any update on this issue?
Comment 2 Jason Weathersby CLA 2012-01-17 12:49:24 EST
What db are you accessing?  Where do you have the driver jar?

Jason
Comment 3 Ramses Gomez CLA 2012-02-14 11:10:36 EST
Hi Jason,

Sorry I just saw your comment I thought I would've gotten and email for the update.

This is not related to the driver jars this is related that Birt can not access the resource reference:

Dec 21, 2011 11:00:39 AM org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager JDBCDriverManager
FINE: JDBCDriverManager starts up
Dec 21, 2011 11:00:39 AM org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager getConnection
FINE: Request JDBC Connection: driverClass=null; url=null; jndi name url=java:comp/env/jdbc/BamServerDataSource
Dec 21, 2011 11:00:39 AM org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager getJndiDSConnection
FINER: Calling getJndiDSConnection: JNDI name url=java:comp/env/jdbc/BamServerDataSource
Dec 21, 2011 11:00:39 AM JndiDataSource getConnection
FINER: ENTRY java:comp/env/jdbc/BamServerDataSource
Dec 21, 2011 11:00:39 AM org.eclipse.birt.report.data.oda.jdbc.JndiDataSource getConnection
INFO: javax.naming.NameNotFoundException: env not bound
Dec 21, 2011 11:00:39 AM JndiDataSource getConnection


as you can see for some reason the org.eclipse.birt.report.data.oda.jdbc.JndiDataSource can not access java:comp/env, if instead I use the global JNDI name it works with no issues. The problem is we can not use the global JNDI name since our application needs to be deployed to multiples application servers and we can not tie the report to a specific global JNDI name.

The nullpointer exception is related to not having a driver specified in the report since I only want to use the JNDI name.

Thanks
Comment 4 Jason Weathersby CLA 2012-02-15 11:01:43 EST
Can you post some details on how you setup your JNDI connection so we can try to reproduce?

Jason
Comment 5 Ramses Gomez CLA 2012-02-15 11:21:48 EST
This is what I've done:

Created the appropriate datasource in jboss, then added the jboss-web.xml file to the war file with:

<resource-ref>
		<res-ref-name>jdbc/BamServerDataSourceRef</res-ref-name>
		<jndi-name>java:jdbc/BamServerDataSource</jndi-name>
	</resource-ref>

Then added the resource reference to the web.xml file:

<resource-ref>
		<description/>
		<res-ref-name>jdbc/BamServerDataSourceRef</res-ref-name>
		<res-type>javax.sql.DataSource</res-type> 
       		<res-auth>Container</res-auth> 
	</resource-ref>

I'm also uploading two test cases I created one for Birt 2.6.2 and the other one for 3.7.1, it has a very simple report with the appropriate set up.

This is the statemente to crete the table to test:

CREATE  TABLE `test`.`test` (
  `idtest` INT(11)  NOT NULL AUTO_INCREMENT ,
  `name` VARCHAR(45) NULL ,
  PRIMARY KEY (`idtest`) );
  
 You will find three file:
 
 the datasource configuration xml file plus the two birt war files with the appropriate files inside.
Comment 6 Ramses Gomez CLA 2012-02-15 11:38:27 EST
Created attachment 211051 [details]
datasource config file
Comment 7 Ramses Gomez CLA 2012-02-15 11:42:17 EST
I wasn't able to upload the war files so I put them in the cloud and these are the links to access them:

Birt 2.6.2
https://docs.google.com/open?id=0BxpMhw7SOiXONTY4ZjUyNjAtMTczYi00MTEzLTg4MDUtMDU5ZWZhYTNlZDlk

Birt 3.7.1
https://docs.google.com/open?id=0BxpMhw7SOiXOMWEzNjVkZjctM2M1ZS00ZGM3LWIyZjctMGU2NTI0NDZlMTFj
Comment 8 Jason Weathersby CLA 2012-02-15 14:22:04 EST
What version of JBoss are you using?  I created a mysql-ds.xml file and copied it to my deploy directory.
<?xml version="1.0" encoding="UTF-8"?>

<!-- $Id: mysql-ds.xml 41016 2006-02-07 14:23:00Z acoliver $ -->
<!--  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>MySqlDS</jndi-name>
    <connection-url>jdbc:mysql://localhost:3306/mydb</connection-url>
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <user-name>root</user-name>
    <password>root</password>
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
    <!-- should only be used on drivers after 3.22.1 with "ping" support
    <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
    -->
    <!-- sql to call when connection is created
    <new-connection-sql>some arbitrary sql</new-connection-sql>
      -->
    <!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers
    <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
      -->

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



I then just use this for my Jndi url:

java:/MySqlDS
Comment 9 Ramses Gomez CLA 2012-02-15 14:45:57 EST
Hi Jason,

Yes that's right if you use the GLobal JNDI name it works (java:/MySqlDS) however we can not use the global JNDI name we need to use a reference, since the same report should be able to work with multiple application servers (websphere, glassfish)

We are using Jboss EAP 5.1.2

Thanks,
Comment 10 Jason Weathersby CLA 2012-02-15 16:53:12 EST
Maybe I am not setting this up correctly but I have my data source:

<?xml version="1.0" encoding="UTF-8"?>

<!-- $Id: mysql-ds.xml 41016 2006-02-07 14:23:00Z acoliver $ -->
<!--  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>env/jdbc/MySqlDS</jndi-name>
    <connection-url>jdbc:mysql://localhost:3306/mydb</connection-url>
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <user-name>root</user-name>
    <password>root</password>
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
    <!-- should only be used on drivers after 3.22.1 with "ping" support
    <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
    -->
    <!-- sql to call when connection is created
    <new-connection-sql>some arbitrary sql</new-connection-sql>
      -->
    <!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers
    <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
      -->

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

and jboss web

<jboss-web>
	<context-root>birt</context-root>
    <resource-ref>
        <res-ref-name>jdbc/MySqlDB</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <jndi-name>env/jdbc/MySqlDS</jndi-name>
    </resource-ref>
</jboss-web>
and this in my web.xml

<resource-ref>
  <description>
    Resource reference to a factory for java.sql.Connection
    instances that may be used for talking to a particular
    database that is configured in the server.xml file.
  </description>
  <res-ref-name>
    jdbc/MySqlDB
  </res-ref-name>
  <res-type>
    javax.sql.DataSource
  </res-type>
  <res-auth>
    Container
  </res-auth>
</resource-ref>	

I use this jndi name in the report:
java:env/jdbc/MySqlDS

This works, but if I change to java:comp/env/jdbc/MySqlDB it fails
Comment 11 Ramses Gomez CLA 2012-02-15 17:49:04 EST
Yes you still have it wrong, still using the global jndi name a simple way to do it is add ref to every reference name.

The jndi nmae you set in the datasource file is the global jndi name, I would advise you not to use env at the begining so lets set it up to: jdbc/MySqlDS


<datasources>
  <local-tx-datasource>
    <jndi-name>jdbc/MySqlDS</jndi-name> (Global JNDI name)


Then you set up the resource reference in the web.xml file. You are telling your application to define a resource reference. Lets name it jdbc/MySqlDBRef


<resource-ref>
  <description>
    Resource reference to a factory for java.sql.Connection
    instances that may be used for talking to a particular
    database that is configured in the server.xml file.
  </description>
  <res-ref-name>
    jdbc/MySqlDBRef     (Resource Reference JNDI name)
  </res-ref-name>
  <res-type>
    javax.sql.DataSource
  </res-type>
  <res-auth>
    Container
  </res-auth>
</resource-ref>    

Then you map the resource reference JNDI name to the Global Jndi name in the jboss-web.xml file:

<jboss-web>
    <context-root>birt</context-root>
    <resource-ref>
        <res-ref-name>jdbc/MySqlDBRef</res-ref-name> (Resource Reference JNDI name)
        <res-type>javax.sql.DataSource</res-type>
        <jndi-name>java:jdbc/MySqlDS</jndi-name> (Global JNDI name)
    </resource-ref>
</jboss-web>

All resource references get created in the component context (hence using java:comp/env), now in your report you will use the JNDI Reference Name that gets created in the component context: java:comp/env/jdbc/MySqlDSRef

What's the idea behind this, if I want to use this report in glassfish which the global jndi name is jdbc/MySqlDS (notice no java: at the begining) I don't have to change my report since it is using a reference all I do is define the right sun-web.xml that does the mapping (similar to jboss-web.xml)

Hope this clarifies the problem you are having.
Comment 12 Jason Weathersby CLA 2012-02-16 11:05:41 EST
Thanks for the clarification. The code in the JDBC driver that does the lookup is defined like:

            initCtx = new InitialContext( getDriverJndiProperties() );
            namedObject = initCtx.lookup( jndiNameUrl );

Which means that jdbc/MySqlDBRef  is not being located in this example.  You would not have a JSP page that we could add to the viewer that successfully looks up the local JNDI would you?  This would just be a test.  Be sure to use the 3.7.1 viewer as it has the POJO runtime instead of the OSGi runtime.
Comment 13 Ramses Gomez CLA 2012-02-16 11:29:04 EST
Hi Jason,

Sorry I'm not able to understand when you need from me? Can you please elaborate?

Thanks
Comment 14 Jason Weathersby CLA 2012-02-16 12:15:29 EST
This is strange.  I created a jsp page and added it to the viewer:

<html>
<head><title>Enter to database</title></head>
<body>
<table>
<%@ page import="java.util.*" %>
<%@ page import="javax.sql.*;" %>

<% 

java.sql.Connection c1;
java.sql.Statement s1;
java.sql.ResultSet rs1;
java.sql.PreparedStatement pst1;
DataSource paymentDB;

c1=null;
s1=null;
pst1=null;
rs1=null;



try{
javax.naming.Context initCtx1 = new javax.naming.InitialContext();
javax.naming.Context envCtx1 = (javax.naming.Context) initCtx1.lookup("java:comp/env");
paymentDB = (DataSource) envCtx1.lookup("jdbc/MySqlDBref");


c1 = paymentDB.getConnection();
String sq1= "select * from orderdetails";
pst1 = c1.prepareStatement(sq1);
rs1 = pst1.executeQuery();
while( rs1.next() ){
%>

<tr>
<td>tst<%= rs1.getString("productCode") %></td>
</tr>
<%
}


if(pst1!=null) pst1.close();
if(rs1!=null) rs1.close();
if(c1!=null) c1.close();
}catch(Exception e){
System.out.println("inside the context exception");
e.printStackTrace();
}

%>

</body>
</html>

This works.  But the following beforeFactory script always has an exception.

importPackage( Packages.java.io );
importPackage( Packages.javax.naming );
importPackage( Packages.java.util );

out = new PrintWriter( new FileWriter( "c:/test/jndievents2.txt", true ) );

try{
initCtx1 = new javax.naming.InitialContext();
envCtx1 =  initCtx1.lookup("java:comp/env");
paymentDB =  envCtx1.lookup("jdbc/MySqlDBref");
out.println( "con "+ paymentDB );
	}catch(e){
	out.println( "exception "+ e );
}

out.close();

This seems like local refs are not available in the report engine.
Comment 15 Jason Weathersby CLA 2012-02-16 12:32:24 EST
This is strange.  I created a jsp page and added it to the viewer:

<html>
<head><title>Enter to database</title></head>
<body>
<table>
<%@ page import="java.util.*" %>
<%@ page import="javax.sql.*;" %>

<% 

java.sql.Connection c1;
java.sql.Statement s1;
java.sql.ResultSet rs1;
java.sql.PreparedStatement pst1;
DataSource paymentDB;

c1=null;
s1=null;
pst1=null;
rs1=null;



try{
javax.naming.Context initCtx1 = new javax.naming.InitialContext();
javax.naming.Context envCtx1 = (javax.naming.Context) initCtx1.lookup("java:comp/env");
paymentDB = (DataSource) envCtx1.lookup("jdbc/MySqlDBref");


c1 = paymentDB.getConnection();
String sq1= "select * from orderdetails";
pst1 = c1.prepareStatement(sq1);
rs1 = pst1.executeQuery();
while( rs1.next() ){
%>

<tr>
<td>tst<%= rs1.getString("productCode") %></td>
</tr>
<%
}


if(pst1!=null) pst1.close();
if(rs1!=null) rs1.close();
if(c1!=null) c1.close();
}catch(Exception e){
System.out.println("inside the context exception");
e.printStackTrace();
}

%>

</body>
</html>

This works.  But the following beforeFactory script always has an exception.

importPackage( Packages.java.io );
importPackage( Packages.javax.naming );
importPackage( Packages.java.util );

out = new PrintWriter( new FileWriter( "c:/test/jndievents2.txt", true ) );

try{
initCtx1 = new javax.naming.InitialContext();
envCtx1 =  initCtx1.lookup("java:comp/env");
paymentDB =  envCtx1.lookup("jdbc/MySqlDBref");
out.println( "con "+ paymentDB );
	}catch(e){
	out.println( "exception "+ e );
}

out.close();

This seems like local refs are not available in the report engine.
Comment 16 Ramses Gomez CLA 2012-02-16 12:36:41 EST
So what does that means now? 
What would be the next step?
Comment 17 Jason Weathersby CLA 2012-02-16 13:04:45 EST
I will ask someone on the data team to look at it.
Comment 18 Jason Weathersby CLA 2012-02-16 13:33:52 EST
Also as a work around you know the jndi url can be changed using property binding, script, or a connection profile xml file.
Comment 19 Ramses Gomez CLA 2012-02-16 13:38:45 EST
Can you please give me more details? it might help us as a work around.

Thanks,
Comment 20 Jason Weathersby CLA 2012-02-16 13:52:11 EST
Sure.  Script

Add a beforeOpen javascript event handler and put in something like:

this.setExtensionProperty("odaJndiName","thenameyouwanttouse");

The name can come from a report parameter params["myjndi"].value or from session variable reportContext.getHttpServletRequest().getSession().getAttribute("myjndiname"); or from some external Java class or properties file.  

The property binding feature is similar to the script approach, just create an expression in the data source editor property binding tab under JNDI URL:

I do not think the connection profile method supports jndi.  Finally another option would be to have the data source in a rptlibrary and change it per install.  Not ideal but still just an xml change.
Comment 21 Ramses Gomez CLA 2012-02-24 14:42:50 EST
Hi Jason

Is there any update from the development team?

Thanks
Comment 22 Ramses Gomez CLA 2012-02-28 15:00:14 EST
hi Jason,

I got this update from RedHat it will probably give you an idea:

We were able to find a more definitive reason as to why the datasource lookup is failing. Access to java:comp/env (ENC) is based on what the thread's context class loader (TCCL) is set to at that given point. With JBoss, org.jboss.web.tomcat.service.WebCtxLoader$ENCLoader is what the TCCL should be set to when the war runs in order to look up "java:comp/env/john/doe". Testing birt, we saw that the TCCL was set to the birt.war instead of org.jboss.web.tomcat.service.WebCtxLoader$ENCLoader, thus causing the lookup to fail. For some reason, Birt is changing the TCCL. We have attached a WAR (enc-example.zip), which is setup like that of the birt.war. It also does a lookup of datasource using resource references. Instructions on setup/deployment can be found in the README provided.

I will be attaching the sample they provided.
Comment 23 Ramses Gomez CLA 2012-02-28 15:01:14 EST
Created attachment 211758 [details]
sample provided by RedHat