Implementing a custom query executor / custom data source in Jasper server

This is small article on how to implement a custom datasource or a custom query executor in Jasper Reports Server, focused on the missing information in other tutorials/documentation available on web.  Before we start lets be clear on some of the related facts –

  1. Implementing a custom datasource in Jasper reports server is DIFFERENT from  implementing a datasource to work with iReports, in both concept and method used.
  2. A custom datasource is a datastructure that holds the information to be presented and is NOT a query executor (Meaning its not a datasource in “JDBC” or iReport sense).
  3. A query executor may create and return a custom datasource OR an instance of one of the predefined datasources.  For most of the cases, using one of the predefined datasources with a custom query executor are good enough and need to create a cutom datasource seldom arises. (please refer JasperServer documentation for information on predefined datasources).

Please refer the attached sample application  (from jasper server source) to understand how custom data source and query executors are created.

Please note these with regard to the sample application –

  1. In addition to the xml configurations in the given sample, the new query language “webscraper” has to be added in the file WEB-INF/flows/queryBeans.xml
  2. Once this is done, if the language specified in the queryString node of a JRXML is webscraper, WebScraperQueryExecuterFactory (and then WebScraperQueryExecuter) will be invoked to execute that query. This is irrespective of the datasource you have set for that report.
  3. A custom datasource has real use only when it works with a custom query executor, or when it can be created and filled with required information without the need for a query (from the report XML).

Skip Authorization on MySQL DB

To skip authorizations and login without password to MySql server,

  1. sudo vi /etc/mysql/my.cnf
  2. Add the line skip-grant-tables after the linewhich reads skip-external-locking.
    1. Optionally comment the line bind-address = 127.0.0.1 if the db has to be accessed from external devices via TCP.
  3. Save and quit vim.
  4. restart mysql server ( sudo /etc/init.d/mysql restart in ubuntu)

Activate password authentication on Ubuntu VMs on Amazon EC2

The VM should now be ready for password based ssh authentication.

Temporarily enable SSH password authentication on RHEL/Centos VMs.

To enable password based authentication on RHEL/Centos machines, login as root to the target host. ( sudo the commands below if you are not logging in as root)

1. Create the password authenticated user if not already created –

  • On console run : adduser [username]
  • Set a password for the new user: passwd [username]

2. Add the user to sudoers and enable remote login –

  • On console run: visudo
  • In the file opened for editing, comment out the line – “Defaults    requiretty
  • Add the line “[username] ALL=(ALL)       ALL”  below the line “root ALL=(ALL)       ALL

3. Enable password authentication for SSH.

  • vi /etc/ssh/sshd_config
  • Replace the line “PasswordAuthentication no” with “PasswordAuthentication yes“. (Uncomment this line if commented.) Save and close this file.
  • /etc/init.d/sshd reload

4. To disable password authentication after use, in the above file replace “PasswordAuthentication yes” with “PasswordAuthentication no“; reload sshd as before.