How can I call BI Publisher Web Service from my Java application with JDeveloper?
BI Publisher provides a set of Web Service APIs, with which you can do pretty much everything you can do from the UI such as running reports, scheduling reports, creating/editing/deleting reports, etc. With JDeveloper you can easily integrate the BI Publisher Web Service with your Java application and start developing your code.
I wrote a ‘BI Publisher Web Service development guide for Java developers with JDeveloper’ paper quite a while ago, but never talked about this topic on this blog. And there have been some changes since then. Now JDeveloper is 11G and BI Publisher has added more APIs and fixed some issues we had before.
So I’ll spend the next couple of posts talking about this topic, hope it will be useful for Java Developers out there who want to integrate with BI Publisher to run and manage BI Publisher reports within your application.
Environment
Here is my environment information:
- BI Publisher 10.1.3.4.1 with March Patch Set (9546699)
- JDeveloper 11.1.1.2
- WebLogic Server 11G (10.3.2)
Get BI Publisher WSDL File
First, you need to get a WSDL file first before start anything. You can obtain your BI Publisher Server’s WSDL file by submitting the following URL from your browser.
| http://hostname:port/xmlpserver/services/PublicReportService?WSDL |
Note: Somehow I couldn’t get this with my BI Publisher running on a OC4J. I don’t know why but keep getting an error message. Looks many people are just fine or it worked fine after upgraded or something. Since I didn’t have enough time to keep debugging I’ve just simply moved to my another BI Publisher Server running on WebLogic 11g Server, which is working perfect, thanks god!
Once you get the WSDL file then save it to your local system.
Create a Web Service Proxy
Now, in order to integrate with Web Service within Java application you need to create a Web Service Proxy. There is a UI wizard to generate this with JDeveloper. In the New Gallery (right click on Project and ‘New’), select Web Server Proxy under Business Tier/Web Services and follow the steps with the default options until finish. When you are asked to provide a WSDL then use the WSDL you just saved at above.
In my example I have chosen ‘JAX-WS Style’ as Client Style.
Once you click the ‘Finish’ button it automatically generates all the required Java classes to provide you a set of Java APIs each of which corresponds with each Web Service API. Also it generates the Proxy class called ‘PublicReportServiceService’ like the below.
| public class PublicReportServiceClient { @WebServiceRef private static PublicReportServiceService publicReportServiceService; public static void main(String [] args) { publicReportServiceService = new PublicReportServiceService(); PublicReportService publicReportService = publicReportServiceService.getPublicReportService(); // Add your code to call the desired methods. } } |
Now you can start writing your own code with the BI Publisher Web Service corresponding Java methods after the ‘Add your code to call….’ line.
Call BI Publisher Web Service
First, I’m going to use a simple API called ‘login(String username, String password)’ to test if the web service integration works. This API accepts two parameters, one is username and another is password. It passes those two values to the BI Publisher Server and returns a session token if the combination of the username and password is valid. You can use this session token later for any following actions such as running a report, scheduling a report, etc, without needing to be authenticated at every communication with the Server.
Anyway, so this ‘login()’ API is one of the BI Publisher Web Service APIs and I can call it through the Web Server Proxy. In the example below ‘publicReportService’ is the proxy, once this is instantiated then I can call it through the proxy ‘publicReportService’.
With the below example, I’m setting ‘Administrator’ for the username and ‘Administrator’ for the password, and trying to print the returned session token in the standard out.
| public class PublicReportServiceClient { @WebServiceRef private static PublicReportServiceService publicReportServiceService; public static void main(String [] args) throws AccessDeniedException_Exception, MalformedURLException { publicReportServiceService = new PublicReportServiceService(); PublicReportService publicReportService = publicReportServiceService.getPublicReportService(); String sessionid = publicReportService.login("Administrator", "Administrator"); System.out.println(sessionid); } } |
When I run this program I get a session token like ‘6691223D7D070473ABA31D91AAB89’, which means the login was successful and I can use this token later when I call other BI Publisher Web Service APIs.
How to Change Endpoint?
Now, as long as I’m developing and testing in this instance I would be fine. But what if I need to migrate my code to a QA or Production and I need to run the BI Publisher calls against a different BI Publisher Server?
When you create the Web Server Proxy with JDeveloper it generates it with a default endpoint URL setting, which is retrieved from the WSDL file. That means, every time I run the BI Publisher Web Service it goes against a BI Publisher server with the endpoint URL. So I want to dynamically change the endpoint URL address instead of hard-coding it somewhere.
With 10G JDeveloper it generated an API that I can use to set the endpoint URL address. But with 11G JDeveloper I need to do that in a slight different way, which is to set that as part of the proxy construction. With my example, I can set that when I initiate ‘publicReportServiceService’. I need to provide a URL, which is the endpoint, and a QName, which consists of namespace and localname. My example, those are something like following.
- Endpoint URL: http://knishida-lap.us.oracle.com:7001/xmlpserver/services/PublicReportService
- Namespace: http://xmlns.oracle.com/oxp/service/PublicReportService
- Localname: PublicReportServiceService
You can find these information from your BI Publisher Server WSDL file, or you just need to change the hostname and port number of the example above. And you can set those values something like below.
Before:
| publicReportServiceService = new PublicReportServiceService(); |
After:
//publicReportServiceService = new PublicReportServiceService(); publicReportServiceService = new PublicReportServiceService(new URL("http://knishida-lap.us.oracle.com:7001/xmlpserver/services/PublicReportService"), new QName("http://xmlns.oracle.com/oxp/service/PublicReportService", "PublicReportServiceService")); |
Now you have a control of which BI Publisher Server instance you want to communicate with the Web Service calls. Great!
Test with Java Servlet
With the above example I was testing with a Java application. But for the next couple of posts I want to use a Java Servlet to demonstrate other APIs. In case you are not familiar with Java Servlet, don’t worry, you can create it with JDeveloper pretty easily. Just select ‘HTTP Servlet’ under ‘Web Tier/Servlet’ in the ‘New Gallery’ menu and follow the wizard steps.
Now I created a Java Servlet to test called ‘BipServletTest’ under the same project. I’m going to use this Servlet to go over the next couple of posts to introduce other BI Publisher Web Service APIs such as runReport, scheduleReport, etc, so stay tuned!