Sie sind auf Seite 1von 42

Building JSR 94 Services

PegaRULES Process Commander 5.2

Copyright 2006
Pegasystems Inc., Cambridge, MA
All rights reserved.
This document and the software describe products and services of Pegasystems Inc. It
may contain trade secrets and proprietary information. This information should not be
disclosed to third parties unless otherwise provided for by a contract or business
agreement with Pegasystems. This document and the software are protected by federal
copyright law, international laws, and/or applicable treaties.
This document is current as of the date of publication only. Changes in the document
may be made from time to time at the discretion of Pegasystems. This document remains
the property of Pegasystems and must be returned to it upon request. This document does
not imply any commitment to offer or deliver the products or services provided.
This document may include references to Pegasystems product features that have not
been licensed by your company. If you have questions about whether a particular
capability is included in your installation, please consult your Pegasystems service
consultant.
For Pegasystems trademarks and registered trademarks, all rights are reserved. Other
brand or product names are trademarks of their respective holders.
Although Pegasystems Inc. strives for accuracy in its publications, any publication may
contain inaccuracies or typographical errors. This document could contain technical
inaccuracies or typographical errors. Changes are periodically added to the information
herein. Pegasystems Inc. may make improvements and/or changes in the information
described herein at any time.

This document is the property of:


Pegasystems Inc.
101 Main Street
Cambridge, MA 02142-1590
(617) 374-9600, fax: (617) 374-9620
www.pega.com
PegaRULES Process Commander
Document: Building JSR 94 Services
Software Version: 5.2
Posting Date: December 2006

Contents
About this Document ...............................................................................................2
Introduction...............................................................................................................3
Key Terms and Concepts ...................................................................................3
The Process .......................................................................................................4
About the JSR 94 Service Sample .....................................................................6
Summary of Steps for Building JSR 94 Services................................................8
About the JSR 94 Service ........................................................................................9
Rules and Data Objects for JSR 94 Services.....................................................9
Session State ...................................................................................................10
Authentication...................................................................................................10
Data Mapping for JSR 94 Services...................................................................11
Result Filter ......................................................................................................13
TCK and Compliance........................................................................................13
Creating a JSR 94 Service .....................................................................................14
Plan the JSR 94 Service...................................................................................14
(Optional) Create the Data Model of the Incoming Java Object .......................15
Create or Identify the Class Rule and Properties .............................................16
Create or Identify the Service Activities............................................................16
Create the Service Package and Service Rules...............................................20
Build the JSR 94 Client.....................................................................................26
Run the Client and Test the Service.................................................................29
Running the Sample...............................................................................................30
PegaRULES Setup...........................................................................................30
Client Application Setup ...................................................................................31
Run the PegaClaimSample Client Application .................................................35
Troubleshooting .....................................................................................................36
Examining Log Files .........................................................................................37
The System Pulse and JSR 94 Services...............................................................39

Building JSR 94 Services

A PegaRULES Process Commander service is a set of rules and data objects that define
and implement an interface between an external application that acts as the client and a
Process Commander application that acts as the server. You use services to enable an
external system to access Process Commander or PegaRULES data and processing.
Java Specification Request 94 (JSR 94) describes a Java Application Programming
Interface (API) for rule engines defined by the Java Community Process (JCP).
PegaRULES JSR 94 services receive and respond to requests from external
applications through JSR 94 invocations.
PegaRULES implements all the Java interfaces described in the JSR 94. An external JSR
94 client application accesses the rules in the PegaRULES database by starting and then
communicating directly with an embedded PegaRULES engine through the JSR 94
interface, and not with the Process Commander Web application.
`This document contains the following sections:

About this Document

Introduction

About the JSR 94 Service

Creating a JSR 94 Service

Running the Sample

Troubleshooting

Building JSR-94 Services

About this Document


Building JSR 94 Services is part of a package of materials that includes a sample JSR 94
client application and sample JSR 94 service rule. The document and sample are intended
for PegaRULES system architects who are Java programmers and understand the JSR 94
API.
Building JSR 94 Services describes the rules and data objects that construct a JSR 94
service, provides instructions for creating them, and provides information about how
external applications communicate with PegaRULES JSR 94 services. It also explains
how to run the JSR 94 service sample.
It is recommended that you read the PegaRULES Process Commander book Integrating
with External Systems before you continue reading this document. The book was shipped
with your software and is also available on the Integration Services pages of the Pega
Developer Network (PDN).
http://pdn.pega.com/DevNet/PRPCv5/IntegrationServices/intsvcs_Index.asp
Use this document and the sample materials to run the JSR 94 example on your Process
Commander system as a training exercise before implementing your JSR 94 services.

0BBuilding JSR 94 Services 2BIntroduction

Introduction
A service receives input from an external system and can respond in some way. For
example, it can reply with data that was requested, it can use the incoming data to create
a work object and initiate a flow, and so on.
A JSR 94 client starts a new instance of the PegaRULES engine, which then runs in the
same Java Virtual Machine (JVM) as the client. Because the JSR 94 client accesses your
application rules directly through the PegaRULES engine, the application server and the
Process Commander Web application do not need to be running for the JSR 94
communication to take place. If the Web application is online, however, both Process
Commander and the JSR 94 client can share the same PegaRULES database as separate
applications.

Key Terms and Concepts


The following are descriptions of how key terms and concepts from the JSR 94
specification are used in the PegaRULES JSR 94 service.

Rule Execution Set


A JSR 94 rule execution set as described in the JSR 94 specification includes, in
PegaRULES, the following:

One (and only one) service rule of type Rule-Service-JSR94

The service package the service rule belongs to

The service activity the service rule invokes

Any rules the service activity calls or runs: additional activities, declarative rules,
utility functions, and so on

Rules Engine
The rules engine refers to the PegaRULES engine.

Rule Service Provider Class


The JSR 94 rule service provider class from PegaRULES is the following:

com.pega.pegarules.pub.services.jsr94.PRuleServiceProvider

Building JSR-94 Services

Service URI
The Service URI of a PegaRULES JSR 94 service is typically the name of the service
rule, which is defined by a three-part key:

Package name

Service class name

Service method name

For example, the URI of the sample JSR 94 service is the following:

SampleJSR94.ClaimService.ProcessClaim

If the external client application requires that the URIs of the services it calls use some
other naming convention, you can provide a different URI for the service by entering the
value you want to use in the Alternate URI field on the Service tab of the service rule.

The Process
Figure 1 illustrates the architecture of the JSR 94 service.

A Single
JVM

JSR-94 Client
request

response

Data-AdminServicePackage

Rule-Service-JSR94

PegaRULES
Engine

Page
Clipboard
Java
Page

Service Activity

Figure 1. Architecture of a JSR 94 Service

0BBuilding JSR 94 Services 2BIntroduction

The following describes how a JSR 94 service works:


1.

A JSR 94 client uses the RuleServiceProvider class to obtain a reference to the


RuleRuntime interface.

2.

Using the RuleRuntime reference and the URI of the JSR 94 service (either the
Service URI or the alternate URI), the client obtains a RuleSession object, which
can be stateful or stateless.

3.

The client gathers parameters, packages them into a java.util.List object, and sends
it to PegaRULES by executing the RuleSession and providing the object list.

4.

The JSR 94 service maps the incoming list of objects to the clipboard and then
invokes the service activity.

5.

The service activity completes the tasks that it is programmed to do. It sets
properties on the clipboard, processes property values, invokes other activities, and
so on. When the activity completes processing, typically it has changed property
values on the clipboard.

6.

The service activity returns control to the JSR 94 service.

7.

The JSR 94 service invokes the appropriate rules to create a response for the
JSR 94 client.

8.

If an object filter was provided either a default object filter is specified in the
JSR 94 service rule or one was passed in by the client application the JSR 94
integration interface filters the items in the java.util.List object being returned to
the client.

9.

The JSR 94 service returns control to the JSR 94 client. If there are any objects to
return, they are returned in a java.util.List.

10. The JSR 94 client evaluates the response and takes appropriate actions.

Building JSR-94 Services

About the JSR 94 Service Sample


The JSR 94 service sample makes a sample PegaRULES application available to an
external JSR 94 client application. The sample application is a simple automobile
insurance claim application. The JSR 94 service example receives claims from the
external client application. The service uses rules to determine whether to approve or
deny the claims and returns the decisions about the claims to the JSR 94 client. Claim
determinations are calculated from two values: the age of the vehicle and the cost of the
repairs.
The JSR 94 example has three parts:

The PegaRULES AutoClaim application.

The JSR 94 PegaClaimSample client application, which sends claims to the


AutoClaim application.

The PegaRULES JSR 94 service, which makes the AutoClaim application available
to the PegaClaimSample application. The service receives requests from and sends
responses to the PegaClaimSample application.

The Java Classes


The PegaRULES AutoClaim application and the JSR 94 PegaClaimSample client
application are based on the same set of Java source classes:

Claim

Damage

Vehicle

These classes make up an insurance claim object that describes the damage to a
policyholders vehicle. The pegaclaimsampleclient51.zip file contains both the class files
and their Java source files so that you can examine the code.

The PegaRULES AutoClaim Application


The AutoClaim application includes the following rules and Java classes:

Three class rules

Three page models

Twelve property rules

One expression rule

Three Java wrapper classes

0BBuilding JSR 94 Services 2BIntroduction

The class and property rules implement the data model described in the Java classes
Claim, Damage, and Vehicle.
The AutoClaim application was created by using the Import JavaBeans Accelerator to
import the Java class named Claim into the base class rule named SampleJavaBase-. The
Claim class contains a variable that refers to an object of the Damage Java class and a
variable that refers to an object of the Vehicle Java class. Therefore, the accelerator
created a class rule for each of the Java classes and a property rule of mode Java
Property for each of the variables specified in all three Java classes.
After the accelerator created the data model described in the Claim, Damage, and Vehicle
Java classes, an additional property was manually created for the Vehicle class: age. The
value of the age property is calculated with an expression rule (Rule-Obj-Expressions).
Incoming claim objects provide values for the year, make, and model of the vehicle. The
expression rule calculates the age of a vehicle by subtracting the value in the year
property from the value of the current year.
The accelerator also generated three Java classes that implement the PRObjectWrapper
interface of the Clipboard Java API. These Java wrapper classes provide you with a
standard way to access Java objects as clipboard pages from within PegaRULES. The
service activity in the JSR 94 service example uses these wrapper classes to manipulate
the Claim Java objects that the PegaClaimSample client application sends.
For more information about Java properties, Process Commander Java pages, and
generated Java wrapper classes, see Working with the Java Pages Feature, posted on the
Integration pages of the PDN.
For information about the PRObjectWrapper interface, see the PegaRULES Process
Commander Javadocs, located on your installation CD.

JSR 94 PegaClaimSample Application


The JSR 94 PegaClaimSample client application includes the three Java classes that
create a claim object (Claim, Damage, and Vehicle) and a Java class named
SubmitClaim. SubmitClaim obtains claims from the Claim class and sends the claims to
the PegaRULES JSR 94 service for processing.

JSR 94 Service Example


The JSR 94 service example includes a class rule, a service package, a service rule, a
service activity, and a map value rule. The service example is described in detail in
Creating a JSR 94 Service, starting on page 14.

Building JSR-94 Services

Summary of Steps for Building JSR 94 Services


The following list summarizes the general steps for building a JSR 94 service in Process
Commander.
1.

Create the Process Commander properties and Java wrapper classes necessary to
support the processing of the service activity. See Data Mapping for JSR 94
Services on page 11 and Create or Identify the Class Rule and Properties on
page 16.

2.

Create the rules and data objects that make a JSR 94 service, as described in
Creating a JSR 94 Service on page 14.

3.

Create the JSR 94 client that uses the JSR 94 service to communicate with
PegaRULES. Although it is outside the scope of this document to describe how to
develop JSR 94 clients, this document does provide the information a client
application uses to identify and communicate with PegaRULES. See Build the JSR
94 Client on page 26.

0BBuilding JSR 94 Services 3BAbout the JSR 94 Service

About the JSR 94 Service


This section describes the rules and data objects that create a JSR 94 service and provides
information about session state, authentication, data mapping, JSR 94 result filters, and
compliance with the JSR 94 TCK.

Rules and Data Objects for JSR 94 Services


Typically, a JSR 94 service package contains one JSR 94 service rule, although it can
contain more than one. A JSR 94 service rule represents a JSR 94 rule execution set. It
represents a single method or function for an external application to use. The rule
identifies a service activity to run and maps the incoming and outgoing data.
A JSR 94 service requires the standard list of components as described in Integrating
with External Systems, with no additional listeners, servers, or other data objects.
Figure 2 describes the components in a JSR 94 service.

Component

Purpose

Service package
(Data-AdminServicePackage)

Serves as a container for the service rule.

Service rule
(Rule-Service-JSR94)

Receives messages from a JSR 94 client, specifies the


activity that processes the incoming message;
determines how to map the incoming and outgoing
values and how to assemble a response, if one is
necessary.

Service activity
(Rule-Obj-Activity)

As the activity called by the service, manipulates the


values on the clipboard, calls other activities that perform
processing of some other kind, or does what is
necessary to complete the processing for the service.

Class rule and properties for


the service activity
(Rule-Obj-Class)
(Rule-Obj-Property)

Holds the service activity and the properties that the


service activity and service use to temporarily store the
values in the JSR 94 message.

Figure 2. Summary of Components Required for JSR 94 Integration

10

Building JSR-94 Services

Session State
As with all Process Commander services, if the session is stateless, the service package
uses requestor pooling. Additionally, the clipboard is cleared for the requestor when the
service completes its response. Subsequent requests to the same service do not have
access to any previous values.
Requestor pools do not contain authenticated requestors (users). Therefore, if the session
is stateless and the service runs as an authenticated user, requestor pooling is not
available.
The state of a RuleRuntime session (stateless vs. stateful) is specified in two places:

In the PegaRULES service package

In the JSR 94 client application code that obtains a RuleSession object

The session semantics of the JSR 94 client and the service package must match. If they
do not, unexpected results may occur when you test your service because session state for
the service is determined by the service package, not the JSR 94 client:

If the JSR 94 client requests a stateless session but the service package is set to
stateful, the session is stateful and requestor pooling is disabled.

If the JSR 94 client requests a stateful session but the service package is set to
stateless, the session is stateless and the clipboard properties are cleared when the
service completes its processing.

For more information about requestor pooling, see PegaRULES Process Commander
Integrating With External Systems.

Authentication
A JSR 94 service can run as either an authenticated or an unauthenticated user.

Running as an Unauthenticated User


If you configure your JSR 94 service to run as an unauthenticated user, the JSR 94 client
does not provide an operator ID. The rule session is assigned a requestor ID from the
requestor pool created for the service. The access group specified in the service package
is used for rule resolution.

0BBuilding JSR 94 Services 3BAbout the JSR 94 Service

11

Running as an Authenticated User


To have a JSR 94 service run as an authenticated user, complete the following steps:
1.

On the Context tab of the Service Package form, select the Requires Authentication
option.

2.

In the JSR 94 client application, provide the user name and password of the
appropriate PegaRULES operator ID with the request for the RuleSession object.
For example:

// Set session properties


Map props = new HashMap();
props.put("UserName", exampleUser);
props.put("Password", examplePassword);
// Create a stateful rule session
StatefulRuleSession session = (StatefulRuleSession)
rr.createRuleSession(SERVICE_URI, props,
RuleRuntime.STATEFUL_SESSION_TYPE);

Note that the session state of the RuleSession object must match that specified in the
service package.
For more information about building the JSR 94 client, see Build the JSR 94 Client on
page 26.

Data Mapping for JSR 94 Services


Data mapping defines the relationships between field-value pairs in external systems and
property-value pairs on PegaRULES clipboard pages. For information about data
mapping for all service rule types, see Chapter 5 in Integrating with External Systems.
The data in a JSR 94 request or response is a java.util.List. You configure the data
mapping of the incoming and outgoing lists on the data mapping tabs of the service rule:

Use the Request tab to specify how to map the input list to the clipboard (Map To).

Use the Response tab to specify how the service rule constructs the output list to be
sent from PegaRULES to the external application (Map From).

To determine how to configure the data mapping for a JSR 94 service rule, assess the
data that will be transmitted. For example, is the data a list of Java objects that are
instances of JavaBeans? Is the data list of Java objects that are not instances of
JavaBeans? Your assessment reveals how to map the input and output lists.

12

Building JSR-94 Services

List of JavaBeans Instances


When the message contains a list of Java objects that are instances of JavaBeans, you can
use the Process Commander Java pages feature to attach the objects to the clipboard. This
feature is described in Working with the Java Pages Feature, which is posted on the
Integration pages of the PDN.
When the data in the input or output list includes Java objects that are instances of
JavaBeans, assess the elements in the list and consider the following:

If the message contains a homogenous list, you can map the entire object directly to
an embedded page list property whose page class is one that inherits from the
Embed-Java- base class, that is, a Java page.

If the message contains a mixed list, you can map the individual components to
individual Java pages.

If, for some reason, you cannot map the Java object directly to a Java page on the
clipboard, map it to a property of mode Java Object List. Then, configure the service
activity to attach the list to a Java Page with the Embed-Java-.AttachJavaObject
activity.

For more information about how to use the Process Commander Java pages feature with a
JSR 94 service, see Working with the Java Pages Feature. The document describes how
to use the Import JavaBeans Accelerator to create within Process Commander the data
model of the java.util.List objects delivered by the JSR 94 client application. It also
describes how to use the Embed-Java-.AttachJavaObject activity to attach the
java.util.List objects to the clipboard.

Note: Even though the request and response messages in the JSR 94 sample could
be mapped directly to and from an embedded Page List property, the messages are
mapped to and from a Java Object List property in order to illustrate how to use the
AttachJavaObject activity in a service activity.

Other Java Objects


If the Java object to be passed to and/or from the JSR 94 service is not an instance of a
JavaBean, you cannot use the Java pages feature to manage its data mapping. In such a
case, you configure the service to map the object to a property of type Java Object, Java
Object List, or Java Object Group, as appropriate. Then you use Java steps in the service
activity to map the data from the object to and from the clipboard.

0BBuilding JSR 94 Services 3BAbout the JSR 94 Service

13

Result Filter
A JSR 94 object filter constrains the result set returned by the service activity based on
some set of criteria. To use an object filter with your JSR 94 interface, complete the
following steps:
1.

Code a Java class that implements javax.rules.ObjectFilter and that specifies how to
limit the results from a call to the JSR 94 service.

2.

Put the object filter Java class in the PegaRULES Process Commander class paths.
For information about putting Java classes in the class paths, go to the PDN
(http://pdn.pega.com) and locate the article PRKB-20931 About the Process
Commander Class Paths. Follow the instructions in the section Adding ThirdParty jar Files and Java Class Files to the Class Paths.

3.

Identify the object filter in one of the following ways:

The client application can pass in the fully qualified name of an ObjectFilter Java
class when it calls the JSR 94 service rule with the StatefulRuleSession.getObjects or
the StatelessRuleSession.executeRules methods.
Specify it in the service rule. Enter its fully qualified name in the Result Filter field
on the Response tab of the JSR 94 service rule. In this case, the filter is used to limit
the results every time the service rule is invoked, unless an ObjectFilter is passed in
by the client application, which would override it.

TCK and Compliance


As directed by the JSR 94 specification, PegaRULES Process Commander provides a
tck.conf file and two tck_res.xml files that you can use with the JSR 94 Technology
Compatibility Kit (TCK) to verify that PegaRULEs is compliant with the JSR 94
specification.
To obtain the files and run the test, download the PegaRULES JSR 94 Compatibility Kit
Test Files zip file (pegarules-tck_res-files.zip) from the Integration Services section of
the Pega Developer Network:
http://pdn.pega.com/DevNet/PRPCv5/IntegrationServices/intsvcs_Index.asp
Then follow the instructions that are included in that zip file to run the test.

14

Building JSR-94 Services

Creating a JSR 94 Service


This section describes how to create a JSR 94 service using the sample service to
illustrate each step. This document does not describe every field on every form. For help
or information about a field that is not defined in this document, see the Application
Developer Help system.
To implement a JSR 94 integration project, complete the following tasks:

Plan the JSR 94 Service

(Optional) Create the Data Model of the Incoming Java Object

Create or Identify the Class Rule and Properties

Create or Identify the Service Activities

Create the Service Package and Service Rules

Build the JSR 94 Client

Run the Client and Test the Service

Plan the JSR 94 Service


During the planning stage, determine which parts of the Process Commander application
to make available to the external JSR 94 client. Then determine the individual functions
that the external system needs. Each function corresponds to a JSR 94 service rule,
identified by its key parts as one method in the same service package.
For each method, determine what the service activity is to accomplish. Identify the input
and output of each activity. Identify the class rules, properties, and other rules that are
necessary for storing and processing the input and output.
Determine whether you need to implement in Process Commander through Process
Commander Java pages and Java Property properties the data model of a Java object
delivered by the JSR 94 client application, as was done for the JSR 94 service sample.
You can build the service package and service rules manually, or use the Create Service
Rules Accelerator. If your JSR 94 service will create a new work object and start a flow
for it or it will complete a flow action for an existing work object, the service can use one
of the standard service activities: createWorkProcess or resumeWorkProcess. In this case,
the inputs and outputs are those described in the Using the Services Accelerator, which is
posted on the PDN. If you plan to create a service for another purpose, create your own
custom service activity before running the Service Accelerator.

0BBuilding JSR 94 Services 4BCreating a JSR 94 Service

15

Choose names for the individual components in the JSR 94 service and use Figure 3 to
keep track of the names. For reference purposes, the middle column of Figure 3 lists the
component names in the JSR 94 service example. Write the names of the components
you or the Service Accelerator create in the remaining column. Choose meaningful,
explanatory names.

Component

JSR94ServiceExample

RuleSet

PegaSample-IntSvcs

RuleSet version

(various)

Access group

sampleuser@samples.com

Class rule for


service activity

SampleJavaBase-

Properties for
service activity
class

ClaimObjectList (mode=Java
Object List)

Service activity
name

ProcessClaim

Service package
name

SampleJSR94

Service class name

ClaimService

Service method
name

ProcessClaim

Your Service Project

Figure 3. Component Names: Complete the Empty Column in This Table

(Optional) Create the Data Model of the Incoming Java Object


During the planning stage, you identified whether you need to create in PegaRULES the
data model of an incoming Java object. If so, use the Import JavaBeans Accelerator to
generate the class rules, properties, and Java wrapper classes that represent the Java
object.
For help with this step, see Working with the Java Pages Feature, located on the
Integration pages of the PDN.

16

Building JSR-94 Services

Create or Identify the Class Rule and Properties


During the planning stage you identified the class rule and properties for the service
activities.The class rule that a service activity applies to usually inherits from either the
Data- or the Work- base class rules. If you used the Import JavaBeans Accelerator to
implement in PegaRULES the data model of the incoming Java object, it is likely that
you have associated the generated classes with a work object class.
However, if the class rule or any of the properties do not exist yet, create them. If you
need to save objects of this type into the database, define the class rule as a concrete class
and specify which property is the key.
If you need to map an incoming java.util.List to a Java Object List property, create one
that applies to the same class rule as does the service rule. For more information, see
Data Mapping for JSR 94 Services on page 11 and Working with the Java Pages
Feature (located on the PDN).

Create or Identify the Service Activities


While the service rule receives requests and sends responses performing any necessary
data mapping the service activity processes the input from the JSR 94 client. Create or
identify the service activity before you or the Service Accelerator creates the service rule.

If the service starts or resumes a flow for a work object, the Services Accelerator
assigns the createWorkProcess or the resumeWorkProcess activity to the service, as
appropriate. For information about these activities, see Using the Service
Accelerator, which is available on the PDN. Then continue with Create the Service
Package and Service Rules on page 20.

If the service uses a custom activity, for each activity, identify the class rule it
applies to (that is, its primary page), the properties that it manipulates, the parameters
it expects, and the step pages that it needs, if any.

To create a service activity, complete the following steps:


1.

From the Rules by Type explorer, choose Technical > Activity.

2.

In the New form, complete the fields as shown in Figure 4.

0BBuilding JSR 94 Services 4BCreating a JSR 94 Service

Field

Selection

Applies to

Enter the name of the PegaRULES class rule that you


created for the activity in the Create or Identify the
Class Rule and Properties procedure on page 15.

17

For example, the class rule for the service activity in


the JSR 94 example is SampleJavaBase-.
Name

Enter the name that you chose for the service activity
in the planning stage (see Figure 3).
For example, the name of the service activity for the
JSR 94 service example is ProcessClaim.

Figure 4. Fields in the New Window for a Service Activity


3.

In the Activity form, on the Pages and Classes tab, configure step pages for each of
the following class rules:
The class rule for the service activity. For example, the class rule for the JSR 94
service example is SampleJavaBase-.
The class rule that represents the main Java class in the JSR 94 client application.
For example, the appropriate class rule for the JSR 94 service example is
SampleJavaBase-Claim.
Write down the names as indicated in Figure 5.

Project

Page and Class Rule


Name for the Activity

Page and Class Rule Name


of the Generated Class Rule

JSR94Service
Example

Page name: ServicePage

Page name: ClaimPage

Class name:
SampleJavaBase-

Class name: SampleJavaBaseClaim

Your JSR 94
Project
Figure 5. Pages and Classes Tab in Activity Window
For example, Figure 6 shows the Pages and Classes tab for the ProcessClaim service
activity.

18

Building JSR-94 Services

Figure 6. Pages and Classes Tab for the Service Activity Example
4.

5.

(Optional) If the incoming object will be mapped to a property of mode Java Object
List in the service rule, configure steps that use the AttachJavaObject activity to
attach the object to a Java page:
Use the first step on the Steps tab to create the step page (Java page) for the class
rule that represents the main Java class in the JSR 94 client application. For example,
the first step in the Process Claim activity uses the Page-New method to create the
ClaimPage page.
Configure the second step to call the AttachJavaObject activity, passing in the
identity of the Java Object List property that holds the object to attach.
Configure the remaining steps for the service activity, as appropriate for your goals.
For example, the ProcessClaim service activity has one more step that uses a map
value rule (Rule-Obj-MapValue) to determine whether to approve or deny the claim
based on the age of the car and the amount of the claim. For more information about
this step and the map value rule, see Service Activity Example: the Map Value Rule
Step on page 18.

6.

On the Security tab, accept the default settings.

7.

On the History tab, enter a description in both the Full Description and the Usage
fields.

8.

Click Save.

Service Activity Example: the Map Value Rule Step


Step 3 in the ProcessClaim activity uses the Property-Map-ValuePair method to run the
map value rule named DetermineApprovalStatus. Figure 7 shows Step 3 in the
ProcessClaim service activity.

0BBuilding JSR 94 Services 4BCreating a JSR 94 Service

19

Figure 7. Running the DetermineApprovalStatus Map Value Rule in the ProcessClaim Activity
The DetermineApprovalStatus map value rule evaluates the age of the vehicle and the
amount of the claim and then sets the value of the approvalStatus property to either
Approved or Denied.
Figure 8 shows the decision map on the Matrix tab of the DetermineApprovalStatus map
value rule.

Figure 8. The Decision Map Matrix for the DetermineApprovalStatus Map Value Rule
As mentioned, the age of the vehicle is determined by an expression rule (Rule-DeclareExpression) that calculates the age from the year of the vehicle. Figure 9 shows the
Expressions tab for the expression rule that calculates the value of the age property.

20

Building JSR-94 Services

Figure 9. Expressions Tab in the Age Expression Rule

Create the Service Package and Service Rules


For information about using the Services Accelerator to create the service package and
service rules, see the Using the Services Accelerator, which is available on the PDN. See
also the Application Developer Help system for descriptions of each form the Accelerator
displays as you work through the sequence.
To create a service package and service rules without using the Services Accelerator,
complete the following procedures.

Create a Service Package


Complete the following steps to create a service package:
1.

From the main Process Commander page, click the Integration icon.

2.

From the Integration page, under Resources, click Service Packages.

3.

Click New.

4.

In the New form, in the Service Package name field, enter the name that you chose
for the service package in your planning stage (See Figure 3). For example, the
service package in the JSR 94 service example is SampleJSR94.

5.

In the Service Package form, on the Context tab, complete the fields as shown in
Figure 10.

0BBuilding JSR 94 Services 4BCreating a JSR 94 Service

Field

Value

Processing Mode

Select Stateless or Stateful, as appropriate for the


service. For information about session state, see
Session State on page 10.

Access Group

Enter the name of the access group that you chose


during the planning stage (see Figure 3).

Requires authentication?

Select if you want the requestor that interacts with the


service to be an authenticated user. In this case, the
Processing Mode must be set to Stateful and the JSR
94 client must provide the user name and password
of a valid Process Commander user.
For information, see Authentication on page 10.

Suppress Show-HTML

Select this option to disable the Show-HTML method


for the service activity that will be associated with the
service rule for the service package.
The Show-HTML method generates a stream of
HTML for an activity and stores the HTML on the
activitys thread page. However, JSR 94 services do
not use HTML because the Process Commander Web
application is not used for JSR 94 communications.

Figure 10. Fields on the Context Tab of the Service Package Window
6.

If you selected stateless as the Processing Mode on the Context tab, select the
Pooling tab and configure the requestor pool for your service. Because requestor
pooling is possible for stateless, unauthenticated services only, the Pooling tab is
ignored if Processing Mode is set to Stateful.

7.

On the History tab, enter a description in both the Full Description and the Usage
fields.

8.

Click Save.

Note: The Deployment and Methods tabs are not used by a service package for a
JSR 94 service.

21

22

Building JSR-94 Services

Create a JSR 94 Service Rule


Now that the service package and service activity exist, you can create the service rule.
Complete the following steps:
1.

On the Rules by Type explorer, select Integration-Services > Service JSR 94.

2.

Click New.

3.

In the New form, complete the fields as shown in Figure 11.

Field

Value

Customer Package Name

Enter the name of the service package you created


for this service. This name must match the
packageName component of the URI specified by the
JSR 94 client.
For example, the service package for the JSR 94
service example is SampleJSR94.

Customer Class Name

Enter the name that you chose for the service class in
the planning stage (see Figure 3). This name must
match the className component of the URI specified
by the JSR 94 client; it is not the name of a Rule-ObjClass rule.
For example, the service class name for the JSR 94
service example is ClaimService.

Customer Method Name

Enter the name that you chose for the service method
in the planning stage (see Figure 3). This name must
match the methodName component of the URI
specified by the JSR 94 client.
For example, the service method name for the
JSR 94 service example is ProcessClaim.

Figure 11. Fields in the New Form for a Service Rule


4.

In the Service Rule form, on the Service tab, complete the fields as shown in
Figure 12.

0BBuilding JSR 94 Services 4BCreating a JSR 94 Service

Field

Value

Alternate URI

(Optional) By default, the Uniform Resource Identifier


for the service rule is the three-part key to its name:
ServicePackageName.className.methodName. If
the external application that calls this rule requires
that the URI use a different naming convention, enter
the string to use as the URI for this service in this
field.
The value you enter must be unique for the rule.
Versions of the same rule can use the same alternate
URI. In that case, Process Commander uses rule
resolution to determine the correct version to use.

Page Class

Select the PegaRULES class rule that corresponds to


the page that will serve as the primary page of the
service activity that you select in the Activity Name
field.
For example, the Page Class for the JSR 94 service
example is SampleJavaBase-.

Page Model

Select a page model, if appropriate.


The JSR 94 example does not use a page model.

Page Name

Enter the name of the page that will serve as the


primary page for the service activity that you select in
the Activity Name field. See Figure 5 on page 17.
For example, the Page Name for the JSR 94 service
example is ServicePage.

Activity Name

Enter the name of the service activity that you created


for this service.
For example, the name of the service activity for the
example JSR 94 service is ProcessClaim.

Figure 12. Fields on the Service Tab for a JSR 94 Service Rule
Figure 13 shows the Service tab for the service rule example.

23

24

Building JSR-94 Services

Figure 13. Service Tab for the JSR 94 Service Rule


5.

On the Request tab, click in the Map Input List field and specify whether you are
mapping the entire input list as a single object or whether you are mapping each
element in the list as separate objects.

6.

Click in the Data Type field and do one of the following:

If you are mapping the input list as a single object, enter java.util.List.
If you are mapping the individual elements, enter the data type of the object. For the
primitive Java types, enter String, boolean, byte, int, short, long, float, or double, as
appropriate. For a custom Java class, use the fully qualified Java class name of the
object.

7.

In the Description field, enter a description of the incoming object.

8.

In the Map To field, select the appropriate destination, typically Clipboard.

9.

If you selected Clipboard in the Map To field, then, in the Map To Key field, select
the name of a property that is either a Java Object List property or an embedded
page list property whose page class is one that inherits from the Embed-Java- base
class. The sample JSR 94 service rule maps the list to a Java Object List property
named ClaimObjectList that belongs to the SampleJavaBase- class rule.

0BBuilding JSR 94 Services 4BCreating a JSR 94 Service

25

Figure 14. Request Tab for the Sample JSR 94 Service Rule
10. If you are mapping individual elements from the input list, repeat steps 6 through 9
for each element in the input list.
11. On the Response tab, click in the Map Output List field and specify whether you are
mapping the entire output list as a single object or whether you are mapping each
element in the list as separate objects.
12. (Optional) If you are using a result filter, enter its fully qualified name in the Result
Filter field. See Result Filter on page 13 for more information.
13. Click in the Data Type field and do one of the following:

If you are mapping the output list as a single object, enter java.util.List.
If you are mapping the individual elements, enter the data type of the object. For the
primitive Java types, enter String, boolean, byte, int, short, long, float, or double, as
appropriate. For a custom Java class, use the fully qualified Java class name of the
object.

14. In the Description field, enter a description of the outgoing object.


15. In the Map From field, select the appropriate source, typically Clipboard.
16. In the Map From Key field, select the property that holds the value of the output list
element of the list. If you are mapping from the Clipboard, it should be either a Java
Object List property or an embedded page list property whose page class is one that
inherits from the Embed-Java- base class.
Figure 15 shows the Response tab for the service rule example.

26

Building JSR-94 Services

Figure 15. Response Tab for the Sample JSR 94 Service Rule
17. If you are mapping individual elements from the output list, repeat steps 13 through
16 for each element in the input list.
18. On the History tab, enter a description in both the Full Description and the Usage
fields.
19. Click Save.

Build the JSR 94 Client


When a JSR 94 client interacts with JSR 94 services in PegaRULES, the client
application starts its own instance of the PegaRULES engine. The engine started by the
client application must have its own prconfig.xml and prlogging.xml files to set up the
environment for that PegaRULES engine instance. Separate instances of the PegaRULES
engine the one in use by the Process Commander Web application and the one started
by a JSR 94 application, for example can share the same database. So if the database is
running, PegaRULES JSR 94 services can respond to external JSR 94 applications even
when the PegaRULES Process Commander Web application is not online.
This section describes the components that the PegaRULES JSR 94 service requires in a
JSR 94 client application. To see these components in context, unzip the
pegaclaimsampleclient51.zip file and examine the SubmitClaim.java file.

Note: This section describes the PegaRULES Process Commander requirements


only. For information about writing the Java code that obtains a JSR 94 Rule Session
and a RuleRuntime object, see the JCP JSR 94 specification at:
http://jcp.org/aboutJava/communityprocess/first/jsr094/index.html

0BBuilding JSR 94 Services 4BCreating a JSR 94 Service

27

Rule Service Provider Class


The JSR 94 rule service provider class from PegaRULES is the following:

com.pega.pegarules.pub.services.jsr94.PRuleServiceProvider

URI for PegaRULES Service Rule


The JSR 94 client application must identify the URI for the appropriate PegaRULES
service rule (Rule-Service-JSR94). Typically, the URI uses the following syntax:
packageName.serviceClassName.serviceMethodName
For example:

private static final String SERVICE_URI =


"SampleJSR94.ClaimService.ProcessClaim";

To change the URI to a string other than


packageName.serviceClassName.serviceMethodName, use the Alternate URI field on the
Service tab of the service rule.

Authentication
As described in The Process on page 4, by using the RuleRuntime reference and the
Service URI of the JSR 94 service, the client obtains a RuleSession object. If the service
is to run as an authenticated user, the client application must provide appropriate
credentials for the service.
To identify the service as an authenticated user, provide the user name and password of
the appropriate PegaRULES operator ID with the request for the RuleSession object. For
example:

// Set session properties


Map props = new HashMap();
props.put("UserName", ExampleUser);
props.put("Password", ExamplePassword);
// Create a stateful rule session
StatefulRuleSession session = (StatefulRuleSession)
rr.createRuleSession(SERVICE_URI, props,
RuleRuntime.STATEFUL_SESSION_TYPE);

28

Building JSR-94 Services

Note that in the sample client code, the values for the UserName and Password properties
are set as constants just after the statement that sets the value of the Service URI as a
constant. See the source SubmitClaim.java file in the pegaclaimsampleclient51.zip file.
As mentioned, the session semantics of the RuleSession code must match that of the
service package. For more information about session state, see Session State on page
10. For more information about authentication, see Authentication on page 10.

JAR Files and Class Paths


When a JSR 94 client application starts an instance of the PegaRULES engine, that
engine is embedded in the client application and it uses the same JVM as does the client.
That is, the runtime class path for the PegaRULES engine is the class path of the client
application. (The compile time class path is the same as usual. For information, see
PRKB-20931 About the Process Commander 5.1 Class Paths, located on the PDN.)
Certain PegaRULES Process Commander JAR files, database driver files, and directories
must be in the clients class path so the JSR 94 interface in the embedded PegaRULES
engine can function correctly.
Include the following list of items in the JSR 94 client classpath:

The PegaRULES JAR files. That is, the JAR files located in the WEB-INF\lib or
APP-INF\lib directory.

Because the PegaRULES engine needs it, the servlet .jar file that contains the Java
class javax.servlet.http.HttpServletResponse.

For WebSphere: j2ee.jar.


For WebLogic: weblogic.jar.
For Tomcat version 4: servlet.jar; for Tomcat version 5: servlet-api.jar

Any additional JAR files that your JSR 94 client requires.

The appropriate database driver files for your database. For example, for SQL
Server: msbase.jar, mssqlserver.jar, and msutil.jar. For Oracle: classes12.zip.

The directory from which you run the JSR 94 client application. For the JSR 94
example, that directory is the pegasample-05-01_jsr94serviceapp\classes directory.

The prconfig.xml and prlogging.xml configuration files. If you place these files in
the directory from which you run the JSR 94 application, the class path statement for
the client directory also covers the prconfig.xml and prlogging.xml files.

0BBuilding JSR 94 Services 4BCreating a JSR 94 Service

29

Additionally, the appropriate PegaRULES \binredist directory (WEB-INF\binredist or


APP-INF\binredist) must be in the path of the client application (not the classpath):

For Windows: \binredist\x86

For Solaris: \binredist\sparc

For AIX: \binredist\ppc

For z-OS: \binredist\s390

The PegaClaimSample batch and shell scripts and the PegaClaimSample Ant script for
the sample provide an example of how to ensure that all the required items are in the
classpath of a JSR 94 client application.

Location of the temp Directory


When the PegaRULES engine runs rules for the first time, it generates Java source files,
compiles the source files into Java class files, and then stores the files in its work (or
temp) directory. While more than one instance of the PegaRULES engine can use the
same database, they should have different temp directories.
Create a top-level directory and then, in the copy of the prconfig.xml file you provide for
your client application, specify the path to that directory with the
Initialization/explicitTempDir parameter.

Run the Client and Test the Service


To test a JSR 94 service, you run the JSR 94 client and then determine whether the
service works correctly. To run the example JSR 94 client, PegaClaimSample, see
Running the Sample on page 30. For information about troubleshooting, continue with
Troubleshooting on page 36.

30

Building JSR-94 Services

Running the Sample


The JSR 94 service example is provided in two zip files, located on the Integration
Services pages of the Pega Developer Network:

PegaSample-IntSvcs.zip. This zip file is the RuleSet with the Integration Services
examples, including the sample JSR 94 service rule and the class and property rules
that make up the Process Commander application used in the JSR 94 sample,
AutoClaim.

pegaclaimsampleclient51.zip. This zip file contains the following items:

Java class and source files for the JSR 94 sample client application
Java class and source files that create the Claim objects the JSR 94 sample client
application sends to Process Commander for processing
An Apache Ant script file that runs the sample client application
A batch file and a shell script that set certain environment variables and then invoke
the run script

This section describes how to set up and run the JSR 94 sample. You upload the
PegaSample-IntSvcs RuleSet, download the client application, install Apache Ant,
configure the client applications runtime environment, and then invoke the
PegaClaimSample.xml script to start the application.

PegaRULES Setup
To set up PegaRULES to run the sample, you import the PegaSample-IntSvcs RuleSet.
Complete the following steps:
1.

Download the PegaSample-IntSvcs RuleSet that matches your version of Process


Commander from the Integration page on the Pega Developer Network:
http://pdn.pega.com/DevNet/PRPCv5/IntegrationServices/intsvcs_Index.asp

2.

From the Process Commander menu, choose File > Import Archive.

3.

In the Select Import Mode field, choose Local Zip File.

4.

Click the Browse button next to the File Name field to choose the file.

5.

Click Upload File. The wizard uploads the file to the Process Commander
ServiceDirectory directory and displays the message File Uploaded Successfully.

6.

In the Select Import Mode field, choose Zip File on Server.

0BBuilding JSR 94 Services 5BRunning the Sample

7.

From the list of files, choose the one you just uploaded. The wizard examines the
file and displays several options.

8.

Click Import. Process Commander processes the zip file. When it is finished, it
displays a status message.

9.

Log out of Process Commander and log back in as the sample user:

31

User ID: sampleuser@samples.com


Password: rules.

Note: If you need help with any of the steps in this procedure, see PegaRULES
Process Commander Administration and Security.

Client Application Setup


To set up any JSR 94 client application, you set up the prconfig.xml and prlogging.xml
configuration files and specify the class path for the client application. To set up the
example JSR 94 client application, you must also download and unzip the pegasample05-01_jsr94serviceapp.zip file so that you can run it.

Create the Client Application Directory and Install the PegaClaimSample


Application
The JSR 94 client application starts a new instance of the PegaRULES engine that then
runs in the same JVM as the JSR 94 client. To download and install the
PegaClaimSample application, complete the following steps:
1.

Create a directory for the client application in a location that has network access to
the PegaRULES Process Commander system named pegaclaimsample. Do not use
any spaces in the directory name.

2.

Download the JSR 94 Sample Client Application (pegaclaimsampleclient51.zip file)


from the Integration page of the PDN:
http://pdn.pega.com/DevNet/PRPCv5/IntegrationServices/intsvcs_Index.asp

3.

Unzip the downloaded zip file into the client application directory.

32

Building JSR-94 Services

Copy the prconfig.xml and prlogging.xml Configuration Files


A JSR-94 client application must have in its class path its own prconfig.xml file and
prlogging.xml file that point to the PegaRULES rulebase. Complete the following steps:
1.

Locate the prconfig.xml and prlogging.xml files for your PegaRULES installation.
If Process Commander is deployed as a Web application, they are located in the
WEB-INF\classes directory. If Process Commander is deployed as an Enterprise
application, they are located in the prresources.jar file, which is located in the APPINF\lib directory.

2.

Copy these files to the pegaclaimsample\classes directory.

Edit the prconfig.xml Configuration File


In this step, edit the copy of the prconfig.xml file in the following ways:

Specify a top-level directory that is different than the one used by the Process
Commander application as the temporary directory. As described in Location of the
temp Directory on page 29, the temporary directory stores generated Java for the
PegaRULES instance.

Disable service listeners.

Edit the compiler node statement to include the path to the sample client
applications \classes subdirectory because the Claim.class, Damage.class, and
Vehicle.class files are located in that directory. The instance of the PegaRULES
engine that the sample client application starts must have in its class path the Claim,
Damage, and Vehicle Java classes or it cannot run the service activity successfully.

Edit the database settings to specify the location of the PegaRULES database
through a JDBC URL rather than a JDBC connection pool. Most likely, the
prconfig.xml file you copied specifies a JDBC connection pool, which is managed
by the application server hosting the Web component. Your JSR 94 client application
cannot use a JDBC connection pool to connect to the database.

Complete the following steps:


1.

Create a top-level directory to serve as the temp directory for the PegaRULES
instance that will be started by the client application.

2.

From the client application directory, open the copy of prconfig.xml file in a text
editor.

3.

Scroll to the Initialization/explicitTempDir setting and set it to the location of the


directory you created in step 1. For example:

0BBuilding JSR 94 Services 5BRunning the Sample

33

<env name="Initialization/explicitTempDir" value="d:\pegatemp" />

4.

Scroll to the initServices settings and set them to false. For example:

<env
<env
<env
<env

5.

name="initServices/initEmail" value="false" />


name="initServices/initFile" value="false" />
name="initServices/initJMS" value="false" />
name="initServices/initMQ" value="false" />

Immediately before the first database statement, insert the following node
statements, replacing the value represented in italics with the value that is
appropriate for your configuration.
<env name="compiler/defaultPaths" value="pathto\pegaclaimsample\classes" />

Note: The prconfig.xml file should contain one compiler node statement only. If the
file already contains a compiler node statement, add (append) your defaultPaths
value to the existing defaultPaths value. Do not create a second compiler node
statement.
6.

Examine the database settings. If the prconfig.xml file specifies a JDBC connection
pool as the method of connecting to the PegaRULES database (theres a value set
for the database/databases/PegaRULES/dataSource setting), either remove it or
comment it out. Then, remove the comments from the sample database entries that
indicate how to configure a JDBC URL to point at the PegaRULES database. Edit
their values so they are appropriate for your environment. For example:

<env name="database/drivers" value="com.microsoft.jdbc.sqlserver.SQLServerDriver" />


<env name="database/databases/PegaRULES/url"
value="jdbc:microsoft:sqlserver://localhost:1433;SelectMethod=cursor;SendStringParameter
sAsUnicode=false" />
<env name="database/databases/PegaRULES/userName" value="a_username" />
<env name="database/databases/PegaRULES/password" value="a_password" />

7.

Save the prconfig.xml file.

34

Building JSR-94 Services

Install Apache Ant


The sample script that you use to run the sample JSR 94 client is an Apache Ant script.
To use the script, you must install Apache Ant, an open source makefile utility for
building Java applications.
Complete the following steps:
1.

Go to http://ant.apache.org/

2.

Download and install Apache Ant version 1.5 or later. Be sure that you set the
ANT_HOME environment variable according to the Ant installation instructions.

Edit the PegaClaimSample Batch or Shell Script


The PegaClaimSample batch or shell file sets the build session environment, and then
runs the PegaClaimSample.xml Ant script, which runs the PegaClaimSample application.
Before you can use the PegaClaimSample batch file or shell script you must edit the file
so that certain environment variables are correct for the system on which you are running
it.
Edit the PegaClaimSample.bat file or the PegaClaimSample.sh file as follows for your
system:
1.

In the client directory that you created, select and open the appropriate
PegaClaimSample script in a text editor.

2.

Edit the PRPC_ROOT designation to reflect the location of your Process


Commander system \lib directory (either APP-INF\lib or WEB-INF\lib).

3.

Edit the DB_DRIVER_LIB designation to reflect the location of the database


drivers for your database.

4.

Edit the SERVLET_JAR designation to reflect the location on the Process


Commander application server (or web application server) of the JAR file that
contains the javax.servlet.http.HttpServletResponse Java class.

5.

For WebSphere: j2ee.jar


For WebLogic: weblogic.jar
For Tomcat version 4: servlet.jar; for Tomcat version 5: servlet-api.jar
Scroll down to the PATH statement (called LIBPATH in the shell script) and verify
that it points to the correct \binredistr subdirectory as follows:
For Windows: PRPC_ROOT\binredist\x86
For Solaris: PRPC_ROOT\binredist\sparc

0BBuilding JSR 94 Services 5BRunning the Sample

6.

For AIX: PRPC_ROOT\binredist\ppc


For z-OS: PRPC_ROOT\binredist\s390
Save the PegaClaimSample batch or shell script.

Run the PegaClaimSample Client Application


To run the PegaClaimSample client application example, complete the following steps:
1.

Verify that you have completed all the setup tasks in the Running the Sample
section.

2.

Open a command prompt or UNIX shell, as appropriate.

3.

Change directories to the pegaclaimsample directory.

4.

Run the PegaClaimSample batch or shell script, as appropriate. This file sets the
build session environment variables and then invokes the PegaClaimSample.xml
Ant script, which builds the client application.

5.

Open the PegaClaimSample batch file or shell script again. Comment out the
buildfile statement that invokes the BuildClaim method.

6.

Remove the comment from the buildfile statement that invokes the SubmitClaim
method.

7.

Save the file and run it again.

8.

Watch the console as the client application runs. When it is finished, the output
should be similar to the following:

JSR94-.processClaim Activity Processing claim : CL_1083167395688 for


Policy Number: pr_1
JSR94-.processClaim Activity Processing claim : CL_1083167395688 for
Policy Number: pr_2
JSR94-.processClaim Activity Processing claim : CL_1083167395688 for
Policy Number: pr_3
Claim No : CL_1083167395688 for Policy Number pr_1 has been Denied
Claim No : CL_1083167395688 for Policy Number pr_2 has been Denied
Claim No : CL_1083167395688 for Policy Number pr_3 has been Approved

35

36

Building JSR-94 Services

Troubleshooting
If the JSR 94 client cannot successfully interact with your JSR 94 service, the problem
typically falls into one of the following categories:

The class path of the client application is missing a Java class needed by the
client, the PegaRULES engine instance, or the JSR 94 service rule. Examine the
output to determine the name of the class, locate the JAR file that contains the Java
class, and put the JAR in the class path.

The access privileges specified by the service rule do not give the client access to
the rules it needs to function properly. Examine the access group assigned to the
service package.

You did not create all the required components. Review Creating a JSR 94
Service (starting on page 14) and verify that you created all the necessary rules.

The activity you wrote does not work properly.

You are using clipboard pages improperly. Examine the following fields and tabs
to verify that the page names (and their class rules) are configured correctly:

Page Name field on the Service tab of the service rule


Pages and Classes tab of the service activity
Page names in activity steps that use the Page-New method
The client is not coded or configured properly. Perhaps the problem is with the
client. Are there problems with authenticating the client as a user? See Running as
an Authenticated User on page 11.

Be aware that you cannot use the System Management application to monitor JSR 94
communications. To run rules, the JSR 94 client application starts a separate instance of
the PegaRULES engine it does not use the PegaRULES Process Commander Web
application. Therefore, you cannot use the tools in the PegaRULES Process Commander
Web application or the System Management application to troubleshoot your JSR 94
service. However, you can use the logging facility to gather information and you can unit
test the service rule. (For information about unit testing service rules, see Testing Services
and Connectors, which is posted on the PDN.)

0BBuilding JSR 94 Services 6BTroubleshooting

37

Examining Log Files


Process Commander uses the Apache Jakarta log4j package for logging and messaging.
By default, the logging facility reports messages with a severity level of alert or higher
for the Process Commander Java classes and for individual rules.
While testing your integration projects you can increase log level settings for specific
Java classes. However, when you are using JSR 94, you cannot use the Logging Level
Settings feature available through the Process Commander browser interface. Instead,
you must insert category statements into the prlogging.xml configuration file. Then, to
examine the log files, use the Remote Logging feature.
Read the section on the log files in Chapter 8 of PegaRULES Process Commander
Administration and Security. Then, examine the following list of Process Commander
Java packages and classes:

com.pega.pegarules.services.jsr94

com.pega.pegarules.priv.services.jsr94

com.pega.pegarules.pub.services.jsr94

com.pega.pegarules.services.ServiceAPI

com.pega.pegarules.services.ServiceHelper

Use the information from Administration and Security to insert appropriate logging
category statements into the prlogging.xml file. Start by setting the log severity level for
the jsr94 packages to info. If you need more information, insert category statements for
the other packages and classes in the list.
Next, follow the instructions in Chapter 8 of Administration and Security that describe
how to install the remote logging feature on your workstation.
To enable remote logging for your JSR 94 service, code the JSR 94 client application to
specify where the service should send its status messages by providing values for the host
name of your computer (RemoteLogHost) and the port number on which it is listening
(RemoteLogPort).
For example:
// Set session properties
Map props = new HashMap();
//props.put("UserName", USERNAME);
//props.put("Password", PASSWORD);
props.put("RemoteLogHost", theServerName);
props.put("RemoteLogPort", 8887);

38

Building JSR-94 Services

// Create a stateless rule session


StatelessRuleSession session = (StatelessRuleSession)
rr.createRuleSession(SERVICE_URI, props,
RuleRuntime.STATELESS_SESSION_TYPE);

Now when you run the JSR 94 client application, the log4j socket server captures and
writes information about the JSR 94 services to the prlogging.xml file which is displayed
in the LogFactor5 window on your workstation

0BBuilding JSR 94 Services 7BThe System Pulse and JSR 94 Services

39

The System Pulse and JSR 94 Services


The PegaRULES agent runs the System Pulse agent activity to synchronize the rules
cache when more than one node shares the same Process Commander database. When an
external application starts an instance of the PegaRULES engine through JSR 94,
background agents like the PegaRULES agent do not run, which means the System Pulse
does not run.
The client application in the JSR 94 sample starts a separate instance of the PegaRULES
engine, sends three claim objects, and then stops the engine instance after it receives the
results. The next time you run the client, it starts a new instance of the PegaRULES
engine. The new engine instance has no rules cached so the service rule finds and uses
any rules that have been updated.
However, if your JSR 94 client application keeps an instance of the PegaRULES engine
running during ongoing requests and rules are updated after the engine instance starts, the
JSR 94 services will not recognize that a rule has changed. This is because the
PegaRULES agent (which runs the System Pulse) is not running for that engine instance.
In this case, create a JSR 94 service that calls the Code-.SystemPulse activity and use it
as follows:
1.

Create a JSR 94 service rule that uses the Code-.SystemPulse activity as its service
activity.

2.

Run the System Pulse service before making rules changes. (The System Pulse
works by determining which rules have changed since the last time it ran.
Therefore you must run it once to set a base level before you make changes to
rules that the JSR 94 application uses.)

3.

Make the rule changes.

4.

Run the System Pulse service again.

5.

Run the other JSR 94 services.

If you plan to run a System Pulse service regularly, start by running it no more than every
30 seconds, which is how frequently Process Commander runs the System Pulse by
default.

Das könnte Ihnen auch gefallen