Friday, 31 January 2014

Consuming OBIEE 11g Web Services using Java

We will talk about consuming OBIEE 11g webservices using Java in this article. My previous articles have been about consuming webservices using JavaScript and consuming webservices using PL/SQL. This is my first on consuming webservices using Java. 
My book also has a number of recipes about consuming and creating web services. Check out a brief description of the book and the table of contents. You may also check out the online application build on top of the discussions in the sample chapter of my book.

The prerequisite for this article is Oracle JDeveloper Studio Edition Version Download it from

We will learn to create iBots (Agents) using webservices in this article. Let us see the process.

1. Open JDeveloper and hit the Create button to create a Generic Application as shown below.
2. I call it OBIEEiBotApp.
3. Create a Project in this Application, as shown below. Do not select anything in the shuttle.
4. Right click on the newly created project and select Web Service Proxy.
5. Select JAX-RPC Web Logic Style radio button in Step 2 of Create Web Service Proxy wizard. Enter your webservice WSDL url in step 3 of this wizard. The URL has the following format
6. Select SAWSessionService in step 4 of the wizard and click the Finish button. This service will help us to create an OBIEE session which can then be used with any operation using Webservice.
7. Repeat steps 4 to 6 but select IBotService in step 6 instead of SAWSessionService. We are selecting the IBotService because we plan to create iBots using Webservices in this article.
Your application will now look like the following
8. Right click on and click the New... button. Create a new Java Class as shown below.
9. Give a name to your class, make the selections as shown in the screenshot below and click OK.
10. Your class will look like the following. You may remove the statement that creates an iBotClass object as we don't really need this. You won't get an error even if this statement isn't removed.
11. Now, we need a few classes for our code so we are going to import them. Put the following import statements right after the package statement.


12. We now have to create a OBIEE session so we create a Logon object and pass it to a SAWSessionServiceSoapPortClient object. The following code does this for us. Put this code in the main method of your class. Code from this point on will go in the main method only.

Dont forget to put replace your username, password, webserver ip and port in the following code.

    Logon my_logon = new Logon();
    LogonResult logResult = new LogonResult();
    String log_sessid = "";
    try {
      SAWSessionServiceSoapPortClient new_soap_port_client =
        new SAWSessionServiceSoapPortClient();
      logResult = new_soap_port_client.logon(my_logon);
      log_sessid = logResult.getSessionID();
    } catch (java.lang.Exception e) {

13. We now have to create our iBot. To achieve this, we first have to create an object of IBotServiceSoapPortClient class and then call the necessary functions to define the various properties of our iBot. We will need the following classes for this operation.

                a. WriteIBot class :- To set the session id, catalogobject and other such properties.
                b. CatalogObject class :- To define the characteristics of the iBot
                c. ItemInfo class :- To set the caption, creator, last modifier etc.
                d. ItemInfoType class :- Required as an arguement to ItemInfo.setType method.
                e. NameValuePair class :- To set the properties such as the Author
                f. Account class :- Object of this class defines a OBIEE account that does the necessary operation.

Let us now look at the code. The entire code will follow the code written in step 12 above.

    try {

      //****************************Object creations************************************

      boolean resolveLinksFlag = false;
      boolean allowOverwriteFlag = false;
      IBotServiceSoapPortClient ibotClient = new IBotServiceSoapPortClient();
      WriteIBotResult ibotResult = new WriteIBotResult();
      WriteIBot ibotObj = new WriteIBot();
      CatalogObject catObj = new CatalogObject();
      ItemInfo itemInfObj = new ItemInfo();
      ItemInfoType itemInfTypObj = ItemInfoType.object;
      NameValuePair[] itemProperties = new NameValuePair[1];
      itemProperties[0] = new NameValuePair();

//********************Will use this for Item Object**************************************

//********************Used to set the account that creates the iBot*************************

      Account accObj = new Account();

//*Setting of the properties of the iBot. Decides the values for each of the iBot tabs in OBIEE portal*
      catObj.setCatalogObject("<?xml version=\"1.0\"?><saw:ibot xmlns:saw=\"\" version=\"1\" priority=\"normal\" xmlns:cond=\"\" xmlns:sawx=\"\" xmlns:xsi=\"\" jobID=\"9\"><saw:schedule><saw:start startImmediately=\"false\" date=\"2013-12-10\" time=\"04:15:00\"/><saw:recurrence runOnce=\"true\"/></saw:schedule><saw:dataVisibility type=\"runAsUser\" runAs=\"weblogic\" runAsGuid=\"256A12F0A11511E28F457FA5CCEDA162\"/><cond:condition/><saw:choose><saw:when condition=\"true\"><saw:deliveryContent disposition=\"deviceDefault\"><saw:headline><saw:caption><saw:text>Test7</saw:text></saw:caption></saw:headline><saw:reportRef path=\"/shared/2. Functional Examples/Examples/Indexing/Indexing\"/></saw:deliveryContent><saw:postActions/></saw:when><saw:otherwise><saw:postActions/></saw:otherwise></saw:choose><saw:deliveryDestinations><saw:destination category=\"dashboard\"/><saw:destination category=\"activeDeliveryProfile\"/></saw:deliveryDestinations><saw:recipients specificRecipients=\"true\" subscribers=\"false\" customize=\"false\"><saw:specificRecipients><saw:user name=\"weblogic\" guid=\"256A12F0A11511E28F457FA5CCEDA162\"/></saw:specificRecipients><saw:subscribers/></saw:recipients><saw:emailRecipients><saw:emailRecipient address=\"\" type=\"HTML\"/></saw:emailRecipients></saw:ibot>");

//***************************Setting of iBot properties*********************************





//************************ACL related code******************************************

      ACL aclObj = new ACL();
      AccessControlToken[] acTokenObj = new AccessControlToken[1];
      acTokenObj[0] = new AccessControlToken();
      Account accObjForToken = new Account();






//*********************Setting of a few more iBot properties******************************







      ibotResult = ibotClient.writeIBot(ibotObj);

    } catch (java.lang.Exception e) {

While the rest of the code is intuitive, I wish to talk about the argument of catObj.setCatalogObject method. This argument is more or less the definition of our iBot object. Have a look at the screenshot below.
Let me also share a screenshot of the typical ibot to draw a comparison between the XML and the iBot feature on the OBIEE portal.
The XML arguement starts with declaring some namespaces. This is followed by the <saw:ibot> tag at the top. It is important to note that the tags in the XML closely correlate the tabs in the screenshot of a typical iBot.
For example, <saw:ibot> tag is followed by <saw:schedule> tag to set the schedule of the iBot. The screenshot shows a Schedule tab as well. This Schedule tab is used for scheduling the iBot through the OBIEE portal.
Similarly, we also have <cond:condition>, <saw:deliveryDestinations>, <saw:recipients>. These perform similar functions as their corresponding tabs.

We can now right click on the class we just created and then select the Run button.
You will get the following result. Check the highlighted part of the bottom of the screenshot below. It shows the OBIEE session id which was used to create the ibot and the result stored in ibotResult object.
You can now login to the screen and find your iBot.

Till next time :-)

No comments: