Context

In Mondrian 4 in Pentaho BA Server I explained how to create a datasource on top of Mondrian 4 Schema in the BA Server and later how to use it in Analyzer to create a basic report. The problem I could not overcome for a long time was how use a JNDI connection defined in tomcat inside a datasource definition. Luckily thanks to help given on Pentaho Forum I was finally able to solve the mystery.

This solution was tested with Pentaho BA Server 5.2.

Problem

To define a datasource that uses a JNDI connection we need to slightly modify olap4j.properties file located under ../pentaho/server/biserver-ee/pentaho-solutions/system. As opposed to the configuration from the previous article we do not provide connection details, but a name of JNDI connection defined in tomcat.

olap4j.properties file for JNDI connection customds.name=Mondrian 4 Test customds.className=org.pentaho.platform.plugin.services.connections.PentahoSystemDriver customds.connectString=jdbc:mondrian4:DataSource=JNDI_CONNECTION;Catalog=solution:/public/Mondrian4Schema.xml 1 2 3 4 5 customds . name = Mondrian 4 Test customds . className = org . pentaho . platform . plugin . services . connections . PentahoSystemDriver customds . connectString = jdbc : mondrian4 : DataSource = JNDI_CONNECTION ; Catalog = solution : / public / Mondrian4Schema . xml

As a result, we will get a mysterious error saying that class PentahoDataSourceResolver cannot be found – java.lang.ClassNotFoundException: org.pentaho.platform.web.servlet.PentahoDataSourceResolver.

Proglem using JNDI 2015-01-19 11:43:33,896 ERROR [org.pentaho.platform.plugin.services.connections.mondrian.MDXOlap4jConnection] MDXConnection.ERROR_0002 - Invalid connection properties: driver=org.pentaho.platform.plugin.services.connections.PentahoSystemDriver;url=jdbc:mondrian4:DataSource=JNDI_CONNECTION; Catalog=solution:/public/Mondrian4Schema.xml java.lang.RuntimeException: java.lang.ClassNotFoundException: org.pentaho.platform.web.servlet.PentahoDataSourceResolver not found by mondrian [33] 1 2 3 4 2015 - 01 - 19 11 : 43 : 33 , 896 ERROR [ org . pentaho . platform . plugin . services . connections . mondrian . MDXOlap4jConnection ] MDXConnection . ERROR_0002 - Invalid connection properties : driver = org . pentaho . platform . plugin . services . connections . PentahoSystemDriver ; url = jdbc : mondrian4 : DataSource = JNDI_CONNECTION ; Catalog = solution : / public / Mondrian4Schema . xml java . lang . RuntimeException : java . lang . ClassNotFoundException : org . pentaho . platform . web . servlet . PentahoDataSourceResolver not found by mondrian [ 33 ]

JNDI connection configuration

You might be wondering where to find the JNDI connections configuration file. It’s located under following location: ../pentaho/server/biserver-ee/tomcat/conf/Catalina/localhost/ pentaho.xml. Mine looks as follows:

JNDI connection configuration <Context path="/pentaho" docbase="webapps/pentaho/"> <Resource name="jdbc/JNDI_CONNECTION" auth="Container" type="javax.sql.DataSource" factory="org.apache.commons.dbcp.BasicDataSourceFactory" maxActive="20" maxIdle="5" maxWait="10000" username="user" password="password" driverClassName="oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@dbname" validationQuery="select 1 from dual"/> </Context> 1 2 3 4 5 6 7 8 9 < Context path = "/pentaho" docbase = "webapps/pentaho/" > < Resource name = "jdbc/JNDI_CONNECTION" auth = "Container" type = "javax.sql.DataSource" factory = "org.apache.commons.dbcp.BasicDataSourceFactory" maxActive = "20" maxIdle = "5" maxWait = "10000" username = "user" password = "password" driverClassName = "oracle.jdbc.OracleDriver" url = "jdbc:oracle:thin:@dbname" validationQuery = "select 1 from dual" / > < / Context >

Solution

The solution is extremely easy, we need to make sure that class PentahoDataSourceResolver is indeed visible when establishing the connection to the database. In order to do so we need to modify jar with mondrian implementation inside osgi bundles. In my case the file was named mondrian-4.1.0.0-209.jar and located under ../pentaho/server/biserver-ee/pentaho-solutions/system/osgi/bundles/.

We need to modify MANIFEST.MF file, particularly a line starting with Import-Package:, so that it look like this:

Proper MANIFEST.MF file Import-Package: org.pentaho.platform.web.servlet.messages.Messages;org.pentaho.platform.web.servlet.PentahoDataSourceResolver;org.olap4j.OlapConnection;org.olap4j.driver.xmla;resolution:=optional,org.olap4j.d 1 2 3 Import - Package : org . pentaho . platform . web . servlet . messages . Messages ; org . pentaho . platform . web . servlet . PentahoDataSourceResolver ; org . olap4j . OlapConnection ; org . olap4j . driver . xmla ; resolution : = optional , org . olap4j . d

I would recommend removing all directories under ../pentaho/server/biserver-ee/pentaho-solutions/system/osgi/cache to make sure that after we restart our server OSGI will use a mondrian jar with modified MANIFEST file.

Sources and links