Sunday Jan 19, 2014

Ten Minute Tutorial: XDS Logger Plugin for Determinations Server (JDeveloper)

Andrew Higginbottom | Policy Automation Technical Zealot

Welcome to another TMT. This time we will create a plugin for Oracle Determinations Server to log incoming SOAP requests in the Oracle Policy Automation XDS (eXplicit Data Set) format - not to be confused with XSD. You can take this and load it into the Oracle Policy Modeling debugger to track down issues with specific SOAP requests. DISCLAIMER: This might take you longer than 10 minutes, depending on how fast you can click and how fast your PC is!

Last time we used Eclipse but this time we will be using JDeveloper to build and test the plugin. Again there are some prerequisites:
  1. Oracle JDeveloper (I used 11.1.2.4.0)
  2. Oracle Policy Automation Runtime Components for Java (I used v10.4.4.21.0)
  3. SoapUI (I used 4.6.4)

Once downloaded, install JDeveloper, extract the OPA Runtime Components to a convenient location and install SoapUI.

Now we begin. Start JDeveloper and accept the "Studio Developer (All Features)" role.

Select Application > New... from the main menu to create a new application workspace.
Give the application a name "ODSXDSPlugin"

Accept the default Project1 and Finish.

Having set up the Application, we now import the Determinations Server WAR file. File > Import... from the main menu, then select > WAR File. Call the project "determinations server".

At the next step Browse... to the location where you extracted the OPA Runtime and select /determinations-server/determinations-server.war.

Right-click determinations-server project, New..., General > Java Class.
Enter Name "XDSLogger", Package "com.opablog.aeh".

Add the "OnBeforeThinkEventHandler" interface. This event is fired for every request, after the request has been parsed into the session but before the rules are executed.


This time I've provided the code to copy and paste in, replacing the entire contents of the new XDSLogger.java file:

package com.opablog.aeh;

import com.oracle.determinations.engine.SessionUtils;
import com.oracle.determinations.server.assess.extensions.AssessPlugin;
import com.oracle.determinations.server.assess.extensions.AssessPluginRegisterArgs;
import com.oracle.determinations.server.assess.extensions.events.OnBeforeThinkEvent;
import com.oracle.determinations.server.assess.extensions.events.OnBeforeThinkEventHandler;
import java.io.IOException;
import java.io.StringWriter;
import org.apache.log4j.Logger;

public class XDSLogger implements OnBeforeThinkEventHandler {
 
    private Logger log = Logger.getLogger(this.getClass());
 
    public XDSLogger() {
        super();
    }

    @Override
    public void handleEvent(Object object, OnBeforeThinkEvent onBeforeThinkEvent) {
        try {
            StringWriter w = new StringWriter();
            SessionUtils.exportSession(onBeforeThinkEvent.getSession(), w);
            log.debug(w.toString());
        } catch (IOException e) {
            log.error(e);
        }
    }

    @Override
    public AssessPlugin getInstance(AssessPluginRegisterArgs assessPluginRegisterArgs) {
        return this;
    }
}


Edit Application Sources/config/application.properties to configure ODS to load the plugin by updating the plugin.libraries parameter to "plugin.libraries=com.opablog.aeh.XDSLogger"

Edit Application Sources/log4j.xml to increase the logging level by setting <level value="DEBUG"/> under the <root> element. Don't do this in production!

Copy in the PocketMoneyComputation.zip rulebase from the \examples\rulebases\compiled folder in your expanded OPA runtime location. Use Windows Explorer to copy the file into your JDeveloper project. For me the destination folder is located at C:\JDeveloper\mywork\ODSXDSPlugin\determinations-server\src\rulebases.


Now we can deploy the plugin to our local server.
Select Run > Start Server Instance (IntegratedWebLogicServer) from the main menu and enter credentials of your choice to use for server setup.

Wait for domain to build and server to start up. Once completed you should see "IntegratedWebLogicServer started." in the Log window.

Now we can deploy our Determinations Server with XDS logger plugin.

Right-click the determinations-server project and Deploy > "determinations-server...". Select "Deploy to Application Server", click Next, then IntegratedWebLogicServer, then Finish. Ignore any warnings logged during startup - they are only there because we turned the logging up to DEBUG.
In the deployment tab you should see that deployment has finished and you are given the URL in the Deployment - Log window.


Finally we can test our plugin by sending a request using SoapUI.
Open the URL in your favourite browser and you will see the familiar page listing the OPA services available. Grab the full URL to the specific Assess service WSDL.

Start SoapUI and select File > New SOAP Project from the main menu. Give the project a name and paste the WSDL URL for Initial WSDL. Make sure Create Requests is checked.

Open Request1 under the Assess node and paste the following minimal SOAP message to replace the default content:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://oracle.com/determinations/server/10.4/PocketMoneyComputation/assess/types">
   <soapenv:Header/>
   <soapenv:Body>
      <typ:assess-request>

         <typ:global-instance>
            <!--You may enter the following 6 items in any order-->
            <!--Optional:-->
            <typ:base_rate>
               <typ:number-val>2.50</typ:number-val>
            </typ:base_rate>
            <typ:person_name>
               <!--You have a CHOICE of the next 3 items at this level-->
               <typ:text-val>Parent</typ:text-val>
            </typ:person_name>
 
            <typ:total_money outcome-style="decision-report"/>
 
            <typ:list-child>
               <typ:child id="1">
                  <typ:child_name>
                     <typ:text-val>Bobby</typ:text-val>
                  </typ:child_name>
                  <typ:child_age>
                     <typ:number-val>7</typ:number-val>
                  </typ:child_age>
                  <typ:child_money outcome-style="value-only"/>
               </typ:child>
               <typ:child id="2">
                  <typ:child_name>
                     <typ:text-val>Betty</typ:text-val>
                  </typ:child_name>
                  <typ:child_age>
                     <typ:number-val>9</typ:number-val>
                  </typ:child_age>
                  <typ:child_money outcome-style="value-only"/>
               </typ:child>
 
            </typ:list-child>
         </typ:global-instance>
      </typ:assess-request>
   </soapenv:Body>
</soapenv:Envelope>

Press "play" (the green arrow pointing to the right) to submit Request1. You should see a response that looks similar to the request, but with calculated values returned along with the inputs used.

In addition to processing the Assess request as normal, our new Determinations Server plugin has logged the inputs to the application log in the OPA XDS format.

You can now copy this XML into a text file and load it up in OPM to debug!

There are obvious improvements that could be made to this, such as logging each request to its own file, but I will leave those as an exercise for the reader. This is supposed to be a TMT after all!



About

Welcome to the OPA blog where Oracle's Policy Automation experts share their views on everything OPA.

Search

Archives
« July 2014
SunMonTueWedThuFriSat
  
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today