Normally, after a report has been created, it is fixed to a specific catalog connection. With the J2EE data source support feature, you can change to another runtime JDBC or JNDI data source to run reports.
This allows you to control the catalog data source connections on JReport Enterprise Server to connect dynamically to your production data sources.
In order to enable you to conveniently set different connections in JReport Server, a configuration file, datasource.xml, is provided with which you can define the connection to use at run-time by setting up connection mapping information such as the JDBC driver, URL, or JNDI data source name, user and password, depending on the data source your application uses.
The datasource.xml file is located in the
<install_root>\bindirectory. Change this file according to the data source you want to use. Two types of connections are supported by JReport Server, they are JNDI data source connection and JDBC connection.The content of the datasource.xml file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<datasource-mapping>
<datasource>
<catalog-connection-name>Connection1</catalog-connection-name>
<connection-type>JNDI</connection-type>
<jndi-datasource>Sample</jndi-datasource>
</datasource>
<datasource>
<catalog-connection-name>Connection2</catalog-connection-name>
<connection-type>JDBC</connection-type>
<driver>sun.jdbc.odbc.JdbcOdbcDriver</driver>
<url>jdbc:odbc:jinfonet</url>
<user>Username</user>
<password>Password</password>
</datasource>
</datasource-mapping>Element Descriptions:
- catalog-connection-name: Specifies the name of the catalog connection that you you want to substitute. Note that this is the connection name that you can see in JReport Catalog Browser.
- connection-type: Specifies the connection type, which can be either JNDI or JDBC.
- jndi-datasource: If you are using a JNDI data source, specify the JNDI data source name you defined in your Java application server which you want to use as the substitute connection.
- driver & url: If you are using a JDBC data source, specify the JDBC Driver and URL in these two attributes.
Notes:
- There can be multiple<datasource></datasource> tags. Each pair will map one of the connections in your catalog. You can define mapping connections for multiple connections for more than one catalog. The catalog connection name should be unique in the datasource.xml file, otherwise the latter <datasource> information will overwrite the previous ones.
- You can choose whether to provide database user and password information for the JNDI connection, using the
userandpasswordattributes. If the user and password information is provided in this file, it will be used to set up the connection regardless of the settings defined in your application server. Otherwise, the settings defined in your application server will be used. Specially, for WebLogic users, you should provide user name and password for WebLogic console instead of database.
Once the user and password are provided in the datasource.xml file, they will be encrypted into one line, which will be like the following:
<encrypt-sign>enDkq7srM9cHhoUwzYXJ3NvcDIYk</encrypt-sign>
If you want to change the user name and password information, just remove this line and type the new information again.After this, you can integrate JReport Server with your application server.
If you are using a self-contained war file, make sure the datasource.xml file is included in the war file, before making the self-contained war file, please modify %InstallRoot%/bin/makewar.xml, and add <include name="datasource.xml" /> into <zipfileset dir="${installroot}/bin" prefix="workspace/bin"> section. Before you deploy it to web server, make sure the datasource.xml is included in the "jreport.war/WEB-INF/lib/jrenv.jar/workspace/bin/datasource.xml".
Reference Note: For more detailed instructions on making self-contained war files, see Deploying JReport Enterprise Server as a Self-Contained WAR/EAR.
If you are integrating JReport server to an application using a normal war file, usually you need to specify -Dreporthome parameter in the application server so that the application server can locate and load the resources it needs. Since the datasource.xml is already in the bin directory, you don't need to do anything special for this file.
If you are using a catalog connection, datasource.xml, and at the same time, you have set new connection information via the server API/URL ((jrs.jdbc_driver, jrs.jdbc_url, jrs.db_user, jrs.db_pswd), the priority of these three are to like this:
Server API > datasource.xml > catalog connection
This means that if the approach with higher priority fails to get the connection, the one with lower priority will be used.
After you have made changes to the datasource.xml file, you need to reload it in JReport Server. This file can be reloaded in the following ways:
- Restart JReport Enterprise Server
- Call jet.server.api.admin.ConnectionInfoProviderService.reloadFile()
Taking WebLogic as an example, use the following steps:
- Start WebLogic server, navigate to <YourProjectName> | Services | JDBC | Connection Pools. On the configuration tab, make sure the connection you are going to use is there and correctly set up.
- Browse to <YourProjectName> | Services | JDBC | Data Sources. On the Configuration tab, create a data source using the JNDI name MyJNDISample. Select the correct connection from the Pool Name drop-down list.
- Open <install_root>\bin\datasource.xml and add:
<datasource-mapping>
<datasource>
<catalog-connection-name>default</catalog-connection-name>
<connection-type>JNDI</connection-type>
<jndi-datasource>MyJNDISample</jndi-datasource>
<user>youruserid</user>
<password>yourpassword</password>
</datasource>
</datasource-mapping>- Integrate JReport Server to WebLogic.
- Run the report that is using this connection.
Taking JBoss as an example, in this case, DB2 is used, and suppose JBoss is installed under D:\jboss-4.0.1, use the following steps:
- Copy the DB2 driver to D:\jboss-4.0.1\server\default\lib.
- Create the file db2-ds.xml in D:\jboss-4.0.1\server\default\deploy and add the following content:
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>DB2DataSource</jndi-name>
<connection-url>jdbc:db2://dbs-b/sample</connection-url>
<driver-class>COM.ibm.db2.jdbc.net.DB2Driver</driver-class>
<user-name>db2admin</user-name>
<password>db2admin</password>
<min-pool-size>0</min-pool-size>
<metadata>
<type-mapping>DB2</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>- Modify datasource.xml (
<install_root>\bin), make sure the followings are included:
<datasource-mapping>
<datasource>
<catalog-connection-name>default</catalog-connection-name>
<connection-type>JNDI</connection-type>
<jndi-datasource>java:/DB2DataSource</jndi-datasource>
</datasource>
</datasource-mapping>- Build the self-contained war file using makewar.bat (
<install_root>\bin).- Integrate JReport server to JBoss.
- Run the report that is using this connection.