Integrating SPSS predictive analytics into Business Intelligent applications, Part 2: Integrating the scoring service into an ILOG JRule

In Part 2 of this series, you'll learn how to use an SPSS predictive scoring service as an additional factor when quoting a premium for an insurance policy. In the scenario, predictive analytics are used to streamline the process of customer acquisition, by predicting the future risk behavior of a customer, thus leading to informed pricing decisions that mitigate future risk. Using the insurance quotation scenario from Part 1, you'll learn how to use an SPSS scoring service and WebSphere® ILOG® JRules, to create and deploy business rules that have a predictive dynamic factor. This content is part of the IBM Business Process Management Journal.

Share:

Andrew Flatt, Software Developer, IBM China

Andrew Flatt photoAndew Flatt works on an internal integration test project. The purpose of the project is to test that multi-product scenarios can be successfully deployed into a cross-platform environment that includes both distributed platforms (AIX, Linux and Windows) and z/OS. The project focuses on both cross-product and cross-platform integration and on consumability. Andrew aims to act as much as possible like a real customer to ensure that the testing we perform is relevant to real-world usage of the products being tested.



14 December 2011

Introduction

Business Intelligent rule systems are designed and updated to provide a view of the business at a point of time. Using analytics in conjunction with existing rule systems allows for adaptable and dynamic factors in the business to be used to make informed decisions. This article discusses the use of business analytics in Business Intelligent rules to provide a dynamic decision influenced by past performance and business analysis. You'll learn how predictive analytics can be used to provide a prediction that is adaptable and dynamic to current business information to enable informed decisions in real-time. We'll use the insurance quotation scenario introduced in Part 1.

After creation, rule-based classification systems become progressively out of touch with the current business. Using analytics in conjunction with existing rule systems allows for automatic adaptation to changing business conditions.

As an integration test team, we created the solution proposed in this series to introduce analytics into our home insurance solution environment. In Part 1, we used SPSS analytics to predict whether a customer is high risk by predicting whether the customer is likely to make a claim on their insurance policy. The sample insurance scenario uses a JRule to perform a real-time quotation on a policy. The integration of ILOG JRules and SPSS gives us a mathematical prediction of risk to combine with Business Intelligent rules to provide real-time quotes. In this article, we'll walk through this scenario to demonstrate how to use predictive analytics in conjunction with an ILOG JRule.

Prerequisites

If you completed Part 1, you already have the following software installed and configured:

  • IBM SPSS Modeler 14.1 with the Enterprise View plug-in
  • IBM SPSS Collaboration and Deployment Services 4.2 Server with correct version of the Modeler Adapter
  • IBM SPSS Collaboration and Deployment Services Deployment Manager 4.2
  • IBM DB2®.

For Part 2, you'll also need to install and configure:

  • IBM WebSphere ILOG JRules V7.1.1.1 or higher, including Rule Studio
  • IBM WebSphere Application Server V7.0.0.13 or higher

You need to deploy IBM ILOG Rule Execution Server to WebSphere Application Server.

You should be familiarize yourself with the basics of the products, using the tutorials provided in the help documentation. The ILOG JRules Quick Start tutorial is a good resource for learning how the ILOG BRMS products fit together.


The scenario and design

Our scenario is an insurance quotation system that uses rules to price a policy. We want to use analytics to help with the pricing of a policy by scoring customers as either high or low risk. Predictive analytics are used to streamline the process of customer acquisition by predicting the future risk behavior of a customer, leading to informed pricing decisions to mitigate future risk.

To accomplish this goal, we'll use profiling and segmentation to determine the historic behavior of a group. This will allow for the prediction of future behavior of a particular customer. The prediction can then be used as additional input to the pricing of policies. We'll achieve this by integrating predictive scoring within an ILOG JRule ruleset.

In this article, we'll use the LB02 SupportPac, which has the functionality to define business rules that reference predictive scores obtained at runtime by invoking the SPSS scoring service. This works by allowing you to connect to your SPSS Collaboration and Deployment Service server to retrieve a scoring configuration, which is used to automatically generate a Business Object Model (BOM). A BOM is a translation of the business terms used by the underlying Java™ or XML code. This allows rules to be defined that reference scores. When a rule application is executed, the scoring service call is made in real time to the scoring service. The scoring result can then be used in the execution to dynamically impact the final decision. Figure 1 shows the method of implementation required for this design.

Figure 1. Figure 1. SupportPac integration
SupportPac integration

The benefits of performing the integration using the SupportPac is:

  • Optimized for real-time calls by using a cache to store scoring calls.
  • Neat integration, which handles the dependencies and generates the scoring BOM and XOM.
  • No additional web applications need to be deployed.
  • The rule directly calls the scoring service. The scoring is called when it is needed and does not need to be a parameter to the rule application.
  • Quick creation of rules using scoring services.

There are currently some restrictions when using the SupportPac V2.

  • The scoring service location, scoring configuration ID, user name and password are stored in the eXecution Object Model (XOM) header. To change these variables, you need to regenerate the XOM and redeploy the rule application. The XOM contains the mapping from the BOM to the Java Objects or XML schemas.
  • The login and password are encrypted in the XOM header using an unchangeable key.

Deploy the existing scenario

First, we'll walk through deploying the original scenario, to which we'll later add predictive scoring. The existing scenario consists of two parts: the rule application and the web service application.

Deploy the RuleApp

The first step is to deploy the RuleApp. The RuleApp contains a ruleset that can be used by the web service to return an insurance quote premium. It takes a Customer as input and returns a Premium.

  1. Log in to the Rule Execution Server console (http://[hostname/IP address]:[WC_defaulthost port]/res), where hostname and port are the WebSphere Application Server where the Rule Execution Server is deployed.
  2. Click Explorer tab and select Deploy RuleApp Archive.
  3. Browse to and select the RuleApp_GetQuotePremium.jar.
  4. Check Increment RuleApp major version.
  5. Click Deploy, then click OK.

Deploy the web service

The second step is to deploy the web service enterprise application. The web service uses a mapping to the execution unit (XU) connection factory to execute the RuleApp, so the web service must be deployed to the same WebSphere Application Server cell at the same scope as the ILOG RES XU Resource Adapter's connection factory.

  1. Log in to the WebSphere Application Server console on which the Rule Execution Server is deployed (http://[host]:[port]/ibm/console).
  2. Select Applications => Application Types => WebSphere enterprise applications, and click Install.
  3. Browse and select HM_GetQuotePremium-EAR.ear, then click Next.
  4. Check Detailed – Show all installation options and parameters., then click Next.
  5. Click Step 6 Map resource references to resources.
  6. Under Target Resource JNDI Name, click Browse.
  7. Check eis/XUConnectionFactory, and click Apply.
  8. Click Step 10 Summary,and click Finish.
  9. Save the changes
  10. Select the application and click Start.

Drive the web service

Now you can take the WSDL from the service to test that the service works. To test the web service, you can use the Web Service Explorer in JRules Rule Studio.

  1. In Rule Studio, switch to the Web perspective by clicking Window => Open Perspective => Other, and selecting Web, then click OK.
  2. Select Run => Launch the Web Services Explorer.
  3. Switch to the WSDL page, and click WSDL Main.
  4. Enter the URL http://[hostname/IP address]:[WC_defaulthost port]/GetQuotePremium-Web/InvokeSetQuotePremiumJruleService/InvokeSetQuotePremiumJruleService.wsdl, where the host name and port are of the WebSphere Application Server where the web service is deployed, then click Go.
  5. Click issueQuote.
  6. Click Source in the top right corner.
  7. Paste the XML from Listing 1 into the soapenv:Body field, and click Go.
Listing 1. Listing 1. XML SOAP Body to call the web service
<q0:issueQuote>
<arg0>
<customer>
<BACCIDENTALDAMAGE>Y</BACCIDENTALDAMAGE> 
<CACCIDENTALDAMAGE>22500</CACCIDENTALDAMAGE> 
<CONTENTSVALUE>22500</CONTENTSVALUE> <HOUSEBEDS>2</HOUSEBEDS>
<HOUSETYPE>DETH</HOUSETYPE> <POLICYTYPE>A</POLICYTYPE>
<PROPERTYVALUE>155000</PROPERTYVALUE> <PURCHASED>N</PURCHASED>
</customer>
</arg0>
</q0:issueQuote>

In the Web Services Explorer Status section, you should see that the response contains a policyPrice. In Figure 2, the red circle shows that the policy price has been returned as 255.

Figure 2. Figure 2. Web service being driven by the Web Services Explorer
Web service being driven by the Web Services Explorer

(See a larger version of Figure 2.)


Implement the scenario

In this section, you'll learn how to perform the integration using the LB02 SupportPac.

Prerequisites

The only additional prerequisite is to install the LB02 SupportPac into Rules Studio. Refer to the Resources section for links to the SupportPac download site and the installation manual.

Due to the limitation of the user, password and scoring location being hard-coded into the generated XOM, depending on your environment configuration, we recommend you set up a scoring user. By doing so, you can redeploy the applications to another system without requiring a recompile. Instead you can just set up the scoring user and modify the machine's host file to point to the correct scoring host.

To create a scoring user, open the SPSS Collaboration and Deployment Services Deployment Manager.

  1. Select the Server Administration View.
  2. If you haven't already, create a new Administered Server as follows:
    1. Select File => New => Administered Server Connection.
    2. Set the Name to CnDS, and click Next.
    3. Enter the host name and port of the SPSS Collaboration and Deployment Services server, and click Finish.
    4. Right-click your administered server, click Log in as, enter the log-in details, and click OK.
    5. Expand Users and Groups.
    6. Double-click on your user repository and select New User.
    7. Set the user name to Score and choose a password.
    8. Add the user to the everyone group, and click OK.
    9. Expand the server, double-click Roles, and select New Role.
    10. Set the Role Name to Scorer, check Score Model, and click OK.
    11. Select the Scorer role in the Roles list, and select Edit Users and Groups.
    12. Select Show all available users/groups.
    13. Add the user Score to the role, and click OK.

Import existing rule projects

To get started, you need to import the existing rule projects into Rule Studio. This will enable you to change the solution from Part 1 to use predictive scoring.

  1. Download HM-GetQuotePremium-rulesPI.zip, which contains the existing rule projects.
  2. Open Rule Studio in the Rules perspective.
  3. Select File => Import => General => Existing Projects into Workspace.
  4. Select Archive file and click Browse.
  5. Select the HM-GetQuotePremium-rulesPI.zip.
  6. Make sure that both projects are checked, and click Finish.

Obtain metadata from SPSS to generate the BOM

The SupportPac does the work of importing and generating the resources required to call the scoring service from a JRule. All you need to do is point to your scoring service.

  1. In the Rule Explorer, right-click the GetQuotePremium-rules project and select Properties.
  2. Click SPSS Scoring Service, and specify the WSDL URI; for example, http://[hostname/IP address]:[WC_defaulthost port]/scoring/services/Scoring?WSDL.
  3. Enter the user name and password. These are encrypted and stored in the XOM header and in the Eclipse workspace metadata. The key used to encrypt the data cannot be changed.
  4. Click Refresh.
  5. Check the scoring configuration that you want the JRule to use, in this case RiskScoringConfig, and click OK.

You have now created the BOM and a com.ibm.rules.analytics folder, which have been added to the rules project.

Update the existing BOM to use scoring

You're now going to update the existing BOM to use scoring. You can use the scoring service when creating rules that will be used to influence business decisions. To configure the existing BOM to use the generated BOM to call the scoring configuration, you need to add a get score method to the existing BOM.

  1. Expand the BOM folder and double-click model.
  2. Expand the tree and double-click the Customer class.
  3. Under Members, select New.
  4. Check the type Method.
  5. Set the Name to getScore.
  6. Set the Type to java.lang.String, and click Finish.
  7. Double-click the new getScore() member.
  8. Under Member Verbalization, click Create. The verbalization should say the score of a customer.
  9. Save the model

Now that you have a method, you need to add the logic to call the scoring service. Start by importing the scoring BOM. Imports are added at the class level.

  1. In the BOM editor, click the Class tab.
  2. Expand BOM to XOM mapping.
  3. Expand Imports.
  4. Enter the following import statement:
    import com.ibm.rules.analytics.scoringservice.models.RiskScoringConfig();
  5. Save the model.

You can now navigate back to the new getScore() method to add logic to call the scoring service.

  1. Double-click getScore() in the members list.
  2. Expand BOM to XOM Mapping.
  3. Enter the code in Listing 2 into the body. Don't worry about multiple calls to this method. The generated scoring BOM handles caching the score value. To remove the cached value, it provides a reset method that can be called in a similar way to the getScore method.
    Listing 2. Listing 2. The get score method's code
    RiskScoringConfig score = new RiskScoringConfig(); 
    //init the scoring params 
    score.BACCIDENTALDAMAGE = this.BACCIDENTALDAMAGE; 
    score.CACCIDENTALDAMAGE = this.CACCIDENTALDAMAGE; 
    score.CONTENTSVALUE = this.CONTENTSVALUE; 
    score.HOUSEBEDS = this.HOUSEBEDS; 
    score.HOUSETYPE = this.HOUSETYPE; 
    score.POLICYTYPE = this.POLICYTYPE; 
    score.PROPERTYVALUE = this.PROPERTYVALUE; 
    score.PURCHASED = this.PURCHASED; 
    //call the scoring service 
    score.getScore(); 
    //return the score 
    return score.RISK;
  4. Save the model

Define the rule to use the scoring service

Now that the existing BOM can call the scoring service, you can edit the rules to make use of the predictive score. We currently have a pricing decision table. For this example, let's give all low risk customers a 20% discount.

  1. Right-click the Discount rule package and select New => Business Rule.
  2. Set the name to LowRiskDiscount, and click Finish.
  3. Set the code of the business rule to the code in Listing 3.
    Listing 3. Listing 3. Discount rule verbalization code
    if the score of customer is "Low" 
    then set premium to premium * 0.80; 
    print "The risk is " + the score of customer; 
    print "The premium after risk assessment is £" + premium ;
  4. Save the business rule.

Figure 3 shows the rule flow that is executed by the rule application. The flow shows a best practice by only defining packages in the flow. As the flow will execute all rules in that package, if rules are added, changed or removed from the packages, the rule flow does not require updating.

Figure 3. Figure 3. Rule flow
Rule flow

Test the updated rules

Now that the rule project has been edited to use a predictive model, you should test it in the Rule Studio environment. To do this:

  1. Right-click the rule project and select Run As => Run Configurations.
  2. Create a new rule project run configuration by double-clicking Rule Project.
  3. On the Rule Project tab, set the project to GetQuotePremium-rules.
  4. On the Parameters & Arguments tab, edit the Customer parameter. Check the function body and set the code to the shown in Listing 4.
Listing 4. Listing 4. Test code to create a customer object
com.ibm.quote.Customer customer = new com.ibm.quote.Customer();

customer.BACCIDENTALDAMAGE = “Y”; customer.CACCIDENTALDAMAGE = 
15000; customer.CONTENTSVALUE = 10000;
customer.HOUSEBEDS = 3;
customer.HOUSETYPE = “DETH”;
customer.POLICYTYPE = “A”;
customer.PROPERTYVALUE = 240000;
customer.PURCHASED = “N”;
return customer;
  1. Click Apply, then Run.
  2. You should see the output similar to this:
    Original Premium: £310.0
    The risk is High
    The premium after risk assessment is £310.0
  3. Now create another run configuration that returns a result of Low risk. You can accomplish this by trial and error or by using the tree diagram view of the model in SPSS Modeler, as shown in Figure 7 of Part 1.

Deploy the application to the Rule Execution Server

We have developed this application using a non-secure port. This means that the user name, password and data to the scoring service is transferred in a clear text SOAP message. You could encrypt this information using on-the-wire encryption, by using the secure HTTPS port for the request. The SupportPac does not support developing the scoring service from the secure port, but the scoring XOM can be manually edited after generation to switch to using the secure port. This will cause tests to fail in the Rule Studio environment and prevent the call from working until certificate trust has been configured. In this article, we'll use the secure port with the scoring service and the Rules Execution Server hosted on separate WebSphere Application Server V7 servers.

  1. Expand the com.ibm.rules.analytics folder and open the spss.scoringservice.models.XOM file in the text editor.
  2. Change the com.ibm.rules.analytics.wsdl property to use the secure port (WebSphere Application Server's default WC_defaulthost_secure port value is 9443) and change http to HTTPS.
  3. Re-import the scoring XOM into the customer BOM:
    1. Expand the BOM folder and double-click model.
    2. Expand the tree and double-click the Customer class.
    3. Expand BOM to XOM mapping.
    4. Expand Imports.
    5. Delete the following import statement:
      import com.ibm.rules.analytics.scoringservice.models.RiskScoringConfig();
    6. Save the model
    7. Re-enter the following statement in the Imports:
      import com.ibm.rules.analytics.scoringservice.models.RiskScoringConfig();
    8. Save the model
  4. Re-run the test configuration from the previous section to ensure that it fails with a run-time exception. This means that the XOM changes have been successfully picked up.

Create a rule application

The next step is to create the rule application, which will be deployed to the Rule Execution Server to be executed by clients.

  1. Select File => New => Project, select RuleApp Project, and click Next.
  2. Set the name to GetQuotePremium-ruleapp, and click Next.
  3. Click Add.
  4. Select GetQuotePremium-rules, and click OK, then Finish.

Deploy the rule application

Next you need to deploy the application to overwrite the original scenario's rule application.

  1. Right-click the GetQuotePremium-ruleapp project, and select RuleApp, then Deploy.
  2. Check Replace RuleApp version to replace the existing RuleApp you deployed earlier, then click Next.
  3. Check Create a temporary Rule Execution Server Configuration.
  4. Fill in the URL, Login and Password fields, then click Finish.
  5. Check the console messages for successful deployment.

Modify the web service client

Now you need to add some JARs to the WEB-INF/lib directory of the HM_GetQuotePremium-EAR.ear file, so that it can call the updated rule. To do this, go to [ILOG Install Directory]/SupportPacs/SupportPacLB02/lib and copy the four JARs into HM_GetQuotePremium-EAR.ear/GetQuotePremium-Web.war/WEB-INF/lib. Then update the application you deployed earlier to reflect this change. You can do this in Rational® Application Developer by importing HM_GetQuotePremium_WebPI.zip as a project and compiling a new EAR file with the updated lib folder. However, it may be easier to just include the JARs in HM_GetQuotePremium-EAR.ear using an archiving tool.

  1. Log in to the WebSphere Application Server console where the Rule Execution Server is deployed (http://[host]:[port]/ibm/console).
  2. Select Applications => Application Types => WebSphere enterprise applications.
  3. Check HM_GetQuotePremium, then click Update.
  4. Browse for the local system's updated HM_GetQuotePremium-EAR.ear, and click Next.
  5. Check Detailed – Show all installation options and parameters, and click Next.
  6. Click Step 6 Map resource references to resources.
  7. Make sure that eis/XUConnectionFactory is under Target Resource JNDI Name. If it is, skip to step 9.
  8. Check eis/XUConnectionFactory, and click Apply.
  9. Click Step 10 Summary, and click Finish.
  10. Save the changes
  11. Make sure that the application is started

Configure trust

If you have configured on-the-wire encryption, as described earlier, you need to configure trust so that the SPSS scoring service request and response can be encrypted and decrypted with the scoring service's public key. Configuring trust is achieved by extracting the default cell keystore certificate from the WebSphere Application Server that hosts the scoring service and adding it to the trust store in the WebSphere Application Server that hosts the web service application. This allows the certificate to be trusted automatically.

In our scenario, the WebSphere Application Server hosting the scoring service is always configured to have a secure (SSL) HTTP channel (port 9443 by default) and this port usually uses the default certificate from the cell or node keystore. The remote client that chooses to target the HTTPS URL needs to have added the scoring service server's public certificate to its own trust store.

In the following steps, the server is the WebSphere Application Server installation that hosts the deployed scoring service and the client is the WebSphere Application Server installation that hosts the client web service.

  1. Log-on to server WebSphere Application Server admin console.
  2. Select Security => SSL certificate and key management => Manage endpoint security configurations.
  3. Expand Inbound => node name servers server name.
  4. Select WC_defaulthost_secure.
  5. Note the SSL configuration name (NodeDefaultSSLSettings or CellDefaultSSLSettings).
  6. Select Security => SSL certificate and key management => SSL configurations => value returned in step 2.
  7. Note the keystore name.
  8. Select Security => SSL certificate and key management => Key stores and certificates => the keystore name returned in step 10 personal certificates.
  9. Check default and click Extract.
  10. Choose a name on the WebSphere Application Server local file system.
  11. Choose the data type binary der.

Now that you have exported the public key to the local file system, you need to securely transfer the file in binary mode to the client machine. The exported certificate can be found in the profile's etc folder and should be put in the client's profile etc folder (WebSphere Application Server_INSTALL_DIR/profiles/PROFILE_NAME/etc/).

  1. Log-on to the client WebSphere Application Server admin console.
  2. Select Security => SSL certificate and key management => Key stores and certificates.
  3. Click on the highest scope TrustStore available (either CellDefaultTrustStore or NodeDefaultTrustStore).
  4. Select Signer certificates => Add.
  5. Specify an alias.
  6. Specify the fully-qualified name of the copied certificate.
  7. Select the data type of binary der. The certificate should display.
  8. Click OK, then Save.

Adding keys to the trust store is dynamic, so you don't need to restart WebSphere Application Server.

Test the web service

You can take the WSDL from the service to test that the updated service works. To test the web service, you can use the Web Service Explorer in Rule Studio again.

  1. In Rule Studio, switch to the Web perspective by selecting Window => Open Perspective => Other and selecting Web, then click OK.
  2. Select Run => Launch the Web Services Explorer.
  3. Switch to the WSDL page, and click WSDL Main.
  4. Enter the URL https://[hostname/IP address]:[WC_defaulthost_secure port]/GetQuotePremium-Web/InvokeSetQuotePremiumJruleService/InvokeSetQuotePremiumJruleService.wsdl, where the host name and port are of the WebSphere Application Server where the web service is deployed, then click Go.
  5. Click issueQuote, then click Source in the upper right corner.
  6. Paste the XML from Listing 1 into the soapenv:Body field, and click Go.

This time the Status section will display a policyPrice and the messages in the output string stating the Original Premium, risk and the premium after risk assessment.


Provide a custom web service containing client code: an alternative approach

Due to the restrictions of the LB02 SupportPac, we'll also describe an alternative integration. This alternative allows you to apply the user name and password to the scoring service call using configurable web service policy sets and bindings in WebSphere Application Server. You can also supply the service location using an external service repository, a property file stored in SPSS Collaboration and Deployment Services, or a property file stored in the WebSphere Application Server installation properties folder. This is more flexible for deploying to multiple environments or environments that are changing frequently.

The design provides a web service that performs a web service call to the SPSS scoring service to obtain the prediction, then uses the initial parameter data and the prediction to call the JRule. To achieve this, you'll need to complete the following steps:

  1. Define and deploy rules to the Rule Execution Server.
  2. Generate a Scoring JAX-WS client.
  3. Create the web service.
  4. Deploy the web service to WebSphere Application Server.
  5. Configure WS-Policy and Security.

Figure 4 illustrates this alternative integration approach.

Figure 4. Figure 4. Web service integration
Web service integration

Step 1. Define and deploy rules to the Rule Execution Server

Design and build a RuleApp with a parameter that includes a required field for the prediction. Ensure that this is used in the business rules and test it. The steps to do this are explained in detail in the ILOG Quick Start Tutorial.

Step 2. Generate a Scoring JAX-WS client

Use a web service client generation tool like Rational Application Developer to generate a web service client. You can find the WSDL address of the scoring service at http://[hostname/IP address]:[WC_defaulthost port]/scoring/services/Scoring?WSDL. If you have issues with cyclic data definitions in the WSDL, contact your SPSS service representative for individual WSDL and XSD files.

Step 3. Create the web service

Create a Java class with a method that uses the customer class (used to define the BOM) for an input parameter and method return. You can then use this class to generate the JAX-WS service that exposes this method; for example, using a bottom-up web service generation tool like Rational Application Developer. The service implementation consists of two parts: the code to call the scoring service and the POJO code to execute the rules.

The scoring service call is implemented in the JAX-WS client generated in Step 2. All that is required is to use the generated client interface to supply the endpoint and scoring inputs. Ideally, on web service application start-up a call to the application properties file populates the correct endpoint and scoring ID for the target environment. After the initial deployment, you can change the endpoint property to make the service call over a secure port. The code in Listing 5 provides an example of how to call the scoring service.

Listing 5. Listing 5. Scoring service client code implementation
public Quote scoreQuote(Quote quote){ 
      String endpoint = “http://scoring.ibm.com/scoring/services/Scoring”;
      String scoringId = “HMCUSTSCORE”;
      //init the the scoring results
	quote.setRisk(0); 
	quote.setRiskConfidence(0); 
	//Create a scoring proxy	
      ScoringProxy proxy = new ScoringProxy(); 
	//Set the endpoint from properties
	proxy._getDescriptor().setEndpoint(endpoint); 
	ScoreRequest scoreRequest = new ScoreRequest(); 
	//Set scoring id from properties 
	scoreRequest.setId(scoringId); 
	//Create the input list	
	List<Input> inputList = scoreRequest.getInput(); 	 
	Input POLICYTYPE = new Input("POLICYTYPE",quote.getPolicytype()); 
	Input HOUSETYPE = new Input("HOUSETYPE",quote.getHousetype()); 
	Input HOUSEBEDS = new Input("HOUSEBEDS",quote.getHousebeds() +""); 
	Input PROPERTYVALUE = new Input("PROPERTYVALUE",
                         	quote.getPropertyvalue()+""); 
	Input BACCIDENTALDAMAGE = new Input("BACCIDENTALDAMAGE",
					quote.getBaccidentaldamage()); 
	Input CACCIDENTALDAMAGE = new Input("CACCIDENTALDAMAGE",
					quote.getCaccidentaldamage()+""); 
	Input CONTENTSVALUE = new Input("CONTENTSVALUE",
					quote.getContentsvalue()+""); 
	//Add the parameters to the input list 
	//Note: I am using JAX-WS (no need to call the setter)	 
	inputList.add(POLICYTYPE); 
	inputList.add(HOUSETYPE); 
	inputList.add(HOUSEBEDS); 
	inputList.add(PROPERTYVALUE); 
	inputList.add(BACCIDENTALDAMAGE); 
	inputList.add(CACCIDENTALDAMAGE); 
	inputList.add(CONTENTSVALUE); 
	try { 
		//Call the scoring service
		ScoreResult result = proxy.getScore(scoreRequest ); 

		//Handle the result
		List<RowValues> rowValues = result.getRowValues(); 
		//This code is a basic example where I know the scoring output can 
		//change.  By using other scoring services this code can be made
 		//dynamic.
		if(rowValues.size() >0 && rowValues.get(0).getValue().size() == 2){ 
			String riskResult = rowValues.get(0).getValue().
					get(0).getValue(); 
			String confidenceResult = rowValues.get(0).getValue().
					get(1).getValue(); 
			if( riskResult.equalsIgnoreCase("Y")) 
				{ 
					quote.setRisk(1); 
				} 
			double confidence = 
					new Double(confidenceResult).doubleValue(); 
			if(0 <= confidence && confidence <= 1){ 
				quote.setRiskConfidence(confidence); 
			}
		}else{ 
			throw new MissingDataException("Data is missing or incorrect",
 					null); 
			} 
		} catch (MissingDataException e) {		 
			e.printStackTrace(); 
		} catch (ScoringException e) { 
			e.printStackTrace(); 
		} 
	} 
	return quote;
}

Once you have the score result, you can call the rules. The rule execution is performed by the execution unit (XU) using POJO code, as shown in Listing 6. A major difference between this integration and the LB02 SupportPac integration is that here you are calling the scoring service first. By then adding the score to the rule application parameters, you're allowing for the decision logic that applies the score to be defined by a business user editing and creating the rules.

Finally the service implementation is finished by populating the customer object with the policy price and returning the object.

Listing 6. Listing 6. POJO code to call the scoring service
/* Call JRules to set the Quote premium */ 
try 
{ 
	//Create a session factory
	if (sessionFactory == null) 
	{ 
		sessionFactory = new IlrPOJOSessionFactory(); 
	} 
	//Create a Session 
	IlrStatelessSession session = sessionFactory.createStatelessSession(); 
	//Create a session request
	IlrSessionRequest sessionRequest = sessionFactory.createRequest();
	//set session properties
    	sessionRequest.setRulesetPath(IlrPath.parsePath(
                "/GetQuotePremiumruleapp/GetQuotePremiumrules")); 
	sessionRequest.setForceUptodate(true); 
			 
	//set the rule input parameters
	Map<String, Object> inputParameters = sessionRequest.getInputParameters(); 
	//The name must match the name of the parameter defined in the JRULE 
	inputParameters.put("customer", customer 
			.getCustomer()); 
	//execute the rule 
	IlrSessionResponse response = session.execute(sessionRequest); 

      //Handle the result
	MyRulesResult result = new MyRulesResult(); 

	result.setOutputString(response.getRulesetExecutionOutput()); 
			 
	result.setPolicyPrice((Double) response 
		.getOutputParameters().get("premium")); 
		 	 
	return result; 
} catch (Exception e) { 
	e.printStackTrace(); 
	return null; 
}

Step 4. Deploy the web service to WebSphere Application Server

Refer to the Deploying the RuleApp section for information on how to deploy and drive the web service.

Step 5. Configure WS-Policy and Security

The scoring operation provided by SPSS Collaboration and Deployment Services should be available only to an authenticated user. Authentication is performed by using a UsernameToken in a WS-Security header of the web service SOAP request. WebSphere Application Server allows you to configure the security header independently of the application. This allows for the application to be reconfigured and deployed on multiple systems without requiring a recompile. To configure WS-Security with a UsernameToken for a web service client application (that is, calling the scoring service) deployed to WebSphere Application V7 (or V6.1 with the Feature Pack for Web Services), create a web service policy set and policy set binding, and then associate these with the web service client application. To accomplish, this complete the following steps:

  1. Log on to WebSphere Application Server admin console.
  2. Deploy the web service client application that calls the scoring service.
  3. Create the web service policy set:
    1. Expand Services => Policy sets, and select Application policy sets.
    2. Select the provided policy set Username WSSecurity default and click Copy.
    3. Enter a name for the new policy set, for example: SPSSClientPolicySet and an optional description, and click OK.
    4. Click the new policy set SPSSClientPolicySet.
    5. Select WS-Addressing and click Delete.
    6. Select WS-Security => Main policy.
    7. Uncheck Message level protection and click Apply.
    8. Click Request token policies. You'll notice that it contains a token called token_auth of type Username and version WS-Security 1.0
    9. Return to the Main policy page and click OK.
  4. Create the web service client policy set binding:
    1. Expand Services => Policy sets, and select General client policy set bindings.
    2. Select the provided policy set Client sample and click Copy.
    3. Enter a name for the new policy set binding, for example: SPSSClientPolicySet Binding and an optional a description, then click OK.
    4. Click the new policy set binding SPSSClientPolicySet Binding.
    5. Click WS-Security .
    6. Click Authentication and protection.
    7. In the Authentication tokens section, click gen_signunametoken.
    8. Click Callback handler.
    9. Enter the user ID and password information in the Basic Authentication section, and click OK.

      The user name should be in the format Native//userid. For example, if authenticating with the admin user ID, specify Native//admin.

    10. Save the changes
  5. Apply the policy set and policy set binding to the web service client application:
    1. Expand Applications => Application Types => WebSphere enterprise applications , and click the web service client application name.
    2. In Web Services Properties section, click Service client policy sets and bindings .
    3. Select the application (the first entry in the displayed table), click Attach Client Policy Set and select your policy set; for example SPSSClientPolicySet, which should now appear in the Attached Client Policy Set column.

      Note: Selecting the application causes all nested service and operations to inherit this policy set. You can apply more fine grained control by selecting the appropriate operations.

    4. Select the application (the first entry in the displayed table), click Assign Binding and select your policy set; for example, SPSSClientPolicySetBinding, which should now appear in the Binding column.
    5. Save your changes.
  6. These changes should be dynamic, and you should now be able to successfully invoke your web service client application. However, if you have any problems, restart the WebSphere Application Server servers.

If you want to run the service over HTTPS, you need to configure trust. Refer to Configure trust for information on how to do this.


Conclusion

Following the steps in this article, you have now set up a JRule that can call the scoring service to create a dynamic result that is influenced by current data in the business. Now that you have a basic understanding on how implement this scenario, there are many ways you can expand on what you learned:

  • Create a custom SSL configuration and use your own CA signed certificates and associate them with the 9443 port.
  • Implement a web service to directly call the scoring service.
  • Add more complex rules, or factors to help categorize customers in to desirable subsegments.
  • Add additional use cases in which the rules manipulate the scoring and exploit the scoring cache.
  • Add additional rules to the flow to allow the scoring to manipulate the rule flow.
  • Use the scoring service to return additional information about the customer to be used as factors in rules.
  • Add monitoring to be able to analyze rule execution.

Downloads

DescriptionNameSize
eXectution Object Model used for rule executionGetQuotePremium-xom.jar3KB
eXecution Object Model used for rule executionHM_GetQuotePremium_Web_pi.zip1.8MB
The getQuote web service EARHM_GetQuotePremium-EAR.ear789KB
Rules Studio workspace archiveHM_GetQuotePremium-rulesPI.zip9KB
The RuleApp to deploy to the Rule Execution ServerRuleApp_GetQuotePremium.jar5KB

Resources

Learn

Get products and technologies

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Business process management on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Business process management, Big data and analytics
ArticleID=780299
ArticleTitle=Integrating SPSS predictive analytics into Business Intelligent applications, Part 2: Integrating the scoring service into an ILOG JRule
publish-date=12142011