9 Creating a Rule-enabled Non-SOA Java EE Application

This chapter describes how to use Oracle JDeveloper to create a rule-enabled non-SOA Java Enterprise Edition (EE) application. It also shows a sample application, a Java Servlet, which runs as a Java EE application using Oracle Business Rules (this describes using Oracle Business Rules without a SOA composite).

The chapter includes the following sections:

The source code for Oracle Business Rules-specific samples and SOA samples are available online in the Oracle SOA Suite samples page.

9.1 Introduction to the Grades Sample Application

The Grades application provides a sample use of Oracle Business Rules in a Java Servlet. The servlet uses Rules SDK Decision Point API.

This sample demonstrates the following:

  • Creating rules in an Oracle Business Rules dictionary using an XSD schema that defines the input and the output data, and the facts for the data model. In this case you provide the XSD schema in the file grades.xsd.

  • Creating a servlet that uses Oracle Business Rules to determine a grade for each test score that is input.

  • Creating a test page to supply input test scores and to submit the data to the grades servlet.

  • Deploying the application, running it, submitting test values, and seeing the output.

There is another example--for more information, see How to Open the Car Rental Sample Application and Project.

9.2 Creating an Application and a Project for Grades Sample Application

You can create Grades sample application by following the steps below.

Note:

The screen shots reflect a previous version, however, the content is applicable to the current release.

To create the application and the project for the grades sample application, do the following:

  • Create a Fusion Web Application (ADF)

  • Create a project in the application

  • Add the schema to define the inputs, outputs, and the objects for the data model

  • Create an Oracle Business Rules dictionary in the project

9.2.1 How to Create a Fusion Web Application for the Grades Sample Application

To work with Oracle Business Rules and create a Java EE application, you first need to create the application in Oracle JDeveloper.

To create a fusion web application (ADF) for grades:

  1. Create an application. You can do this in the Application Navigator by selecting New Application..., or from the Application menu list by selecting New Application....

  2. In the Name your application dialog enter the application options, as shown in Figure 9-1:

    1. In the Application Template area, select Fusion Web Application.

    2. In the Application Name field, enter an application name. For example, enter GradeApp.

    3. In the Directory field, specify a directory name or accept the default.

    4. In the Application Package Prefix field, enter an application package prefix. For example, com.example.grades.

      The prefix, followed by a period applies to objects created in the initial project of an application.

    Figure 9-1 Adding GradeApp Application

    Description of Figure 9-1 follows
    Description of "Figure 9-1 Adding GradeApp Application"
  3. Click Finish. After creating the application Oracle JDeveloper displays the file summary, as shown in Figure 9-2.

Figure 9-2 New Grades Application Named GradeApp

Description of Figure 9-2 follows
Description of "Figure 9-2 New Grades Application Named GradeApp"

9.2.2 How to Develop Accessible ADF Faces Pages

Oracle software implements the standards of the Web Content Accessibility Guidelines (WCAG) 1.0 Level AA using an interpretation of the standards at http://www.oracle.com/accessibility/standards.html

ADF Faces user interface components have built-in accessibility support for visually and physically impaired users. User agents such as a web browser rendering to nonvisual media such as a screen reader can read component text descriptions to provide useful information to impaired users. Access key support provides an alternative method to access components and links using only the keyboard. ADF Faces accessibility audit rules provide direction to create accessible images, tables, frames, forms, error messages and popup windows using accessible HTML markup.

For information on how to develop accessible ADF Faces pages, see Developing Accessible ADF Faces Pages in Oracle Fusion Middleware Web User Interface Developer's Guide for Oracle Application Development Framework.

9.2.3 How to Create the Grades Project

In the Grades sample application you do not use the Model or ViewController projects. You create a project in the application for the grades sample project.

To create a grades project:

  1. In the GradeApp application, in the Application Navigator, from the Application Menu select New Project....

  2. In the New Gallery, in the Items area select Generic Project.

  3. Click OK.

  4. In the Name your project page enter the values as shown in Figure 9-3:

    1. In the Project Name field, enter a name. For example, enter Grades.

    2. Enter or browse for a directory name, or accept the default.

    3. Select the Project Technologies tab.

    4. In the Available area double-click ADF Business Components to move this item to the Selected area. This also adds Java to the Selected area as shown in Figure 9-3.

      Figure 9-3 Adding Generic Project to the Grades Application

      Description of Figure 9-3 follows
      Description of "Figure 9-3 Adding Generic Project to the Grades Application"
  5. Click Finish. This adds the Grades project.

9.2.4 How to Add the XML Schema and Generate JAXB Classes in the Grades Project

To create the Grades sample application you need to use the grades.xsd file, as shown in example grades.xsd schema below. You can create and store the schema file locally and then use Oracle JDeveloper to copy the file to your project.

<?xml version= '1.0' encoding= 'UTF-8' ?>
<xs:schema targetNamespace="http://example.com/grades"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"     
        xmlns:tns="http://example.com/grades"
        attributeFormDefault="qualified" elementFormDefault="qualified" 
        xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" 
        xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
        jaxb:extensionBindingPrefixes="xjc" 
        jaxb:version="2.0">        
        
    <xs:element name="TestScore">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="name" type="xs:string"/>
                <xs:element name="testName" type="xs:string"/>
                <xs:element name="testScore" type="xs:double"/>
                <xs:element name="testCurve" type="xs:double"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="TestGrade">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="grade" type="tns:Grade"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:simpleType name="Grade">
        <xs:restriction base="xs:string">
            <xs:enumeration value="A"/>
            <xs:enumeration value="B"/>
            <xs:enumeration value="C"/>
            <xs:enumeration value="D"/>
            <xs:enumeration value="F"/>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

To add the XML schema to the grades project:

  1. Save the schema file as shown in example grades.xsd schema to a local file named grades.xsd.
  2. In the Application Navigator select the Grades project.
  3. Right-click and in the context menu select New....
  4. In the New Gallery select the All Technologies tab.
  5. In the Categories area, expand General and select XML.
  6. In the Items area, select XML Schema. Click OK.
  7. In the Create XML Schema dialog, in the File Name field enter grades.xsd.
  8. In the Create XML Schema dialog, in the Directory field add the xsd directory to the Grades project path name, as shown in Figure 9-4.

    Figure 9-4 Adding Schema to Grades Project in xsd Directory

    Description of Figure 9-4 follows
    Description of "Figure 9-4 Adding Schema to Grades Project in xsd Directory"

    Click OK.

  9. In the grades.xsd file, select the Source tab.
  10. Copy the schema shown in example above to the grades.xsd in the Grades project, as shown in Figure 9-5.

    Figure 9-5 Shows the Grades.xsd Schema File in the Grades Project

    Description of Figure 9-5 follows
    Description of "Figure 9-5 Shows the Grades.xsd Schema File in the Grades Project"

9.2.4.1 How to generate JAXB 2.0 content model from grades schema

To generate JAXB 2.0 content model from grades schema:

  1. In the Application Navigator, in the Grades project expand Resources and select grades.xsd.
  2. Right-click and in the context menu select Generate JAXB 2.0 Content Model.
  3. In the JAXB 2.0 Content Model from XML Schema dialog, click OK.

9.2.5 How to Create an Oracle Business Rules Dictionary in the Grades Project

After creating a project in Oracle JDeveloper create business rules within the Grades project.

To use business rules with Oracle JDeveloper, you do the following:

  • Add a business rule to the project and import grades.xsd schema

  • Create input and output variables

  • Create an Oracle Business Rules dictionary in the project

To create a business rules dictionary in the business tier:

  1. In the Application Navigator, select the Grades project.
  2. Right-click and in the context menu select New.... and select the All Technologies tab.
  3. In the New Gallery, in the Categories area, expand Business Tier and select Business Rules.
  4. In the New Gallery, in the Items area, select Business Rules. Click OK.

    Oracle JDeveloper displays the Create Business Rules dialog, as shown in Figure 9-6.

    Figure 9-6 Adding a Business Rule to Grades with the Create Business Rules Dialog

    Description of Figure 9-6 follows
    Description of "Figure 9-6 Adding a Business Rule to Grades with the Create Business Rules Dialog"
  5. In the Name field, enter a name to name the dictionary. For example, enter GradingRules.
  6. To add an input, from the list next to the Add button select Input....
  7. In the Type Chooser, expand the Project Schemas Files folder and expand grades.xsd. Select the input TestScore, as shown in Figure 9-7.

    Figure 9-7 Shows the Type Chooser Dialog with TestScore Element

    Description of Figure 9-7 follows
    Description of "Figure 9-7 Shows the Type Chooser Dialog with TestScore Element"
  8. On the Type Chooser window, click OK. This displays the Create Business Rules dialog.
  9. In the Create Business Rules dialog, in a similar manner to the input add the output by selecting Output... to add the output element TestGrade from the grades.xsd schema.

    The resulting Create Business Rules dialog is shown in Figure 9-8.

    Figure 9-8 Create Business Rules Dialog with Grades Input and Output

    Description of Figure 9-8 follows
    Description of "Figure 9-8 Create Business Rules Dialog with Grades Input and Output"

    Click OK. Oracle JDeveloper creates the GradingRules dictionary as shown in Figure 9-9.

  10. In the File menu, select Save All to save your work.

Figure 9-9 Shows the New Grading Rules Dictionary

Description of Figure 9-9 follows
Description of "Figure 9-9 Shows the New Grading Rules Dictionary"

Note that the business rule validation log area for the new dictionary shows several validation warnings. These validation warning messages are cleared as you modify the dictionary in later steps.

9.3 Creating Data Model Elements and Rules for the Grades Sample Application

Create data model elements and rules for the grades sample application by following the steps below.

To create the data model and the business rules for the Grades sample application, do the following:

  • Create value sets for grades

  • Create rules by adding a Decision Table for grades

  • Split the Decision Table and add actions for rules

  • Rename the default decision function

9.3.1 How to Create Value Sets for Grades Sample Application

In this example you associate a value set with a fact type. This supports using a Decision Table where you need value sets that specify how to draw values for each cell in the Decision Table (for the conditions in the Decision Table).

To create the value set for the grades sample application:

  1. In Rules Designer, select the Value Sets navigation tab.
  2. From the list next to the Create Value Set... button, select List of Ranges.
  3. For the value set, double-click in the Name field to select the default name.
  4. Enter Grade Scale, and press Enter to accept the value set name.
  5. In the Value Set table, double-click the icon for the Grade Scale value set to display the Edit Value Set dialog.
  6. In the Edit Value Set dialog, click Add to add a value and click Add three times to add three more values.
  7. In the Endpoint field, enter 90 for the top endpoint and press Enter to accept the new value.
  8. For the next value, in the Endpoint field enter 80 and press Enter to accept the new value. Similarly, for the next two values enter values in the Endpoint field, values 70 and 60.
  9. In the Included Endpoint field for each value select each check box.
  10. Modify the Alias field for each value to enter the values A, B, C, D, and F, for each corresponding range, (press Enter after you add each alias).

9.3.2 How to Associate a Value Set with a Fact Property

To prepare for creating Decision Tables you can associate a global value set with fact properties in the data model. In this way condition cells in a Decision Table Conditions area can use the value set when you create a Decision Table.

To associate a value set with a fact property:

  1. In Rules Designer, select the Facts navigation tab.
  2. In the Facts navigation tab select the XML Facts tab.
  3. Double-click the XML fact icon for the TestScore fact. This displays the Edit XML Fact dialog.
  4. In the Edit XML Fact dialog select the testScore property.
  5. In the Value Set field, from the list select Grade Scale.
  6. Click OK.

9.3.3 How to Add a Decision Table for Grades Sample Application

You create rules in a Decision Table to process input facts and to produce output facts, or to produce intermediate conclusions that Oracle Business Rules can further process using additional rules or in another Decision Table.

To use a Decision Table for rules in this application you work with facts representing a test score. Then, you use a Decision Table to create rules based on the test score to produce a grade.

To add a decision table for Grades application:

  1. In Rules Designer, select Ruleset_1 under the Rulesets list.
  2. In Ruleset_1, click Create from the Decision Table area on the Overview tab. This creates DecisionTable_1. You can ignore the warning messages shown in the Business Rule Validation log area. You remove these warning messages in later steps.
  3. In the Decision Table, DecisionTable_1, click the Add button and from the list select Condition.
  4. In the Decision Table, double-click <edit condition>. Then, in the variables navigator expand TestScore and select testScore. This enters the expression TestScore.testScore for condition C1.

If you view the rules validation log, you should see warning messages. You remove these warning messages as you modify the Decision Table in later steps.

9.3.4 How to Add an Action to a Decision Table

To add an action to a decision table:

You add an action to the Decision Table to assert a new Grade fact.

  1. In the Decision Table, click the Add button and from the list select Action and select Assert New.
  2. In the Actions area, double-click Assert New.

    This displays the Action Editor dialog.

  3. In the Action Editor dialog, in the Facts area select TestGrade.
  4. In the Action Editor dialog, in the Properties table for the property grade, select the Parameterized check box and the Constant check box.

    This specifies that each rule independently sets the grade.

  5. In the Action Editor dialog select the Always Selected check box.
  6. In the Action Editor dialog click OK.
  7. Select Save All from the File main menu to save your work.

Next you add rules to the Decision Table and specify an action for each rule.

9.3.5 How to Add Rules in the Decision Table for Grades Sample Application

You can use the Decision Table split operation to create rules for the value set associated with the conditions row in the Decision Table. This creates one rule for every value.

To split the decision table, from the Decision Table, click the Split Table button from the list select Split Table. The split operation eliminates the "do not care" cells from the table. The table now shows five rules that cover all ranges, as shown in Figure 9-10.

These steps produce validation warnings for action cells with missing expressions. You fix these problems in later steps when you define actions for each rule.

Figure 9-10 Splitting a Decision Table Using Split Table Operation for Grades

Description of Figure 9-10 follows
Description of "Figure 9-10 Splitting a Decision Table Using Split Table Operation for Grades"

To add actions for each rule in the decision table:

In the Decision Table you specify a value for the result, a grade property, associated with TestGrade for each action cell in the Actions area. The possible choices for each grade property are the valid grades. In this step you fill in a value for each of the rules. The values you enter correspond to the conditions that form each rule in the Decision Table.

  1. In the Actions area, double-click the action cell for rule R1 as shown in Figure 9-11.

    Figure 9-11 Adding Action Cell Values to Grades Decision Table

    Description of Figure 9-11 follows
    Description of "Figure 9-11 Adding Action Cell Values to Grades Decision Table"
  2. In the list select the corresponding value for the action cell. For example, select Grade.F.
  3. For each of the remaining action cells select the appropriate value for TestScore: D, C, B, and A.

9.3.6 How to Rename the Decision Function for Grades Sample Application

The name you specify when you use a decision function with a Rules SDK Decision Point must match the name of a decision function in the dictionary. To make the name match, you can rename the decision function to any name you like. Thus, for this example you rename the default decision function to use the name GradesDecisionFunction.

To rename the decision function:

  1. In the Application Navigator, in the Grades project, expand the Resources folder and double-click the dictionary GradingRules.rules.
  2. Select the Decision Functions navigation tab.
  3. In the Name field in the Decision Functions table edit the decision function name to enter the value GradesDecisionFunction, and then press Enter, as shown in Figure 9-12.

Figure 9-12 Renaming Decision Function in Rules Designer

Description of Figure 9-12 follows
Description of "Figure 9-12 Renaming Decision Function in Rules Designer"

9.4 Adding a Servlet with Rules SDK Calls for Grades Sample Application

The Grades sample application includes a servlet that uses the Rules Engine.

To add this servlet with Oracle Business Rules you need to understand the important Rules SDK methods. Thus, to use the Oracle Business Rules dictionary you created with Rules Designer, you do the following:

  • Create initialization steps that you perform one time in the servlet init routine.

  • Create a servlet service routine using the Rules SDK Decision Point API.

  • Perform steps to add the servlet code in the project.

For more information on Rules SDK Decision Point API, see Working with Rules in Standalone (Non SOA/BPM) Scenarios.

9.4.1 How to Add a Servlet to the Grades Project

You add a servlet to the grades project using the Create HTTP Servlet wizard.

To add a servlet to the Grades project with Oracle JDeveloper:

  1. In the Application Navigator, select the Grades project.
  2. Right-click the Grades project and in the context menu select New....
  3. In the New Gallery, select the All Technologies tab.
  4. In the New Gallery, in the Categories area expand Web Tier and select Servlets.
  5. In the New Gallery, in the Items area select HTTP Servlet. Click OK.

    Oracle JDeveloper displays the Create HTTP Servlet Welcome page.

  6. Click Next.

    This displays the Web Application page.

  7. Select Servlet 2.5\JSP 2.1 (Java EE 1.5) and click Next.

    This displays the Create HTTP Servlet - Step 1 of 3: Servlet Information page.

  8. Enter values in Create HTTP Servlet - Step 1 of 3: Servlet Information page, as follows, and as shown in Figure 9-13.
    • Class: GradesServlet

    • Package: com.example.grades

    • Generate Content Type: HTML

    • Generate Header Comments: unchecked

    • Implement Methods: service() checked and all other check boxes unchecked

    Figure 9-13 Create HTTP Servlet Wizard - Step 1 of 3: Servlet Information

    Description of Figure 9-13 follows
    Description of "Figure 9-13 Create HTTP Servlet Wizard - Step 1 of 3: Servlet Information"

    Click Next.

    This displays the Create HTTP Servlet: Step 2 of 3: Mapping Information dialog as shown in Figure 9-14.

    Figure 9-14 Create HTTP Servlet Wizard - Step 2 of 3: Mapping Information

    Description of Figure 9-14 follows
    Description of "Figure 9-14 Create HTTP Servlet Wizard - Step 2 of 3: Mapping Information"
  9. Configure this dialog as follows:
    • Name: GradesServlet

    • URL Pattern: /gradesservlet

    Click Finish when done.

    JDeveloper adds a Web Content folder to the project and creates a GradesServlet.java file and opens the file in the editor as shown in Figure 9-15.

    Figure 9-15 Generated GradesServlet.java

    Description of Figure 9-15 follows
    Description of "Figure 9-15 Generated GradesServlet.java"
  10. Replace the generated servlet with the source as shown in the grades application example below.
    package com.example.grades;
     
    import java.io.IOException;
    import java.io.PrintWriter;
     
    import java.util.ArrayList;
    import java.util.List;
     
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
     
    import oracle.rules.rl.exceptions.RLException;
    import oracle.rules.sdk2.decisionpoint.DecisionPoint;
    import oracle.rules.sdk2.decisionpoint.DecisionPointBuilder;
    import oracle.rules.sdk2.decisionpoint.DecisionPointInstance;
    import oracle.rules.sdk2.exception.SDKException;
    import oracle.rules.sdk2.repository.DictionaryFQN;
     
    public class GradesServlet extends HttpServlet {
     
        private static final String CONTENT_TYPE = "text/html";
        private static final String DICT_PKG = "com.example.grades";
        private static final String DICT_NAME = "GradingRules";
        private static final DictionaryFQN DICT_FQN =
            new DictionaryFQN(DICT_PKG, DICT_NAME);
        private static final String DF_NAME = "GradesDecisionFunction";
     
        private DecisionPoint m_decisionPoint = null; // init in init()
     
        public void init(ServletConfig config) throws ServletException {
            super.init(config);
            
            try {
                
                // specifying the Decision Function and Dictionary FQN
                // load the rules from the MDS repository.
                m_decisionPoint = new DecisionPointBuilder()
                                    .with(DF_NAME)
                                    .with(DICT_FQN)
                                    .build();
            } catch (SDKException e) {
                System.err.println("Failed to build Decision Point: " +
                                   e.getMessage());
                throw new ServletException(e);
            }
        }
     
        public void service(HttpServletRequest request,
                            HttpServletResponse response) throws ServletException,
                                                                 IOException {        
            // retrieve parameters
            String name = request.getParameter("name");
            String strScore = request.getParameter("testScore");
     
            // open output document
            StringBuilder doc = new StringBuilder();        
            addHeader(doc);
     
            // create TestScore object to assert
            final TestScore testScore = new TestScore();
            testScore.setName(name);
            
            try {
                testScore.setTestScore(Integer.parseInt(strScore));
            } catch (NumberFormatException e){ /* use default val */ }                
     
            // get DecisionPointInstance for invocation
            DecisionPointInstance point = m_decisionPoint.getInstance();
            
            // set input parameters
            point.setInputs(new ArrayList() {{ add(testScore); }});
     
            // invoke decision point and get result value
            TestGrade testGrade = null;        
            try {
                
                // invoke the decision point with our inputs
                List<Object> result = point.invoke();
                if (result.size() != 1){
                    error(doc, testScore.getName(), "bad result", null);                
                }
                // decision function returns a single TestGrade object
                testGrade = (TestGrade)result.get(0);
            } catch (RLException e) {
                error(doc, testScore.getName(), "RLException occurred: ", e);
            } catch (SDKException e) {
                error(doc, testScore.getName(), "SDKException occurred", e);
            } 
            
            if (testGrade != null){
                // create output table in document
                openTable(doc);
                addRow(doc, testScore.getName(), strScore, testGrade.getGrade());
                closeTable(doc);
            }
     
            addFooter(doc);
     
            // write document
            response.setContentType(CONTENT_TYPE);
            PrintWriter out = response.getWriter();
            out.println(doc);
            out.close();
        }
     
     
        public static void addHeader(StringBuilder doc) {
            doc.append("<html>");
            doc.append("<head><title>GradesServlet</title></head>");
            doc.append("<body>");
            doc.append("<h1>Test Results</h1>");
        }
     
        public static void addFooter(StringBuilder doc) {
            doc.append("</body></html>");
        }
     
        public static void openTable(StringBuilder doc) {
            doc.append("<table border=\"1\"");
            doc.append("<tr>");
            doc.append("<th>Name</th>");
            doc.append("<th>Score</th>");
            doc.append("<th>Grade</th>");
            doc.append("</tr>");
        }
     
        public static void closeTable(StringBuilder doc) {
            doc.append("</table>");
        }
        
        public static void addRow(StringBuilder doc, String name, String score, Grade grade){
            doc.append("<tr>");
            doc.append("<td>"+ name +"</td>");
            doc.append("<td>"+ score +"</td>");
            doc.append("<td>"+ grade.value() +"</td>");
            doc.append("</tr>");
        }
     
        public static void error(StringBuilder doc, String name, String msg, Throwable t){
            doc.append("<tr>");
            doc.append("<td>"+ name +"</td>");
            doc.append("<td colspan=2>"+ msg + " " + t +"</td>");
            doc.append("</tr>");
        }
    }
    

The above example includes a Oracle Business Rules Decision Point, that uses an MDS repository to access the dictionary. For more information, see What You Need to Know About Using Decision Point in a Production Environment.

When you add the Servlet as shown in the grades application example, note the following:

  • In the init() method the servlet uses the Rules SDK Decision Point API for Oracle Business Rules. For more information on using the Decision Point API, see Working with Rules in Standalone (Non SOA/BPM) Scenarios.

  • The DecisionPointBuilder() requires arguments including a decision function name and, in a production environment a dictionary FQN to access a dictionary in an MDS repository, as shown:

                m_decisionPoint = new DecisionPointBuilder()
                                    .with(DF_NAME)
                                    .with(DICT_FQN)
    

    For more information on using the Decision Point API, see Working with Rules in Standalone (Non SOA/BPM) Scenarios.

9.5 Adding an HTML Test Page for Grades Sample Application

Add an HTML test page for the grades application by following the steps below.

The Grades sample application includes an HTML test page that you use to invoke the servlet you created in Adding a Servlet with Rules SDK Calls for Grades Sample Application.

To add an HTML page to the servlet you use the Create HTML File wizard.

To add an HTML test page:

  1. In the Application Navigator, in the Grades project select the Web Content folder.
  2. Right-click the Web Content folder project and in the context menu select New....
  3. In the New Gallery, select the All Technologies tab.
  4. In the New Gallery, in the Categories area expand Web Tier and select HTML.
  5. In the New Gallery, in the Items area select HTML Page. Click OK.

    Oracle JDeveloper displays the Create HTML File dialog.

  6. Configure this dialog as follows and as shown in Figure 9-16:
    • File Name: index.html

    • Directory: C:\JDeveloper\mywork\GradeApp\Grades\public_html

    Figure 9-16 Create HTML File Dialog

    Description of Figure 9-16 follows
    Description of "Figure 9-16 Create HTML File Dialog"

    Click OK.

    JDeveloper adds index.html to the Web Content folder and opens the editor.

  7. In the editor for index.html, select the Source tab.
  8. Copy and paste the HTML code from the HTML test page example below to replace the contents of the index.html file. Note that in the form element action attribute uses the URL Pattern you specified in Figure 9-14.
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"></meta>
        <title>Test Grade Example Servlet</title>
      </head>
      <body>
        <form name="names_and_scores" 
              method="post" 
              action="/grades/gradesservlet" >
              <p>Name: <input type="text" name="name" /></p>
              <p>Test Score: <input type="text" name="testScore"/></p>
           <input type="submit" value="Submit">
        </form>
      </body>
    </html>
    
  9. Select Save All from the File main menu to save your work.

9.6 Preparing the Grades Sample Application for Deployment

Business rules are deployed as part of the application for which you create a deployment profile in Oracle JDeveloper.

You deploy the application to Oracle WebLogic Server.

9.6.1 How to Create the WAR File for the Grades Sample Application

You deploy the GradeApp sample application using JDeveloper with Oracle WebLogic Server.

To create the WAR file for the grades sample application:

  1. In the Application Navigator, select the Grades project.

  2. Right-click the Grades project and in the context menu select Project Properties.... This displays the Project Properties dialog for the project.

  3. In the Project Properties navigator, select the Deployment item as shown in Figure 9-17.

    Figure 9-17 Project Properties - Deployment

    Description of Figure 9-17 follows
    Description of "Figure 9-17 Project Properties - Deployment"
  4. In the Project Properties dialog, click New....

    This displays the Create Deployment Profile dialog.

  5. In the Create Deployment Profile dialog, in the Archive Type list, select WAR File.

  6. In the Create Deployment Profile dialog, in the Name field enter grades, as shown in Figure 9-18. Note the Name value uses the package value that you specified in the form element action attribute in step 8 of Adding an HTML Test Page for Grades Sample Application.

    Figure 9-18 Create Deployment Profile Dialog for WAR File

    Description of Figure 9-18 follows
    Description of "Figure 9-18 Create Deployment Profile Dialog for WAR File"
  7. Click OK.

    This displays the Edit WAR Deployment Profile Properties dialog.

  8. In the Edit War Deployment Profile Properties dialog, select General and configure the General page as follows, as shown in Figure 9-19:

    1. Set the WAR File: C:\JDeveloper\mywork\GradeApp\Grades\deploy\grades.war

    2. In the Web Application Context Root area, select Specify Java EE Web Context Root:

    3. In the Specify Java EE Web Context Root: text entry area, enter grades.

    4. In the Deployment Client Maximum Heap Size (in Megabytes): list select Auto

    Figure 9-19 Edit WAR Deployment Properties - General

    Description of Figure 9-19 follows
    Description of "Figure 9-19 Edit WAR Deployment Properties - General"
  9. In the Edit WAR Deployment Profile Properties dialog, click OK.

    JDeveloper creates a deployment profile named grades (WAR File) as shown in Figure 9-20.

    Figure 9-20 Project Properties - Deployment Profile Created

    Description of Figure 9-20 follows
    Description of "Figure 9-20 Project Properties - Deployment Profile Created"
  10. In the Project Properties dialog, click OK.

9.6.2 How to Add the Rules Library to the Grades Sample Application

To add the rules library to the weblogic-application file:

  1. In the GradeApp application, in the Application Navigator expand Application Resources.
  2. Expand Descriptors and expand META-INF and double-click to open weblogic-application.xml.
  3. Add the oracle.rules library reference to the weblogic-application.xml file. Add the following lines, as shown in Figure 9-21.
    <library-ref>
        <library-name>oracle.rules</library-name>
    </library-ref>
    

    Figure 9-21 Adding Oracle Rules Library Reference to WebLogic Descriptor

    Description of Figure 9-21 follows
    Description of "Figure 9-21 Adding Oracle Rules Library Reference to WebLogic Descriptor"
  4. Save the weblogic-application.xml file.

9.6.3 How to Add the MDS Deployment File to the Grades Sample Application

To add the MDS deployment file:

  1. In the Application Navigator, select the GradeApp application.
  2. Right-click the GradeApp application and in the context menu select Application Properties....

    This displays the Application Properties dialog.

  3. In the Application Properties navigator select the Deployment item, as shown in Figure 9-22.

    Figure 9-22 Application Properties - Deployment

    Description of Figure 9-22 follows
    Description of "Figure 9-22 Application Properties - Deployment"
  4. In the Application Properties dialog, click New....

    This displays the Create Deployment Profile dialog.

  5. Configure this dialog as follows, as shown in Figure 9-23:
    • Archive Type: MAR File

    • Name: metadata1

    Figure 9-23 Create Deployment Profile Dialog for MAR File

    Description of Figure 9-23 follows
    Description of "Figure 9-23 Create Deployment Profile Dialog for MAR File"

    Click OK.

    This displays the Edit MAR Deployment Properties dialog as shown in Figure 9-24.

    Figure 9-24 Edit MAR Deployment Profile Properties - MAR Options

    Description of Figure 9-24 follows
    Description of "Figure 9-24 Edit MAR Deployment Profile Properties - MAR Options"
  6. Expand the Metadata File Groups item and select the User Metadata item and click Add.

    This displays the Add Contributor dialog.

  7. In the Add Contributor dialog, click the Browse button and navigate to the directory for the project that contains the GradingRules.rules dictionary file.

    In this example, navigate to C:\JDeveloper\mywork\GradeApp\Grades and click Select.

  8. In the Add Contributor dialog, click OK to close the dialog. This displays the Edit MAR Deployment Properties dialog as shown in Figure 9-25

    Figure 9-25 Edit MAR Deployment Profile Properties - User Metadata

    Description of Figure 9-25 follows
    Description of "Figure 9-25 Edit MAR Deployment Profile Properties - User Metadata"
  9. In the Edit MAR Deployment Profile Properties dialog, expand the Metadata File Groups and expand the User Metadata item and select Directories.

    This displays the Directories page as shown in Figure 9-26.

    Figure 9-26 Edit MAR Deployment Profile Properties - Directories

    Description of Figure 9-26 follows
    Description of "Figure 9-26 Edit MAR Deployment Profile Properties - Directories"
  10. Select the oracle directory check box. This selects the GradingRules.rules dictionary to be included in the MAR.

    Click OK.

    JDeveloper creates an application deployment profile named metadata1 (MAR File) as shown in Figure 9-27.

    Figure 9-27 Application Properties - Deployment - MAR

    Description of Figure 9-27 follows
    Description of "Figure 9-27 Application Properties - Deployment - MAR"

    Click OK in the Application Properties dialog.

9.6.4 How to Add the EAR File to the Grades Sample Application

Add an EAR file to the Grades sample application.

To add the ear file to the grades sample application:

  1. In the Application Navigator, select the GradeApp application.
  2. Right-click and in the context menu select Application Properties....
  3. In the Application Properties dialog, select Deployment and click New.... This displays the Create Deployment Profile dialog.
  4. Configure this dialog as follows, as shown in Figure 9-28.
    • Archive Type: EAR

    • Name: grades

    Figure 9-28 Create Deployment Profile Dialog for EAR File

    Description of Figure 9-28 follows
    Description of "Figure 9-28 Create Deployment Profile Dialog for EAR File"
  5. Click OK. This displays the Edit EAR Deployment Profile Properties dialog.
  6. In the Edit Ear Deployment Profile Properties dialog, in the navigator select Application Assembly as shown in Figure 9-29.

    Figure 9-29 Edit EAR Deployment Profile Properties - Application Assembly

    Description of Figure 9-29 follows
    Description of "Figure 9-29 Edit EAR Deployment Profile Properties - Application Assembly"
  7. Configure this dialog as follows:
    • Select the metadata1 check box.

    • Expand the Grades.jpr item and select the grades check box.

  8. In the Edit EAR Deployment Profile Properties dialog, click OK.

    JDeveloper creates an application deployment profile named grades(EAR File) as shown in Figure 9-30.

    Figure 9-30 Application Properties - Deployment - EAR

    Description of Figure 9-30 follows
    Description of "Figure 9-30 Application Properties - Deployment - EAR"
  9. Click OK to close the Application Properties dialog.
  10. Select Save All from the File main menu to save your work.

9.7 Deploying and Running the Grades Sample Application

You can now deploy and run the grades sample application on Oracle WebLogic Server.

9.7.1 How to Deploy to Grades Sample Application

To deploy the grades sample application:

  1. In the Application Navigator, select the GradeApp application.
  2. Right-click the GradeApp application and in the context menu select Deploy > grades > to > and select either an existing connection or New Connection... to create a connection for the deployment. This starts the deployment to the specified Oracle WebLogic Server.
  3. As the deployment proceeds, Oracle JDeveloper shows the Deployment Configuration dialog.
  4. In the Deployment Configuration dialog enter the following values, as shown in Figure 9-28:
    • In the Repository Name field, from the list, select: mds-soa

    • In the Partition Name field, enter grades

    Figure 9-31 Deployment Configuration Dialog for MDS with Repository and Partition

    Description of Figure 9-31 follows
    Description of "Figure 9-31 Deployment Configuration Dialog for MDS with Repository and Partition"
  5. In the Deployment Configuration dialog, click Deploy.

9.7.2 How to Run the Grades Sample Application

After you deploy the grades sample application, you can run the application.

To run the grades sample application:

  1. Point a web browser at,

    http://yourServerName:port/grades/

    This displays the test servlet as shown in Figure 9-32.

    Figure 9-32 Grades Sample Application Servlet

    Description of Figure 9-32 follows
    Description of "Figure 9-32 Grades Sample Application Servlet"
  2. Enter a name and test score and click Submit. This returns results as shown in Figure 9-33.

The first time you run the servlet there may be a delay before any results are returned. The first time the servlet is invoked, during servlet initialization the runtime loads the dictionary and creates a rule session pool. Subsequent invocations do not perform these steps and should run much faster.

Figure 9-33 Grades Sample Application Servlet with Results

Description of Figure 9-33 follows
Description of "Figure 9-33 Grades Sample Application Servlet with Results"