Tyler Muth’s Blog

Technology with a focus on Oracle, Application Express and Linux

Call BI Publisher Web Services from APEX

Posted by Tyler Muth on March 31, 2008

Integration between Application Express and BI Publisher is primarily focused on delivering high fidelity reports to the browser, such as clicking a “Print” link on an APEX report and getting back a PDF version of that report in your browser. The configuration and architecture of this integration is documented here. However, there have been a number of questions on the APEX forum and from customers I’ve presented to that are not answered by this solution. So, with the knowledge that BI Publisher 10.1.3.3.2 introduced Web Service APIs to run reports (documented here), and Application Express 3.0 introduced the ability to call Web Services, I thought there might be another integration point between these two products.

This technique is completely different from the traditional integration, since the database where the report resides can be completely different from the database where APEX is installed. We’re going to configure a database connection in BI Publisher then build a report using that connection. APEX is essentially going to pass some parameters to that report and doesn’t need access to the data at all. Since we’re defining the data source in BI Publisher, the report data can actually come from any JDBC compliant database (Oracle, SQL Server, MySQL, etc), a Web Service, or even File data sources.

In summary:

  • Select zero or more parameters on an APEX Page
  • Press Submit
  • This calls an APEX Process of type “Web Service Reference”
  • The Web Service Call instructs BI Publisher to run a report with the given parameters
  • Then deliver it to one or more email address and an FTP server (could also be WebDav, Fax, or a Network Printer)

Software used in the post:

Please make sure all of the following software is installed and configured before starting. You can obviously omit either the Email server or the FTP server if you only care about 1 delivery end point. Make sure you test the Email and / or FTP servers with their respective clients before you try delivering reports to them with BI Publisher.

Create a Report in BI Publisher

If you are not familiar with BI Publisher, please take the time to go through this Oracle By Example (OBE). The OBE will walk you through all of the steps necessary to build the report in BI Publisher. Once you are familiar with BIP:

  1. Create a report based on HR.DEPARTMENTS and HR.EMPLOYEES. This report has a parameter that allows you to select which department you want to view and uses an RTF template to format the output.
  2. Configure your SMTP and FTP servers in the Admin interface
  3. Click on the “Schedule” link for the report and test FTP delivery first as its less prone to errors. Then test email delivery. Make sure these work from the schedule interface before proceeding. If they don’t work here, there’s no chance they’ll work when called from a Web Service API.
  4. Make note of the URL of your report as you’ll use this later in the Web Service API.

Here are 2 screen-shots of my report:

report edit

report view

Test The Web Service Call in soapUI

Now that we know we can schedule a report to be delivered via FTP and Email, lets test the BI Publisher Web Service Call to this report. Start by creating a new WSDL Project in soapUI. From the BI Publisher Web Service API Documentation, use the following URL for the WSDL:

http://<host>:<port>/xmlpserver/services/PublicReportService?wsdl

Create a New Request under PublicReportService > scheduleReport. Lets start with a simple request to deliver our report to FTP with no parameters:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <pub:scheduleReport xmlns:pub="http://xmlns.oracle.com/oxp/service/PublicReportService">
         <scheduleRequest>
            <deliveryRequest>
               <ftpOption>
                  <ftpServerName>tmuth-ftp</ftpServerName>
                  <ftpUserName>tyler</ftpUserName>
                  <ftpUserPassword>oracle1</ftpUserPassword>
                  <remoteFile>/employees.pdf</remoteFile>
               </ftpOption>
            </deliveryRequest>
            <notificationTo>tyler@tmuth-lap</notificationTo>
            <notifyWhenFailed>true</notifyWhenFailed>
            <reportRequest>
               <attributeFormat>pdf</attributeFormat>
               <reportAbsolutePath>/~tmuth/employees/employees.xdo</reportAbsolutePath>
            </reportRequest>
            <userJobName>employees</userJobName>
         </scheduleRequest>
         <userID>tmuth</userID>
         <password>oracle1</password>
      </pub:scheduleReport>
   </soapenv:Body>
</soapenv:Envelope>

Some things to note about the code above:

  • Line 7: “tmuth-ftp” isn’t the actual server name, it’s the name I gave it in the BIP Admin interface when I added the FTP server.
  • Line 10: Don’t forget the leading slash
  • Line 17: This is the URL I noted when I ran my report. The BIP interface will often escape the tilde with a percent seven E, but you can just use the tilde here.
  • Lines 21 and 22: This is the username and password I used to login to the BIP Web Interface.

Once that is working, you can try adding a parameter to narrow it to just the sales department. Add the following code at the end of the “reportRequest” section between lines 17 and 18:

<parameterNameValues>
  <item>
     <name>DEPARTMENT</name>
     <multiValuesAllowed>false</multiValuesAllowed>
     <values>
        <!--  80 = SALES, -1 = All -->
        <item>80</item>
     </values>
  </item>
</parameterNameValues>

Now, lets add email as a second delivery end-point. Add the following code to the “deliveryRequest” section between lines 11 and 12:

<emailOption>
  <emailBody>webservice test</emailBody>
  <emailFrom>bip@localhost</emailFrom>
  <emailSubject>test</emailSubject>
  <emailTo>tyler@tmuth-lap</emailTo>
</emailOption>

Create an APEX Application to Call The Report

  1. Create a new APEX application with one blank page (Page 1).
  2. Create a new “Web Service Reference” (Application > Shared Components > Logic)
    1. Do not search a UDDI repository.
    2. Create the reference manually (link on the right side of the page).
    3. Enter the WSDL you used for soapUI
    4. Enter the SOAP envelope at the bottom of this section (make sure you change the values to match your configuration).
  3. Create an Item on Page 1 of type “Select List”. The LOV should be a query of department_name,department_id from hr.departments. The NULL value is -1.
  4. Create a Button labeled “Deliver Report”. Also have the page branch to itself.
  5. Create a Process (on-submit):
    1. Type: Web Service
    2. Select the Web Service Reference you created earlier.
    3. Only fire this process when you press the Deliver Report button.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <pub:scheduleReport xmlns:pub="http://xmlns.oracle.com/oxp/service/PublicReportService">
         <scheduleRequest>
            <deliveryRequest>
               <ftpOption>
                  <ftpServerName>tmuth-ftp</ftpServerName>
                  <ftpUserName>tyler</ftpUserName>
                  <ftpUserPassword>oracle1</ftpUserPassword>
                  <remoteFile>/employees.pdf</remoteFile>
               </ftpOption>
               <emailOption>
                  <emailBody>webservice test</emailBody>
                  <emailFrom>bip@localhost</emailFrom>
                  <emailSubject>test</emailSubject>
                  <emailTo>tyler@tmuth-lap</emailTo>
               </emailOption>
            </deliveryRequest>
            <notificationTo>tyler@tmuth-lap</notificationTo>
            <notifyWhenFailed>true</notifyWhenFailed>
            <reportRequest>
               <attributeFormat>pdf</attributeFormat>
               <reportAbsolutePath>/~tmuth/employees/employees.xdo</reportAbsolutePath>
               <parameterNameValues>
                  <item>
                     <name>DEPARTMENT</name>
                     <multiValuesAllowed>false</multiValuesAllowed>
                     <values>
                        <item>#P1_DEPARTMENT#</item>
                     </values>
                  </item>
               </parameterNameValues>
            </reportRequest>
            <userJobName>employees</userJobName>
         </scheduleRequest>
         <userID>tmuth</userID>
         <password>oracle1</password>
      </pub:scheduleReport>
   </soapenv:Body>
</soapenv:Envelope>

Notice that we reference APEX Items in Web Service Requests using #ITEM# notation.You can now test your application by selecting a department then submitting the page.apex_app.png

Use Cases

  • Long running reports, asynchronously delivered via email
  • Print bar codes via network attached printer
  • Publishing a report in HTML or PDF format to a web site via FTP

Downloads

Click here to download the APEX Application, BI Publisher Report, and PDF output of the BIP Report. Note that in the APEX application, the P1_DEPARTMENT item queries HR.DEPARTMENTS. employees.zip is the BIP Report which you simply want to upload to BI Publisher “as-is” without unzipping.

18 Responses to “Call BI Publisher Web Services from APEX”

  1. Very nice post Tyler! Well done.

    Dimitri

  2. [...] Check out Tyler’s post on using BIP web services to integrated BIP and Application Express: Call BI Publisher Web Services from APEX 3/31/08; 10:40:28 PM Comment [0] Mortgage Rate LiesTim Dexter Not so much a how to today – that [...]

  3. Really helpful, thank you for this great post Tyler.

  4. Jason said

    Tyler,

    Very nice, and a very lucid example of using the Manual Web references feature of Application Express (one of my favorites). One thing I would note is that in your instructions for creating the Manual Web reference, the URL under Service Description should be the address of the service, and not the URL of the WSDL itself. This address can be found by inspecting the WSDL and looking for /definitions/service/port/soap:address/@location.

    Regards,

    Jason

  5. Todd said

    Tyler,

    Thanks for taking the time to create this nice post. This logic will really benefit applications that need to submit reports to run in the background (long running reports…).

    Thank You!
    Todd

  6. Partha said

    Thanks for the nice article. There has been a lot of emphasis on BI Publisher and how it is a preferred solution for nice formatted reports for APEX, however, it is not mentioned whether BI Publisher standalone is an extra cost option or the licensing model. With the complexity of the licensing model of Oracle, it becomes difficult to judge this. Also, since APEX comes with the database, and because of the embedded gateway with 11g, there is no need for Oracle Application server, we would like to have options for no-more-license solution for the reports as well.

    Second comment is the username / password in most of the examples. Is this the only way to do it? where the usernames and passwords have to necessarily be hardcoded the way it is given in the example? The solution (integration) mentioned above is quite new for people who are not used to java or xml or webservices, so, they try to do copy / paste and customize for their requirements, but then, when it goes to production, the DBA has a say on the production passwords and corporate policy dictates that dba changes the passwords every month – this will lead to application dependancy; Hence if there are alternate ways to do this, kindly mention them in future articles or use them as default even if it means a level of complexity.

    Partha K

  7. Tyler Muth said

    Partha,

    BI Publisher requires a license, as do almost all other Oracle products. If Oracle only charged for the Database, the company would collapse and a lot of stock holders would not be happy. APEX is a bit of an anomaly in Oracle as its one of the few free products. As far as the embedded gateway, its nice for development, but I would never choose it for a production system over Oracle HTTP Sever based on Apache. Apache has a very long positive track-record, a lot of configuration options and modules, and a large number of people in the IT community who know it well.

    As far as the username / password issue, this is the only way I know of, but there might be another way. There is the concept of running a report as “guest” in BIP, but I don’t know if that’s an option in the web service APIs. I’ll see if one of the BI guys can chime-in. You might want to ask it on the BIP forum as well. I certainly see your point here.

  8. Tony Miller said

    Tyler,
    Awesome job on the article.. This will help with mey new job here in Houston. We have batch run reports that take a while right now IN Oracle Reports and driven by a forms based application. Trying to help move stuff to APEX and BI Publisher..

    Thanks !

    Tony Miller
    Webster, TX

  9. [...] on a bit of luck with the setting up of BI Publisher Web Service access for ApEx as I came across this excellent article by Tyler Muth that documents the whole process. In the article, Tyler uses a tool called soapUI to [...]

  10. [...] If you had worked on APEX and BI Publisher integration (using Web Services) as documented here excellently by Tyler Muth you would have noticed that APEX can identify BI Publisher web services [...]

  11. Pooja said

    Hi Tyler,

    Am very much new to web services technology…. I need a help in using the web services for running the BI Publisher report through backend and its very urgent for me so as to deliver this to my client. We had followed the link mentioned above “BI Publisher Web Service API Documentation” for generating the required class files but we are running out with errors. Could you please share a sample working report with exact version of the jar files used and commands to be executed in sequence.

    Thanks for your help in advance…

    Pooja

  12. Tyler Muth said

    Pooja,

    Sorry, there are no jar files or Java involved whatsoever. Consider this example decaffeinated. Are you trying to call the BIP Web Services from Application Express?

  13. Pooja said

    Hi Tyler,

    Thanks for a quick reply.. basically my requirement is to call the bip webservice through a Java Program(which is inturn registered as an iBot in OBIEE Applications). Can you please suggest any way to call the BIP report in an iBot.

    Thank You

  14. Yesh Nandi said

    Tyler:

    Great article. Could you give an example of how the SOAP response would be collected back if I need to run the report in APEX itself (rather than your example of ftp and email.)

    I am a little confused about the SOAP response structure of a multi-page report (PDF or HTML ) …

    Thanks – Yesh

  15. Yesh Nandi said

    Hi Tyler:

    When I execute the “runreport” operation in SOAPUI, I get a SOAP response with

    JVBERi0xLjQNCjYgMCBvYmoNCjw8IC9MZW5ndGggMTg3NSAvRmlsdGVyIC9GbGF0ZURlY2>

    application/pdf

    How can I collect this information and display it in my APEX application ?

    Thanks – Yesh

  16. hari said

    helpful article,
    but how about throw BI Publiser sessionid to Apex?

  17. David said

    Just a question related to this. How do you deal with the situation in which reports security is an issue (ie. were not willing to publish our reports wide open to the public user)? Were running in an OID SSO environment so if the visitor went to the report directly their authentication would pass but how would you go about passing the authentication information where APEX is an SSO application and BIP is SSO enabled and the report is not publicly accessible.

  18. name said

    Hello!,

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>