How-to Create and Deploy a Rule Enabled Web Service
First Created: 01-Feb-2006
Last Updated: 01-Feb-2006
Author: Bruce Lowenthal
- Introduction
- Prerequisites
- The Pension Application Web Service
- Discussion of the Web Services Java Source
- Installation and Testing
- Summary
- A. Appendix - Java Source Files
1.0 Introduction
This document describes an example of how to create, deploy and test a Rule
Enabling a J2EE 1.4 (JAX-RPC) Web Service using JDeveloper 10g. This document
provides both a discussion of the Java implementing the Web service and its
client as well as providing a description of the steps needed to deploy such a
Web service using JDeveloper.
Note that deployment of J2EE 1.4 (JAX-RPC) Web services is particularly
tricky and these steps may be helpful for deployment of any Web services
applications. In this document 10.1.3 DP3 OC4J and 10.1.3.0.2.223 JDeveloper
were used and details of deployment will differ in other releases.
2.0 Prerequisites
2.1 What you should know
- How to install 10.1.3.0.0 JDeveloper and OC4J
- How to use JDeveloper 10.1.3.0.0
2.2 What are the Software Requirements?
This demo requires that the following software components are installed and
configured correctly:
- Oracle Application Server 10.1.3.0.0 standalone version or full install
- Oracle JDeveloper 10.1.3.0.0
- Sun's JDK 1.5.1 or above, available from
here
- Any HTML browser like Mozilla, Microsoft Internet Explorer, Netscape, etc.
2.3 What are the Notations?
- %ORACLE_HOME%
- The directory where 10.1.3. Application Server was installed
- %JAVA_HOME%
- The directory where your JDK is installed
- %DEMO_HOME%
- The directory where this demo is unzipped
3.0 The Pension Application Web Service
The pension application example is used in this discussion. The pension
application uses Rules to compute a retiree's pension based on their salary, age
and disability status at retirement. This application is identical to the
application presented in the viewlet: "Rule Enabling a J2EE Application" except
it is implemented using Web services.
The architecture of this application is fairly straightforward. Browser input is
sent to a servlet called Example1.java. There it is processed and used to
populate Java objects. These objects are sent to the pension Web services where
they are processed by Rules that generate the results. These results are
returned to the Example1.java servlet where they are formatted for display by
the browser.
3.1 Pension Application Components
The servlet is straightforward and is implemented by the Example1 class listed
in Appendix A.5. Example1 receives browser input via the doGet method (line 16)
and uses the input to populate the object retiree (lines 38-42). Example 1 then
calls pension Web services (line 43) and then formats the results for browser
display (lines 56-57).
The pension Web services consists of three methods:
- getVersion(): Returns the version of the Web service
- setRules(String): Sets the Rulesets for this Web service allowing the
changing of Rulesets without re-deploying the Web service. In this
application, the Rules are not provided with the initial installation of the
Web services. They must be provided to the Web Services later via this
method.
- assertRun(Retiree) returns Retiree: Computes a pension given the salary,
age and disability status of a retiree at retirement and returns the pension
amount via retirementSalary. Also, the text of any alerts that have been
issued during the processing of the fact is available in Retiree.alerts.
4.0 Discussion of the Web Services Java Source
In this section, each of the four Java source files used to implement the Web
service are discussed in detail. These include source for Retiree,
PensionException, PensionRules and PensionRulesWS. In addition, the source file
that implements the servlet that calls the Web services is also discussed. The
servlet class is Example1.
Listings of all source files are available in Appendix A below.
4.1 Retiree.java
Retiree.java implements the class (Java bean) that is the Fact type analyzed by
the Rules. Objects of this class are passed to the Web service where they are
provided directly to Rules for analysis and update. Objects of this class are
also returned back the Web service client application as the result of the Rules
analysis.
As can be seen, there is nothing special about this bean. The fields are:
- baseSalary, disabledAtRetirement and retirementAge: These are fields
used as input to the rules engine.
- retirementSalary: returns the results of the Rules analysis
- alerts: returns the text of any alerts generated during the Rules
analysis.
Note that the method alert is called by Rules to issue an alert.
The J2EE 1.4 Web services standard makes certain restrictions regarding the
types of objects that can be transferred between Web services clients and
servers. Check these restrictions before defining classes such as Retiree that
are passed as parameters or results between Web service clients and servers.
This comment applies to the entire Java source files discussed in this document.
4.2 PensionException.java
This class defines Exceptions that can be returned from the Web Service. In this
class:
- faultActor contains the original Exception class
- faultString contains the stack trace of the original message as a String
- faultLocalized message contains the Rules source that caused the
exception for some RuleSession exceptions
- message contains message of the original fault
There are many restrictions regarding the definition of Web services
Exceptions. See the J2EE 1.4 Web services document for details.
4.3 PensionRules.java
This interface defines the Web service methods available for access.
The format of this interface file is dictated by the J2EE 1.4 Web services
standard. In particular it must extend java.rmi.Remote and its
methods must throw java.rmi.RemoteException.
4.4 PensionRulesWS.java
This class defines the methods that can be called in this Web service.
Generally the source here would differ little from the source if the methods
were directly called rather than accessed via Web services. The main
differences are due to the fact that the called methods are potentially executed
in a different environment than the Web service client. As noted in
the discussion regarding Retiree.java, there are some J2EE Web service
restrictions regarding the types of parameters and results allowed.
4.4.1 init (Object) return void
init is called by the Web services infrastructure to provide information
about the local environment. In this case, the path to the local Web Files area
is saved. This path is used later for saving and restoring Rules.
4.4.2 getVersion() return String
getVersion() only returns a version string. It is included to show the
simplest Web service method.
4.4.2 setRules(String) return void
setRules(String) provides the Web service with the Rules to be used by
RuleSession. Providing the Rules in this way allows one to change the Rules
without redeploying the application. Note that the Rules are saved in line 74 of
the source file in Appendix A.4. They are retrieved in lines 48 and 49 in the
same source file.
[48] caSize = isr.read(ca);
[49] rules = String.copyValueOf(ca, 0, caSize);
[50] rs = new RuleSession();
[51] rs.executeRuleset(rules);
[73] byte[] rulesWS = rules.getBytes();
[74] fos.write(rulesWS);
[75] fos.close();
Note that the Rules repository could have been deployed with the Web service. If
this were done, then the entire Web service would have to be redeployed when the
Rules were changed assuming no direct access to the Web services internal file
structure. If deployment of Web services with Rules repositories is desired then
instructions in section
4.8 below would be changed to include the Rules repository (updating the Web
Files Filters) and the code in lines 48 and 49 of Appendix A.4 would be changed
to look something like the code around lines 36-43 of Appendix A5.
[36] RuleRepository repo =
RepositoryManager.createRuleRepositoryInstance(
[37] RepositoryManager.getRegisteredRepositoryType(
"oracle.rules.sdk.store.jar"));
[38] RepositoryContext jarCtx = new RepositoryContext();
[39] jarCtx.setProperty(Constants.I_PATH_BASE, contextDir + "/fileRepository");
[40] repo.init( jarCtx );
[41] rules = repo.loadDictionary("rulesDictionary",
"production").ruleSetRL("main");
[42] repo.close();
[43] myPort.setRules(rules);
4.4.3 assertRun(Retiree) return Retiree
This method asserts the Retiree fact to the Rules engine; causes the Rules
engine to run and returns the updated Retiree Fact as the result. If alerts are
to be issued they update the alerts field in Retiree.
Note that the code in lines 42 to 52 of Appendix A.4 will load the RuleSession
with the Rules provided and saved via the setRules(String) method.
[46] FileInputStream fis = new FileInputStream(rFile);
[47] InputStreamReader isr = new InputStreamReader(fis);
[48] caSize = isr.read(ca);
[49] rules = String.copyValueOf(ca, 0, caSize);
[50] rs = new RuleSession();
[51] rs.executeRuleset(rules);
The important statements in this method are 53, 54 and 61 where the Rules
engine is called and the results returned.
[53] rs.callFunctionWithArgument("assert", retiree);
[54] rs.callFunction("run");
[61] return retiree;
4.5 Example1.java
Example1.java handles the input from the Browser, calls the Web services and
returns the result to the browser. Note also that the code is nearly identical
to the code that would be written if the Rules processing were not written as a
Web service.
In Example1.java, line 31 instantiates the object myPort, of type
Example1PortClient. is used to call Web services. Example1PortClient
was created by the JDeveloper Web service infrastructure when the stubs were
generated (Section 4.11). In the code, lines 46-50 set up the Retiree fact later
to be asserted to the Rules engine. Line 43 calls the Web service with the
object retiree and is returned an updated Retiree object. Lines 65-66
display the results from the returned Retiree object.
[31] Example1SoapHttpPortClient
myPort = new Example1SoapHttpPortClient();
[46] retiree.baseSalary = Integer.parseInt(request.getParameter("baseSalary"));
[47] retiree.retirementAge =
Integer.parseInt(request.getParameter("retirementAge"));
[48] retiree.disabledAtRetirement =
[49] request.getParameter("disabledAtRetirement").equals("true");
[50] retiree = myPort.assertRun(retiree);
[65] out.println(retiree.alerts + "<br>Base salary: " + (int)retiree.baseSalary
+ "<p>" +
[66] "Pension is: " + (int)retiree.retirementSalary +
"<p><hr></body></html>");
4.6 Rules Repository Files
The Rules Repository Files will not be discussed. For a discussion of Rules
creation and modification see the viewlet: "Rule Enabling a J2EE Application".
Also, a discussion of the HTML Test Page will not be discussed here although it
will be referenced later in this discussion.
5.0 Installation and Testing
In this section the steps in installation and initial testing of the Rule
Enabled Web service are discussed using source files and a rule repository that
accompany this note. Each sub section in this section provides a step in the
installation and testing of this Rule enabled Web service. Instructions in this
section assumes:
- Installation will be on a Windows platform. Note: Installation and
testing on Linux or Unix platforms is very similar.
- Use of JDeveloper 10.1.3.0.0. JDeveloper should be
configured to generate the IP address 127.0.0.1 for the local
address. This is done by:
- Tools >> Embedded OC4J Server Preferences
- Startup under Global
- Select the radio button: Specify Host Name: and enter
127.0.0.1 in the adjacent field.
- Use of an installed 10.1.3.0.0 Oracle OC4J application server on
the same machine. Note that deployment instructions for other versions of
these products are likely to differ.
5.1 Create an application workspace
In JDeveloper, create the workspace RuleExamples with the directory
c:\rules\examples.
If the directory c:\rules\examples is not used, make corresponding changes to
the instructions below. It should be noted that these instructions should be
followed EXACTLY with particular care regarding the upper/lower casing of the
text.
5.2 Create a new project
Create the project example1 as an empty project with the directory
c:\rules\examples\example1. Instructions:
- Right clicking on the RuleExamples icon
- Selecting New Project…
- Selecting Projects under General
- Selecting Empty Project under Items; select OK
- In the popup set Project Name to example1; select OK
DO NOT click on the + sign next to the example1 item under RuleExamples until
after the files are copied in the next section.
5.3 Copy Example1 Source Files
There are a number of files that were distributed with this note in its
example1 folder. Copy the directories public_html and src and
their contents into the example1 directory created by the operations of
the prior step. Copied files should include:
- public_html\index.html
- public_html\fileRepository
- public_html\WEB-INF\web.xml
-
src\example1\client\Example1.java
-
src\example1\server\PensionException.java
-
src\example1\server\PensionRules.java
-
src\example1\server\PensionRulesWS.java
-
src\example1\server\Retiree.java
5.4 Set Project Properties
Right click the project icon (example1) and select Project Properties.
- Select Technology Scope to include Java, HTML, JSP and Servlets
and Web Services
- Select J2EE Application and change only J2EE Web Application
Name to example1
- Select Run/Debug. Under Run Configurations select
default. Select Edit.
- In the popup, uncheck the Attempt to Run Active File Before Default
box and browse the Default Run Target to select the file:
\rules\examples\example1\public_html\index.html
- Select OK to return to Project Properties window
- Select
Libraries and:
- Select Add Library adding JAX-RPC Client
- Select Add Library adding Servlet Runtime
- Select Add Jar adding the jar file rl.jar and rulesdk.jar
from the lib directory in the rules directory of a 10.1.3.0.0
Application Server installation.
- Select OK
5.5 Compile Copied Files
Right click the icon labeled example1 under RuleExamples then
select Rebuild. No errors should be detected.
5.6 Create Web Service
Create the Web service in the following way:
- Right click the icon labeled example1
- Select New
- Select Web Services under Business Tier
- Select Java Web Services under Items
- Select the OK button.
- In the resulting popup, select the J2EE 1.4 (JAX-RPC) Web Service
radio button and select the OK button.
- In the resulting popup set the Component to Publish dropdown to
example1.server.PensionRulesWS
- Set Web Service Name to Example1
- Service Endpoint Interface should be example.server.Example1
-
SOAP 1.1 Binding should be checked.
- Select the next button.
- Select the next button on the Web Service Message Format page.
-
Select the next button on the custom datatype serializers page
-
Select the next button on the mapping page. This should take
some time as the methods are evaluated.
- On the Methods page, check the
boxes next to assertRun, getVersion and setRules.
Do not check the box next to destroy()
- Select the Finish
button. JDeveloper may process this for a number of seconds.
- if successful, the web services log should show:
- Generating WSDL and mapping file
- Generating deployment descriptors
- Generation finished
- Adding service files to deployment profile
5.7 Edit the WSDL
If JDeveloper was configured to use 127.0.0.1 in step 5.0, this step
can be skipped.
The web services address may have to be edited. Assuming that the
Web Services are deployed in a local OC4J, the IP address used should be
localhost or the 127.0.0.1 variant of localhost. To do ensure this:
- Select Example1\wsdl under WEB-INF.wsdl for editing if it
is not already in the edit window.
- Under Services, expand Example1, expand
Example1SoapHttpPort and select soap:address
- In the right pane, the IP address may be edited to 127.0.0.1
- Save the WSDL
5.8 Fix Deployment Filter
The deployment filter may need to be modified.
- Right click WebServices.deploy under Resources under
example1 in
JDeveloper.
- Select Properties…
- Select Filters under Web-INF/classes under File Groups
- Select the + sign next to server and check any unchecked
boxes.
- Select the OK button.
- Note: This step may not be needed in future versions of JDeveloper.
5.9 Make sure local OC4J is running and has a connection
Make sure that a local version of OC4J is running and that an Application
Server Connection in JDeveloper has be set up which references the local,
running OC4J. Application Server connections are set under the Connections
JDeveloper tab. Directions for installing OC4J or setting up JDeveloper
connections are not included in this note.
5.10 Deploy to local OC4J
Under Resources under example1, right click on WebServices.deploy and deploy
to the local OC4J via the local OC4J connection; for all pop-ups, click OK
or Yes. The JDeveloper deployment log should indicate that deployment
was successful. The final line of the deployment log should be something like:
----Deployment finished.
----May 22, 2005 3:31:51 PM
5.11 Create Web Service Stubs
There should be an entry Example1 under example1.server under
Application Sources under example1. Right click Example1
and select Generate Web Service Proxy…
- This should take a number of seconds and will generate a number of
files.
- When the Shared Service Endpoint Interface box appears, select
Yes
- When the Port Endpoints box appears select Run against a
service deployed to an external service.
- Select OK
- This should take some time. When complete select the Web
Services tab at the bottom of JDeveloper's window.
- The Web Services log in JDeveloper should have entries:
● Generating
proxy
● A possible warning regarding getter and setter methods
● Proxy
generation finished
5.12 Modify the Client Servlet
Select Example1.java for editing under example1.client under
Application Sources under example1. At around line 23 in the doGet
method there is a line consisting of the following: "/**". Replace that
"/**" by "//**".
Note: This change turns a comment into source code for compilation. If this
change were made in an earlier step then syntax errors would have been generated
and the step would have been unsuccessful.
5.13 Initial Test
Left click the compile and run icon in JDeveloper (right pointing green
triangle).
- After a number of seconds, possibly a minute or so, the Example1 HTML
page should be displayed in a browser.
- If not, a Gateway Timeout may occur (depending on configuration).
In that case,
- Modify the IP address in the url to 127.0.0.1 keeping the same port
number.
- Then resubmit with the new URL.Select Submit (without entering or
changing any fields
- If the following is displayed then the servlet and the Web service have
been deployed properly:
- Version 0.9
- Exception: Base Salary and Retirement Age must be valid integers.
- Base Salary: 0
- Pension: 0
5.14 Validate Exception Handling
Select the back arrow/button in the browser and enter 20000 in the Base
Salary box and 65 in the Retirement age box then Select Submit. If the servlet
and the Web service are properly installed then the following should be
displayed:
- Version 0.9
- WS Exception: java.io.FileNotFoundException:, more stack trace, etc
OR
- WS Exception: example1.server.PensionException
Note: The exception may not occur if deployment is on top of a previously
deployed application. In that case, the output should look like the next step
without the line staring with "Reset Rules".
5.15 Install Rules and Test the Application
Select the back arrow/button in the browser and check the Reset Rules
checkbox. Then select Submit. Something like the following should be displayed:
5.16 Further Testing
Select the back arrow/button in the browser and uncheck the Reset Rules
checkbox. Set Retirement age to 64 and select Submit. Something like the
following should be displayed:
- Version 0.9
- Alert: Partial pension paid (age=64)
- Base Salary: 20000
- Pension: 16000
This concludes the installation and testing of rule enabling a Web Service.
To change the rules, edit the Rule Dictionary at
/rules/examples/example1/public_html, save the changes and check the checkbox
Reset Rules to load the updated rules. In this document, the creation and
modification of Rules will not be discussed. Rule creation and modification is
discussed in the viewlet: "Rule Enabling a J2EE application".
6.0 Summary
Following this document, you should be able to create and install an Oracle
Business Rules enabled web service.
A. Appendix - Java Source Files
This appendix provides a listing of the source files used in this document.
A.1 Retiree.java Source
[01] package example1.server;
[02]
[03] public class Retiree {
[04] public double baseSalary = 0;
[05] public int retirementAge = 0;
[06] public boolean disabledAtRetirement = false;
[07] public double retirementSalary = 0;
[08] public String alerts = "";
[09]
[10] public void alert(String text, int age) {
[11] alerts = alerts + "<b>Alert: " + text + " (age=" + age + ")</b><p>";
[12] }
[13]
[14] public double getBaseSalary() {
[15] return baseSalary;
[16] }
[17]
[18] public int getRetirementAge() {
[19] return retirementAge;
[20] }
[21]
[22] public boolean getDisabledAtRetirement() {
[23] return disabledAtRetirement;
[24] }
[25]
[26] public void setRetirementSalary(double retirementSalary) {
[27] this.retirementSalary = retirementSalary;
[28] }
[29]
[30] public String getAlerts() {
[31] return alerts;
[32] }
[33]
[34] public Retiree() {
[35] }
[36]
[37] }
A.2 PensionException Source
[01] package example1.server;
[02]
[03] import java.io.Serializable;
[04]
[05]
[06] public class PensionException extends Exception implements Serializable {
[07]
[08] private java.lang.String faultActor;
[09] private java.lang.String faultString;
[10] private java.lang.String localizedMessage;
[11] private java.lang.String message;
[12]
[13]
[14] public PensionException(String faultActor, String faultString,
[15] String localizedMessage, String message) {
[16] this.faultActor = faultActor;
[17] this.faultString = faultString;
[18] this.localizedMessage = localizedMessage;
[19] this.message = message;
[20] }
[21]
[22] public java.lang.String getFaultActor() {
[23] return faultActor;
[24] }
[25]
[26] public void setFaultActor(String faultActor) {
[27] this.faultActor = faultActor;
[28] }
[29]
[30] public java.lang.String getFaultString() {
[31] return faultString;
[32] }
[33]
[34] public void setFaultString(String faultString) {
[35] this.faultString = faultString;
[36] }
[37]
[38] public java.lang.String getLocalizedMessage() {
[39] return localizedMessage;
[40] }
[41]
[42] public void setLocalizedMessage(String localizedMessage) {
[43] this.localizedMessage = localizedMessage;
[44] }
[45]
[46] public java.lang.String getMessage() {
[47] return message;
[48] }
[49]
[50] public void setMessage(String message) {
[51] this.message = message;
[52] }
[53]
[54] public PensionException() {
[55] }
[56]
[57] }
A.3 PensionRules Source
[1] package example1.server;
[2] import java.rmi.RemoteException;
[3]
[4] public interface PensionRules extends java.rmi.Remote {
[5] public java.lang.String getVersion() throws
java.rmi.RemoteException;
[6] public Retiree assertRun(Retiree retiree)
[7] throws RemoteException,
PensionException;
[8] public void setRules(String rules) throws RemoteException,
PensionException;
[9] }
A.4 PensionRulesWS Source
[01] package example1.server;
[02] import java.io.ByteArrayOutputStream;
[03] import java.io.File;
[04] import java.io.FileInputStream;
[05] import java.io.FileOutputStream;
[06] import java.io.InputStreamReader;
[07] import java.io.PrintStream;
[08] import javax.xml.rpc.server.ServiceLifecycle;
[09] import javax.xml.rpc.ServiceException;
[10] import java.rmi.RemoteException;
[11] import oracle.j2ee.ws.server.ServletEndpointContextImpl;
[12] import oracle.rules.rl.RuleSession;
[13]
[14] public class PensionRulesWS implements ServiceLifecycle, PensionRules
[15] {
[16] public static final String RULES_LOC = "rulesWS.txt";
[17] String initClass = null;
[18] ServletEndpointContextImpl eci = null;
[19] String path = null;
[20] RuleSession rs = null;
[21]
[22] public void init(Object p0) throws ServiceException
[23] {
[24] eci = (ServletEndpointContextImpl)p0;
[25] path = eci.getServletContext().getRealPath("/");
[26] initClass = path;
[27] }
[28]
[29] public void destroy()
[30] {
[31] // Some logic to do on service destruction
[32] }
[33]
[34] public String getVersion() throws RemoteException
[35] {
[36] return "0.9";
[37] }
[38]
[39] public Retiree assertRun(Retiree retiree) throws PensionException {
[40] String rules = "";
[41] try {
[42] if (rs == null) {
[43] int caSize = 0;
[44] File rFile = new File(path
+ RULES_LOC);
[45] char[] ca = new
char[(int)rFile.length()];
[46] FileInputStream fis = new
FileInputStream(rFile);
[47] InputStreamReader isr =
new InputStreamReader(fis);
[48] caSize = isr.read(ca);
[49] rules =
String.copyValueOf(ca, 0, caSize);
[50] rs = new RuleSession();
[51] rs.executeRuleset(rules);
[52] }
[53] rs.callFunctionWithArgument("assert", retiree);
[54] rs.callFunction("run");
[55] } catch (Exception e) {
[56] ByteArrayOutputStream os = new
ByteArrayOutputStream();
[57] e.printStackTrace(new
PrintStream(os));
[58] throw new
PensionException(e.getClass().getName(), os.toString(),
[59] "Rules:
<br>>" + rules.replaceAll("\n", "<br>>"), e.getMessage());
[60] }
[61] return retiree;
[62] }
[63]
[64] public void setRules(String rules) throws PensionException {
[65] try {
[66] File rFile = new File(path +
RULES_LOC);
[67] rs = null;
[68] if (rules == null) {
[69]
rFile.delete();
[70] return;
[71] }
[72] FileOutputStream fos = new
FileOutputStream(rFile);
[73] byte[] rulesWS = rules.getBytes();
[74] fos.write(rulesWS);
[75] fos.close();
[76] } catch (Exception e) {
[77] ByteArrayOutputStream os =
new ByteArrayOutputStream();
[78] e.printStackTrace(new
PrintStream(os));
[79] throw new
PensionException(e.getClass().getName(), os.toString(),
[80]
e.getLocalizedMessage(), e.getMessage());
[81] }
[82]
[83] }
[84]
[85] }
A.5 Example1.java Source
[01] package example1.client;
[02]
[03] import example1.server.*;
[04] import java.io.*;
[05] import javax.servlet.*;
[06] import javax.servlet.http.*;
[07]
[08] import oracle.rules.rl.RuleSession;
[09] import oracle.rules.sdk.dictionary.RuleDictionary;
[10] import oracle.rules.sdk.repository.*;
[11] import oracle.rules.sdk.store.jar.Constants;
[12]
[13] public class Example1 extends HttpServlet {
[14] private String contextDir = null;
[15]
[16] public void init(ServletConfig config) throws ServletException {
[17] super.init(config);
[18] contextDir = (config.getServletContext()).getRealPath("/");
[19] }
[20]
[21] public void doGet(HttpServletRequest request, HttpServletResponse
response)
[22] throws ServletException, IOException {
[23] /**
[24] response.setContentType("text/html; charset=windows-1252");
[25] PrintWriter out = response.getWriter();
[26] String rules = null;
[27] Retiree retiree = new Retiree();
[28] boolean resetRules =
"ON".equals(request.getParameter("resetRules"));
[29]
out.println("<html><head><title>Example1</title></head><body>");
[30] try {
[31] Example1SoapHttpPortClient myPort =
new Example1SoapHttpPortClient();
[32]
[33]
out.println("<h2><center>Example1</center></h2>Version "
[34] +
myPort.getVersion() + "<p>");
[35] if (resetRules) {
[36] RuleRepository
repo = RepositoryManager.createRuleRepositoryInstance(
[37]
RepositoryManager.getRegisteredRepositoryType("oracle.rules.sdk.store.jar"));
[38]
RepositoryContext jarCtx = new RepositoryContext();
[39]
jarCtx.setProperty(Constants.I_PATH_BASE, contextDir + "/fileRepository");
[40] repo.init(
jarCtx );
[41] rules =
repo.loadDictionary("rulesDictionary", "production").ruleSetRL("main");
[42] repo.close();
[43]
myPort.setRules(rules);
[44]
out.println("Reset Rules: " + contextDir + "ruleDictionary1<p>");
[45] }
[46] retiree.baseSalary =
Integer.parseInt(request.getParameter("baseSalary"));
[47] retiree.retirementAge =
Integer.parseInt(request.getParameter("retirementAge"));
[48] retiree.disabledAtRetirement =
[49]
request.getParameter("disabledAtRetirement").equals("true");
[50] retiree = myPort.assertRun(retiree);
[51] } catch (PensionException pe) {
[52] if (pe.getFaultString() == null)
[53]
out.println("WS Exception: " + pe.getClass().getName() + "<br>");
[54] else
[55]
out.println("WS Exception: " + pe.getFaultString() + "<br>"
[56]
+ pe.getFaultActor() + "<br>" + pe.getLocalizedMessage() + "<br>");
[57] } catch (NumberFormatException nfe) {
[58] out.println("Exception: Base Salary
and Retirment Age must be valid integers.<br>");
[59] } catch (Exception e) {
[60] out.println("Exception: " +
e.getClass().getName() + "<br>");
[61] ByteArrayOutputStream baos = new
ByteArrayOutputStream();
[62] e.printStackTrace(new
PrintStream(baos));
[63]
out.println(baos.toString().replaceAll("\n","<br>"));
[64] }
[65] out.println(retiree.alerts + "<br>Base salary: " +
(int)retiree.baseSalary + "<p>" +
[66] "Pension is: "
+ (int)retiree.retirementSalary + "<p><hr></body></html>");
[67] out.close();
[68] //**/
[69] }
[70] }