Friday, February 12, 2010

How to integrate JasperServer and Oracle E-Business Suite

Suppose you want to use JasperServer (3.7) to generate reports containing data from the E-Business Suite. (In case you wonder, JasperServer is an open-source product that can be used to host JasperReports reports).
In many cases you will just write a (huge) select statement that extracts the data. However, sometimes the data will have to come from an Oracle API, and in that case we can do something like

select some_oracle_function(x) from dual;

However, many of Oracle's APIs require some initialization first, which is done with the familiar function fnd_global.apps_initialize.
While it is still possible to include the call to fnd_global.apps_initialize in some function that you later 'select from dual' from, there is a caveat: You are likely to run into the error

ORA-14552: cannot perform a DDL, commit or rollback inside a query or DML

This is should not be surprising, there is nothing to stop Oracle from doing commits and the like in fnd_global.apps_initialize. They might write audit-logs, or it might be something completely different. We do not know.

So we need to be able to issue a PL/SQL Statement before the select in JasperServer.

Luckily this is possible by using the language 'plsql' in queryString:

<querystring language="plsql">...

in the jrxml file.

This enables us to write stored procedures that can do all kinds of fancy PL/SQL-Stuff and then return a cursor with the desired query results.

In order to be able to do this, some extra configuration is needed.
First, you need to add the line

net.sf.jasperreports.query.executer.factory.plsql=com.jaspersoft.jrx.query.PlSqlQueryExecuterFactory


to the file
(war-file-for-jasperserver)/WEB-INF/classes/jasperreports.properties

You also have to add the string 'plsql' below 'sql' in the files (war-file-for-jasperserver)/WEB-INF/flows/queryBeans.xml
and (war-file-for-jasperserver)/WEB-INF/applicationContext.xml

Now you can write a PL/SQL-Procedure like the following:

procedure get_data_from_ebs(p_cursor out ref_cur, p_some_parameter in number) is
begin
fnd_global.apps_initialize(-1,-1,-1);
open p_cursor for
select * from some_table where p_some_parameter=xyz;
end;

You have to define 'type ref_cur is ref cursor;' in your package spec.

Now you can use this procedure in the jrxml like so:

<querystring language="plsql">
<![CDATA[{call get_data_from_ebs($P{cursor}, $P{some_parameter})}]]>
</querystring>

I also had to add

<parameter name="DATABASE_TIMEZONE" class="java.lang.String" isforprompting="false">
<defaultvalueexpression><![CDATA["Europe/Berlin"]]></defaultvalueexpression>
</parameter>

in that file.

A nice side-effect is that the messy SQL is kept out of the jrxml.

6 comments:

  1. Nice article. Have you already posted a link to it from the JasperServer forums on JasperForge.org? It would be well received there.

    ReplyDelete
  2. Good afternoon,

    Thanks a lot for sharing your findings. I followed everything in your blog about the additional configuration steps.

    I made the following changes:

    1 ) C:\Program Files\jasperserver-ce-3.7.0\apace-tomcat\webapps\jasperserver\WEB-INF\classes\jasperreports.properties:

    Added the line:

    net.sf.jasperreports.query.executer.factory.plsql=com.jaspersoft.jrx.query.PlSqlQueryExecuterFactory


    2) C:\Program Files\jasperserver-ce-3.7.0\apace-tomcat\webapps\jasperserver\WEB-INF\flows\queryBeans.xml

    Added plsql

    ---







    sql
    plsql
    hql







    3) C:\Program Files\jasperserver-ce-3.7.0\apace-tomcat\webapps\jasperserver\WEB-INF\applicationContext.xml

    Added plsql and PLSQL after every instance of sql

    ---






    sql
    plsql
    SQL
    PLSQL









    sql
    plsql
    SQL
    PLSQL






    WIth these changes, my report runs perfect in IReport however it gives me an error when I try to run the report on JasperServer 3.7.0 Community Edition.

    I have a cursor in IReport that works fine but I'm not sure how to declare/create that cursor (is it a local control?) on JasperServer.


    Anyway, the actualy error is in the code section below. "PlSqlQueryExecuterFactory not found."

    Do you have an idea on what else I may be missing ? The report runs on IReport 3.7.1 but fails to run on JasperServer.


    Thanks for any help regarding this,

    Gervin Lapira

    ReplyDelete
  3. I have the exact same problem, have tried the same fixes. Still no progress.

    Has anybody figured this out?

    Todd

    ReplyDelete
  4. As soon as I asked, I figured it out.

    I got it working by copying the following file from within the iReports installation directory:
    ...\ireport\modules\ext\jasperreports-extensions-3.5.3.jar

    into the .../jasperserver/WEB-INF/lib folder and restarting the server.

    Good luck.

    Todd

    ReplyDelete
  5. I've done all of these things, including todd's suggestion, and I still get the error: The selected JRXML could not be parsed. You might have selected the wrong file.

    ReplyDelete