The advantage of using a rigorous and well defined interface such as a WS-I compliant web service, is the ability to integrate it with other applications, using tools to aid that integration. Using HTTP as the communication layer and XML as the request and response formats, gives a systems integrator an industry standard way of communicating, with the choice of many tools to build that integration.
This tutorial is a quick walkthrough of the direct integration of Oracle Determinations Server running a rulebase with a simple Java application. The generated JAX-WS client will perform the job of creating the Request as a web service call, making the call, and interpreting the response.
A JAX-WS client allows you to build a web service call with Plain Old Java Objects (POJOs). The client performs the conversion to XML and a SOAP Request. The response is likewise converted from XML back to POJOs for ease of integration.
This tutorial uses the JAX-WS Reference Implementation project available from http://jax-ws.dev.java.net.
As this tutorial discusses programming in Java, you should be familiar with java, and be able to set up and run a program in an IDE of your choice (Eclipse or Netbeans for example). The following Software is required to follow this tutorial:
You should follow the instructions for installing JAX-WS correctly on your computer. This tutorial was written using version 2.1.7 of the JAX-WS RI, however older and new versions should work.
The first thing to do is to have a look at the SimpleBenefits rulebase in Oracle Policy Modeling. This rulebase is a very simple example. It determines 3 goals.
Is the claimant eligible for the low income allowance?
What is the claimant's low income allowance amount?
Is the claimant eligible for the teenage child allowance?
These goals are attributes of the global entity, and there are also child entities - the claimant's children. Eligibility for the low income allowance is based on the information on the global attribute only. Eligibility for the teenage child allowance is based on the claimant's children and their age.
You can run this rulebase in the Determinations Server from Oracle Policy Modeling by the following method:
The JAX-WS wsimport tool can be found in the bin directory of the JAX-WS install. It is called (wsimport.bat for Windows and wsimport.sh for Unix). For detailed instructions on running this tool, see https://jax-ws.dev.java.net/jax-ws-21-ea2/docs/wsimport.html
Using wsimport.bat to create a Java client on Windows.
The arguments passed to the wsimport program are as follows:
Now that we have a Java client that runs against the specific wsdl for SimpleBenefits, we can create a program that uses it. The program in this tutorial is a simple command line application that creates an assess request, runs it against a Determinations Server and prints the results.
The program will take in a single optional argument, the end point to send the request to. If no end point is provided, it will default to: http://localhost:9000/determinations-server9000/assess/soap/specific/10.2/SimpleBenefits
The entire class SimpleBenefitsSpecificAssessJaxWs is provided in Appendix 2 at the end of this document.
There are several steps to creating a correct assess request using the JAX-WS generated client
In order to compile and run the program, you will need to add all the jars found in the jaxws-ri\lib directory
In order to use the JAX-WS generated code, we need to import it into our class:
import com.oracle.determinations.server._10_2.simplebenefits.assess.types.*;
In the code below, we create the assess request, the session and the entities that we intend to use (Session, Global, ListChild – for holding children entities). All these objects exist within the SimpleBenefits rulebase and also exist as XML elements within the service request that we will send. The generated objects are named for the entity and attribute names, which makes them easy to write code for.
If this were a real application, it would probably collect information on the claimant and the children from a user interface, or perhaps load them from a database. To keep things simple, we will just hard-code the values for the claimant and his/her two children.
Each entity instance needs a unique id to identify it so we will set them to "global", "child1"and "child2" respectively. If the data was coming from a database, we would probably use primary keys for the ids of the entities.
AssessRequest request = new AssessRequest();
GlobalInstanceType global = new GlobalInstanceType();
ChildEntityListType children = new ChildEntityListType();
global.setListChild(children);
ChildInstanceType child1 = new ChildInstanceType();
child1.setId("child1");
ChildInstanceType child2 = new ChildInstanceType();
child2.setId("child2");
children.getChild().add(child1);
children.getChild().add(child2);
Before we send the request we need to add the outcomes that we want the Determinations Server to return. In this case, there are three outcomes that we want: is the claimant eligible for the low income allowance, their low income allowance payment and is the claimant eligible for the teenage child allowance.
To request outcomes for these 3 attributes, we add each attribute, and, instead of providing a value, we set the outcome style. This indicates that instead of providing a value we are asking for the Determinations Server to return the value.
In this case we are only interested in the answer, so the outcome style will be value-only.
global.setEligibleLowIncomeAllowance(new BooleanAttributeType());
global.getEligibleLowIncomeAllowance()
.setOutcomeStyle(OutcomeStyleEnum.VALUE_ONLY);
global.setLowIncomeAllowancePayment(new NumberAttributeType());
global.getLowIncomeAllowancePayment()
.setOutcomeStyle(OutcomeStyleEnum.VALUE_ONLY);
global.setEligibleTeenageAllowance(new BooleanAttributeType());
global.getEligibleTeenageAllowance()
.setOutcomeStyle(OutcomeStyleEnum.VALUE_ONLY);
Now we will set the values that we know: the claimant's income, whether the claimant a public housing client, and the ages of the children. These are attributes in the rulebase, and also in the generated web client - attributes of the Global entity (for the claimant) and the child entity (the child's age).
System.out.println("Setting claimant_income to 13000.00");
global.setClaimantIncome(new NumberAttributeType());
global.getClaimantIncome().setNumberVal(new BigDecimal(13000.00));
System.out.println("Setting claimant_public_housing_client to true");
global.setClaimantPublicHousingClient(new BooleanAttributeType());
global.getClaimantPublicHousingClient().setBooleanVal(true);
System.out.println("Setting child_age on child1 to 16");
child1.setChildAge(new NumberAttributeType());
child1.getChildAge().setNumberVal(new BigDecimal(16));
System.out.println("Setting child_age on child2 to 8");
child2.setChildAge(new NumberAttributeType());
child2.getChildAge().setNumberVal(new BigDecimal(8));
Next, there is no need to associate the children with the claimant, via the relationship claimantschildren as claimantschildren is a containment relationship. We simply need to set the global instance to the request:
request.setGlobalInstance(global);
The request is complete and ready to send. We create a specific service instance and call the assess method. This method will return an AssessResponseDocument, which should have the outcomes we asked for.
OdsAssessServiceSpecific102SimpleBenefits service
= new OdsAssessServiceSpecific102SimpleBenefits(new URL(endPoint),
SERVICE_QNAME);
System.out.println("\n--- Request Sent to Determinations Server ---");
AssessResponse response =
service.getOdsAssessServiceSpecific102SimpleBenefitsSOAP().assess(request);
System.out.println("\n--- Response from Determinations Server ---");The endPoint is the one specified when the program is run (supplied as an argument, or default and the SERVICE_QNAME is defined statically, at the top of the class as it never changes.
public static QName SERVICE_QNAME = new QName(
"http://oracle.com/determinations/server/10.2/SimpleBenefits/assess/types",
"odsAssessServiceSpecific102SimpleBenefits");
The Determinations Server must be running, with the SimpleBenefits rulebase deployed at the expected end point for the request to succeed.
When the Response document is returned, we can now process it for the outcomes that were in the request. If this were a real application, the outcomes would probably be displayed to the user, or persisted to the database. In this case we will simply print them out.
// look for the outcomes
BooleanAttributeType lowIncomeAllowance = response.getGlobalInstance()
.getEligibleLowIncomeAllowance();
NumberAttributeType lowIncomeAllowancePayment = response.getGlobalInstance()
.getLowIncomeAllowancePayment();
BooleanAttributeType childAllowance = response.getGlobalInstance()
.getEligibleTeenageAllowance();
// print out the results
System.out.println("\n--- Results ----");
if (lowIncomeAllowance.isBooleanVal() != null) {
System.out.println("eligible_low_income_allowance = "
+lowIncomeAllowance.isBooleanVal());
}
else if (lowIncomeAllowance.getUnknownVal() != null) {
System.out.println("eligible_low_income_allowance is unknown");
}
else if (lowIncomeAllowance.getUncertainVal()!= null) {
System.out.println("eligible_low_income_allowance is uncertain");
}
if (lowIncomeAllowancePayment.getNumberVal() != null) {
System.out.println("low_income_allowance_payment = "
+lowIncomeAllowancePayment.getNumberVal());
}
else if (lowIncomeAllowancePayment.getUnknownVal() != null) {
System.out.println("low_income_allowance_payment is unknown");
}
else if (lowIncomeAllowancePayment.getUncertainVal()!= null) {
System.out.println("low_income_allowance_payment is uncertain");
}
if (childAllowance.isBooleanVal() != null) {
System.out.println("eligible_teenage_allowance = "
+lowIncomeAllowance.isBooleanVal());
}
else if (childAllowance.getUnknownVal() != null) {
System.out.println("eligible_teenage_allowance is unknown");
}
else if (childAllowance.getUncertainVal()!= null) {
System.out.println("eligible_teenage_allowance is uncertain");
}
When you run the program, you should get the following output printed to standard out. From the response, we can see that all outcomes are known and that the claimant is eligible for both allowances and that the low income allowance payment is 70.0.
--- Starting new SimpleBenefitsAssess ---
Creating new Assess request
Setting attribute outcomes for 'eligible_low_income_allowance',
'low_income_allowance_payment' and 'eligible_teenage_allowance'
Setting claimant_income to 13000.00
Setting claimant_public_housing_client to true
Setting child_age on child1 to 16
Setting child_age on child2 to 8
--- Request Sent to Determinations Server ----
--- Response from Determinations Server ----
--- Results ----
eligible_low_income_allowance = true
low_income_allowance_payment = 70.0
eligible_teenage_allowance = true
In the tutorial above, we created and used a Java client compiled against the Specific wsdl of the SimpleBenefits rulebase. The procedure for creating a client against the Generic wsdl is an identical, although the Java client will be different, and require different code to achieve the same effect.
To complete this tutorial against the Generic wsdl, you should follow the steps above but with the following differences.
Follow the steps outlined in 1 Compile and run the SimpleBenefits rulebase, but save the Generic wsdl instead of the specific.
Save this wsdl as the file SimpleBenefits_generic.wsdl
Follow the steps outlined in 2 Compile the client, but for the saved generic wsdl instead of the specific. So, the wsimport command will look like:
wsimport -s C:\SimpleBenefits\wsdls\generic\jaxws\javaclient\src -d
C:\SimpleBenefits\wsdls\generic\jaxws\javaclient\classes
C:\SimpleBenefits\wsdls\generic\SimpleBenefits_generic.wsdl
This is the significantly different part for the Java client generated against the generic wsdl. Although the steps are the same, the code needed to get the same result will be different for the generic java client
1. Add the JAX-WS libraries to the classpath.
As with the specific exampl, you will need to add all the jars found in the jaxws-ri\lib directory. The list of jars is as follows:
activation.jar
FastInfoset.jar
http.jar
jaxb-api.jar
jaxb-impl.jar
jaxb-xjc.jar
jaxws-api.jar
jaxws-rt.jar
jaxws-tools.jar
jsr173_api.jar
jsr181-api.jar
jsr250-api.jar
mimepull.jar
resolver.jar
saaj-api.jar
saaj-impl.jar
stax-ex.jar
streambuffer.jar
woodstox.jar
2. Import the generated java client code
The generic namespace will be different from the specific namespace. In order to use the JAX-WS generated code, we need to import it into our class:
import
com.oracle.determinations.server._10_2.rulebase.assess.types.OdsAssessServiceGeneric102SimpleBenefits;
3. Create the assess and the entities that you will need for the request needs
The code for creating entities is a little different for the generic client. All entities must be put inside their containing entity (except global entity). All the entities must have the proper entity public name as the attribute "id".
From the code below, you can see that you need a few more lines to create the entity instances for the generic Java client.
AssessRequest request = new AssessRequest();
GlobalInstanceType global = new GlobalInstanceType();
EntityType children = new EntityType();
children.setId("child");
global.getEntity().add(children);
EntityInstanceType child1 = new EntityInstanceType();
child1.setId("child1");
EntityInstanceType child2 = new EntityInstanceType();
child2.setId("child2");
children.getInstance().add(child1);
children.getInstance().add(child2);4. Specify the outcomes (answers) that we want the Determinations Server to answer
Creating outcomes for the generic client also requires a few more lines of code. We create an AttributeType for each outcome, set the attribute public name as "id" and set its outcome style.
AttributeType lowIncomeAllowance = new AttributeType();
lowIncomeAllowance.setId("eligible_low_income_allowance");
lowIncomeAllowance
.setOutcomeStyle(OutcomeStyleEnum.VALUE_ONLY);
AttributeType lowIncomeAllowancePayment = new AttributeType();
lowIncomeAllowancePayment.setId("low_income_allowance_payment");
lowIncomeAllowancePayment
.setOutcomeStyle(OutcomeStyleEnum.VALUE_ONLY);
AttributeType teenageAllowance = new AttributeType();
teenageAllowance.setId("eligible_teenage_allowance");
teenageAllowance
.setOutcomeStyle(OutcomeStyleEnum.VALUE_ONLY);
global.getAttribute().add(lowIncomeAllowance);
global.getAttribute().add(lowIncomeAllowancePayment);
global.getAttribute().add(teenageAllowance);
5. Set attributes and relationships of the entities
When we create attributes for the generic client we create "AttributeType" objects and set the id for the Attribute to the public name of the rulebase attribute.
System.out.println("Setting claimant_income to 13000.00");
AttributeType claimantIncome = new AttributeType();
claimantIncome.setId("claimant_income");
claimantIncome.setNumberVal(new BigDecimal(13000.00));
System.out.println("Setting claimant_public_housing_client to true");
AttributeType claimantPHClient = new AttributeType();
claimantPHClient.setId("claimant_public_housing_client");
claimantPHClient.setBooleanVal(true);
global.getAttribute().add(claimantIncome);
global.getAttribute().add(claimantPHClient);
System.out.println("Setting child_age on child1 to 16");
AttributeType child1Age = new AttributeType();
child1Age.setId("child_age");
child1Age.setNumberVal(new BigDecimal(16));
child1.getAttribute().add(child1Age);
System.out.println("Setting child_age on child2 to 8");
AttributeType child2Age = new AttributeType();
child2Age.setId("child_age");
child2Age.setNumberVal(new BigDecimal(8));
child2.getAttribute().add(child2Age);Reference relationships of entities have to be identified in the same way. When we create a Relationship, set the name to the public name of the relationship. In this example, the relationship “climantschildren” is a containment relationship, thus it no longer needs to declared and set to the request.
After all attributes and relationships have been populated, the global entity instance needs to set to the request.
request.setGlobalInstance(global);
6. Call the assess method
Calling the assess method in the generic client is almost identical to the specific method, although the names are different.
OdsAssessServiceGeneric102SimpleBenefits service = new
OdsAssessServiceGeneric102SimpleBenefits
(new URL(endPoint), SERVICE_QNAME);
System.out.println("\n--- Request Sent to Determinations Server ----");
AssessResponse response = service.getOdsAssessServiceGeneric102SimpleBenefitsSOAP()
.assess(request);
7. Process the response
Once the response has been returned by the rulebase, we need to process the response to get the answers to the questions that we asked. This requires a little more code in the generic format because the generic XML does not distinguish between different types of entities, and it does not have specific names for the attributes we need to get.
However, by adding a simple method to look for the attributes that we need, we can simplify the code.
For details on the very simple methods getAttribute, see the full listing of the code in the Appendix below.
System.out.println("\n--- Results ----");
if (lowIncomeAllowanceResp.isBooleanVal() != null) {
System.out.println("eligible_low_income_allowance = "
+lowIncomeAllowanceResp.isBooleanVal());
}
else if (lowIncomeAllowanceResp.getUnknownVal() != null) {
System.out.println("eligible_low_income_allowance is unknown");
}
else if (lowIncomeAllowanceResp.getUncertainVal() != null) {
System.out.println("eligible_low_income_allowance is uncertain");
}
if (teenageAllowanceResp.isBooleanVal() != null) {
System.out.println("eligible_teenage_allowance = "
+teenageAllowanceResp.isBooleanVal());
}
else if (teenageAllowanceResp.getUnknownVal() != null) {
System.out.println("eligible_teenage_allowance is unknown");
}
else if (teenageAllowanceResp.getUncertainVal() != null) {
System.out.println("eligible_teenage_allowance is uncertain");
}
if (lowIncomeAllowancePaymentResp.getNumberVal() != null) {
System.out.println("low_income_allowance_payment = "
+lowIncomeAllowancePaymentResp.getNumberVal());
}
else if (lowIncomeAllowancePaymentResp.getUnknownVal() != null) {
System.out.println("low_income_allowance_payment is unknown");
}
else if (lowIncomeAllowancePaymentResp.getUncertainVal() != null) {
System.out.println("low_income_allowance_payment is uncertain");
}
When you run the generic version of this simple program, you should get the following output printed to standard out. From the response, the results are exactly the same as the specific program.
--- Starting new SimpleBenefitsAssess (Generic) ---
Creating new Assess request
Setting attribute outcomes for 'eligible_low_income_allowance',
'low_income_allowance_payment' and 'eligible_teenage_allowance'
Setting claimant_income to 13000.00
Setting claimant_public_housing_client to true
Setting child_age on child1 to 16
Setting child_age on child2 to 8
--- Request Sent to Determinations Server ----
--- Response from Determinations Server ----
--- Results ----
eligible_low_income_allowance = true
eligible_teenage_allowance = true
low_income_allowance_payment = 70.0
As you can see for both examples you can follow the same steps to generate and use an JAX-WS Java client for a rulebase deployed on the Determinations Server. You can use either client to achieve the desired operation.
The major difference between the specific and the generic client is ease of use versus maintainability. The specific format is easier to use and much less prone to error, because attributes and relationships have specific names within the rulebase. You cannot accidently misname at attribute or a relationship using the specific format. The disadvantage with the Specific format is that adding, removing or renaming attributes and relationships will require you to regenerate the Java client using the JAX-WS wsimport tool.
The interface generated for the generic client however, can be used for any rulebase, and never needs to be recompiled. Its disadvantage is that it is easier to make mistakes with the names of attributes and relationships and the code is somewhat more cumbersome.
End Point – An address that can be used to communicate with a web service. For this Tutorial the end point is the location of the SimpleBenefits rulebase when deployed to the Oracle Determinations Server.
JAX-WS – Java API for XML-Based Web Services. A standard defined by JSR 224 (http://jcp.org/en/jsr/detail?id=224). This tutorial uses the JAX-WS Reference implementation to generate a Web Service client.
Oracle Determinations Server – A web application which provides Oracle Policy Automation services as a web service.
Rulebase – A compiled rule project authored in Oracle Policy Modeling.
URL – Uniform Resource Locator. A global address for documents and services on the World Wide Web
Web Service – A service provided over the Web. Typically using XML and SOAP.
WSDL – Web Service Description Language. A standard way of describing Web Services that user XML and SOAP
import java.math.BigDecimal;
import java.net.URL;
import javax.xml.namespace.QName;
import com.oracle.determinations.server._10_2.simplebenefits.assess.types.AssessRequest;
import com.oracle.determinations.server._10_2.simplebenefits.assess.types.AssessResponse;
import com.oracle.determinations.server._10_2.simplebenefits.assess.types.BooleanAttributeType;
import com.oracle.determinations.server._10_2.simplebenefits.assess.types.ChildEntityListType;
import com.oracle.determinations.server._10_2.simplebenefits.assess.types.ChildInstanceType;
import com.oracle.determinations.server._10_2.simplebenefits.assess.types.GlobalInstanceType;
import com.oracle.determinations.server._10_2.simplebenefits.assess.types.NumberAttributeType;
import
com.oracle.determinations.server._10_2.simplebenefits.assess.types.OdsAssessServiceSpecific102SimpleBenefits;
import com.oracle.determinations.server._10_2.simplebenefits.assess.types.OutcomeStyleEnum;
public class SimpleBenefitsSpecificAssessJaxWs
{
public static String DEFAULT_ENDPOINT
= "http://localhost:9000/determinations-server9000/assess/soap/specific/10.2/SimpleBenefits";
public static QName SERVICE_QNAME = new QName(
"http://oracle.com/determinations/server/10.2/SimpleBenefits/assess/types",
"odsAssessServiceSpecific102_SimpleBenefits");
public static void main(String[] args) {
String endPoint = args.length > 0 ? args[0] : DEFAULT_ENDPOINT;
try {
System.out.println("--- Starting new SimpleBenefitsAssess ---");
System.out.println("Creating new Assess request");
AssessRequest request = new AssessRequest();
GlobalInstanceType global = new GlobalInstanceType();
ChildEntityListType children = new ChildEntityListType();
global.setListChild(children);
ChildInstanceType child1 = new ChildInstanceType();
child1.setId("child1");
ChildInstanceType child2 = new ChildInstanceType();
child2.setId("child2");
children.getChild().add(child1);
children.getChild().add(child2);
System.out.println("Setting attribute outcomes for "
+"'eligible_low_income_allowance',"
+" 'low_income_allowance_payment'"
+" and 'eligible_teenage_allowance'");
global.setEligibleLowIncomeAllowance(new BooleanAttributeType());
global.getEligibleLowIncomeAllowance()
.setOutcomeStyle(OutcomeStyleEnum.VALUE_ONLY);
global.setLowIncomeAllowancePayment(new NumberAttributeType());
global.getLowIncomeAllowancePayment()
.setOutcomeStyle(OutcomeStyleEnum.VALUE_ONLY);
global.setEligibleTeenageAllowance(new BooleanAttributeType());
global.getEligibleTeenageAllowance()
.setOutcomeStyle(OutcomeStyleEnum.VALUE_ONLY);
System.out.println("Setting claimant_income to 13000.00");
global.setClaimantIncome(new NumberAttributeType());
global.getClaimantIncome().setNumberVal(new BigDecimal(13000.00));
System.out.println("Setting claimant_public_housing_client to true");
global.setClaimantPublicHousingClient(new BooleanAttributeType());
global.getClaimantPublicHousingClient().setBooleanVal(true);
System.out.println("Setting child_age on child1 to 16");
child1.setChildAge(new NumberAttributeType());
child1.getChildAge().setNumberVal(new BigDecimal(16));
System.out.println("Setting child_age on child2 to 8");
child2.setChildAge(new NumberAttributeType());
child2.getChildAge().setNumberVal(new BigDecimal(8));
request.setGlobalInstance(global);
OdsAssessServiceSpecific102SimpleBenefits service
= new OdsAssessServiceSpecific102SimpleBenefits(new URL(endPoint),SERVICE_QNAME);
System.out.println("\n--- Request Sent to Determinations Server ----");
AssessResponse response = service.getOdsAssessServiceSpecific102SimpleBenefitsSOAP().assess(request);
System.out.println("\n--- Response from Determinations Server ----");
// look for the outcomes
BooleanAttributeType lowIncomeAllowance = response.getGlobalInstance()
.getEligibleLowIncomeAllowance();
NumberAttributeType lowIncomeAllowancePayment = response.getGlobalInstance()
.getLowIncomeAllowancePayment();
BooleanAttributeType childAllowance = response.getGlobalInstance().getEligibleTeenageAllowance();
// print out the results
System.out.println("\n--- Results ----");
if (lowIncomeAllowance.isBooleanVal() != null) {
System.out.println("eligible_low_income_allowance = "
+lowIncomeAllowance.isBooleanVal());
}
else if (lowIncomeAllowance.getUnknownVal() != null) {
System.out.println("eligible_low_income_allowance is unknown");
}
else if (lowIncomeAllowance.getUncertainVal()!= null) {
System.out.println("eligible_low_income_allowance is uncertain");
}
if (lowIncomeAllowancePayment.getNumberVal() != null) {
System.out.println("low_income_allowance_payment = "
+lowIncomeAllowancePayment.getNumberVal());
}
else if (lowIncomeAllowancePayment.getUnknownVal() != null) {
System.out.println("low_income_allowance_payment is unknown");
}
else if (lowIncomeAllowancePayment.getUncertainVal()!= null) {
System.out.println("low_income_allowance_payment is uncertain");
}
if (childAllowance.isBooleanVal() != null) {
System.out.println("eligible_teenage_allowance = "
+lowIncomeAllowance.isBooleanVal());
}
else if (childAllowance.getUnknownVal() != null) {
System.out.println("eligible_teenage_allowance is unknown");
}
else if (childAllowance.getUncertainVal()!= null) {
System.out.println("eligible_teenage_allowance is uncertain");
}
}
catch(Exception e) {
System.out.println("An error occurred"+ e.getMessage());
e.printStackTrace();
}
}
}
import java.math.BigDecimal;
import java.net.URL;
import javax.xml.namespace.QName;
import com.oracle.determinations.server._10_2.rulebase.assess.types.AssessRequest;
import com.oracle.determinations.server._10_2.rulebase.assess.types.AssessResponse;
import com.oracle.determinations.server._10_2.rulebase.assess.types.AttributeType;
import com.oracle.determinations.server._10_2.rulebase.assess.types.EntityInstanceType;
import com.oracle.determinations.server._10_2.rulebase.assess.types.EntityType;
import com.oracle.determinations.server._10_2.rulebase.assess.types.GlobalInstanceType;
import com.oracle.determinations.server._10_2.rulebase.assess.types.OdsAssessServiceGeneric102SimpleBenefits;
import com.oracle.determinations.server._10_2.rulebase.assess.types.OutcomeStyleEnum;
public class SimpleBenefitsGenericAssessJaxWs
{
public static String DEFAULT_ENDPOINT
= "http://localhost:9000/determinations-server9000/assess/soap/generic/10.2/SimpleBenefits";
public static QName SERVICE_QNAME = new QName(
"http://oracle.com/determinations/server/10.2/rulebase/assess/types",
"odsAssessServiceGeneric102_SimpleBenefits");
public static void main(String[] args) {
String endPoint = args.length > 0 ? args[0] : DEFAULT_ENDPOINT;
try {
System.out.println("--- Starting new SimpleBenefitsAssess (Generic) ---");
System.out.println("Creating new Assess request");
AssessRequest request = new AssessRequest();
GlobalInstanceType global = new GlobalInstanceType();
EntityType children = new EntityType();
children.setId("child");
global.getEntity().add(children);
EntityInstanceType child1 = new EntityInstanceType();
child1.setId("child1");
EntityInstanceType child2 = new EntityInstanceType();
child2.setId("child2");
children.getInstance().add(child1);
children.getInstance().add(child2);
System.out.println("Setting attribute outcomes for "
+"'eligible_low_income_allowance',"
+" 'low_income_allowance_payment'"
+" and 'eligible_teenage_allowance'");
AttributeType lowIncomeAllowance = new AttributeType();
lowIncomeAllowance.setId("eligible_low_income_allowance");
lowIncomeAllowance
.setOutcomeStyle(OutcomeStyleEnum.VALUE_ONLY);
AttributeType lowIncomeAllowancePayment = new AttributeType();
lowIncomeAllowancePayment.setId("low_income_allowance_payment");
lowIncomeAllowancePayment
.setOutcomeStyle(OutcomeStyleEnum.VALUE_ONLY);
AttributeType teenageAllowance = new AttributeType();
teenageAllowance.setId("eligible_teenage_allowance");
teenageAllowance
.setOutcomeStyle(OutcomeStyleEnum.VALUE_ONLY);
global.getAttribute().add(lowIncomeAllowance);
global.getAttribute().add(lowIncomeAllowancePayment);
global.getAttribute().add(teenageAllowance);
System.out.println("Setting claimant_income to 13000.00");
AttributeType claimantIncome = new AttributeType();
claimantIncome.setId("claimant_income");
claimantIncome.setNumberVal(new BigDecimal(13000.00));
System.out.println("Setting claimant_public_housing_client to true");
AttributeType claimantPHClient = new AttributeType();
claimantPHClient.setId("claimant_public_housing_client");
claimantPHClient.setBooleanVal(true);
global.getAttribute().add(claimantIncome);
global.getAttribute().add(claimantPHClient);
System.out.println("Setting child_age on child1 to 16");
AttributeType child1Age = new AttributeType();
child1Age.setId("child_age");
child1Age.setNumberVal(new BigDecimal(16));
child1.getAttribute().add(child1Age);
System.out.println("Setting child_age on child2 to 8");
AttributeType child2Age = new AttributeType();
child2Age.setId("child_age");
child2Age.setNumberVal(new BigDecimal(8));
child2.getAttribute().add(child2Age);
request.setGlobalInstance(global);
OdsAssessServiceGeneric102SimpleBenefits service = new OdsAssessServiceGeneric102SimpleBenefits
(new URL(endPoint), SERVICE_QNAME);
System.out.println("\n--- Request Sent to Determinations Server ----");
AssessResponse response = service.getOdsAssessServiceGeneric102SimpleBenefitsSOAP()
.assess(request);
System.out.println("\n--- Response from Determinations Server ----");
// look for the outcomes
GlobalInstanceType globalResp = response.getGlobalInstance();
AttributeType lowIncomeAllowanceResp
= getAttribute(globalResp, "eligible_low_income_allowance");
AttributeType lowIncomeAllowancePaymentResp
= getAttribute(globalResp, "low_income_allowance_payment");
AttributeType teenageAllowanceResp
= getAttribute(globalResp, "eligible_teenage_allowance");
// print out the results
System.out.println("\n--- Results ----");
if (lowIncomeAllowanceResp.isBooleanVal() != null) {
System.out.println("eligible_low_income_allowance = "
+lowIncomeAllowanceResp.isBooleanVal());
}
else if (lowIncomeAllowanceResp.getUnknownVal() != null) {
System.out.println("eligible_low_income_allowance is unknown");
}
else if (lowIncomeAllowanceResp.getUncertainVal() != null) {
System.out.println("eligible_low_income_allowance is uncertain");
}
if (teenageAllowanceResp.isBooleanVal() != null) {
System.out.println("eligible_teenage_allowance = "
+teenageAllowanceResp.isBooleanVal());
}
else if (teenageAllowanceResp.getUnknownVal() != null) {
System.out.println("eligible_teenage_allowance is unknown");
}
else if (teenageAllowanceResp.getUncertainVal() != null) {
System.out.println("eligible_teenage_allowance is uncertain");
}
if (lowIncomeAllowancePaymentResp.getNumberVal() != null) {
System.out.println("low_income_allowance_payment = "
+lowIncomeAllowancePaymentResp.getNumberVal());
}
else if (lowIncomeAllowancePaymentResp.getUnknownVal() != null) {
System.out.println("low_income_allowance_payment is unknown");
}
else if (lowIncomeAllowancePaymentResp.getUncertainVal() != null) {
System.out.println("low_income_allowance_payment is uncertain");
}
}
catch(Exception e) {
System.out.println("An error occurred"+ e.getMessage());
e.printStackTrace();
}
}
// Go through the list of attributes for the global entity and return the
// attribute that matches the attributeId.
private static AttributeType getAttribute(GlobalInstanceType globalResp, String attributeId) {
AttributeType attribute = null;
for (int i =0; i < globalResp.getAttribute().size(); i++) {
if (attributeId.equals(globalResp.getAttribute().get(i).getId())) {
attribute = globalResp.getAttribute().get(i);
break;
}
}
return attribute;
}
}