Calling Ilog Jrule Rules Execution server from java client

7.3k Views Asked by At

I am trying to execute a rule in IBM Jrule Rules execution server , using a java client. I am having Websphere community Edition V2.1 server, I am able call and execute the rules using JSF deployed in the samae server.

I want to call and execute the rules using a java client. I didn't find any way to do this,

In EJB. we can call EJB from web as well as from java client , by setting Initial Context envionment property. Is there any way similar to this is there, to call Rule Execution server rules, using java client, web part is already working.

import ilog.rules.res.session.IlrPOJOSessionFactory;
import ilog.rules.res.session.IlrStatelessSession;
import ilog.rules.res.session.IlrSessionFactory;
import ilog.rules.res.session.IlrStatefulSession;
import ilog.rules.res.session.IlrSessionRequest;
import ilog.rules.res.session.IlrJ2SESessionFactory;
import ilog.rules.res.session.IlrSessionResponse;
import ilog.rules.res.model.IlrPath;
import ilog.rules.res.session.extension.IlrExtendedJ2SESessionFactory;
import miniloan.Borrower;
import miniloan.Loan;

public class POJOEx {

    public static void main(String... arg) {
        // create rule session factory
        //IlrSessionFactory sessionFactory = new IlrPOJOSessionFactory();
        //IlrExtendedJ2SESessionFactory sessionFactory = new IlrExtendedJ2SESessionFactory();
        //      j2se factory
        IlrSessionFactory sessionFactory = new IlrJ2SESessionFactory();

        try {
            // use stateless session for invocation
            IlrStatelessSession statelessSession = sessionFactory.createStatelessSession();
//input parameter
            Borrower borrower = new miniloan.Borrower("Joe", 600,
                    80000);
// in out parameter
            Loan loan = new miniloan.Loan(500000, 240, 0.05);

            IlrSessionRequest request = sessionFactory.createRequest();
//rule path
            request.setRulesetPath(IlrPath.parsePath("/miniloanruleapp/2.0/miniloanrules/1.0"));

request.setUserDat("miniloanruleapp.MiniloanrulesclientRunnerImpl.executeminiloanrules");

            request.setInputParameter("borrower", borrower);
            request.setInputParameter("loan", loan);
//executing 
            IlrSessionResponse response = statelessSession.execute(request);

            System.out.println("userdata = " + response.getOutputParameters().get("loan"));
            System.out.println("outputString = " + (String) response.getUserData());
            System.out.println("executionId  = " + response.getExecutionId());


        } catch (Exception ex) {
            ex.printStackTrace();
        }          

    }
}

I am getting below error.

ilog.rules.res.xu.ruleset.impl.archive.IlrRulesetArchiveInformationNotFoundException: Cannot get the information about the ruleset /miniloanruleapp/2.0/miniloanrules/1.0

can anybody suggest where to specify Rules execution server url, username and password. like we specify InitialContext values in EJB.

3

There are 3 best solutions below

1
On


Let me clarify what is RES because it seems there is a misunderstanding here, it may be me.
RES is used in Ilog terminology to describe multiple things:
- The web interface that allows you to manage your ruleapp.
- The actual application that you deploy on your WebSphere CE (or else) in order to execute the rules.
- The .jar files that allows you to execute the ruleapp locally.

You, AFAIK, cannot connect RES using a local JAVA application.
What you have coded is calling the rule engine contained in the RES*.jar files in order to execute your ruleapp locally.
There is no way you can use your JAVA application like you are using your EJB application.
You have to use a webservice or else which is feasible if you put the ruleapp name as a parameter of the web service for instance.
You are using miniloan so you probably know the example using the web interface where you can tell which version of the ruleset to use.
It will be the same if you want to programmatically manage your ruleapp deployed on RES (real application on your application server) you will need to use MDB. Nothing else.

It is disapointing, I know because I went through that, but there is no way I know (at least) to do that. This is not the behaviour you have to follow.

To make it work then put your ruleapp in the classpath (or root of your JAVA application in eclipse) and run it... Then you will execute your rules.

RES doesn't provide the same tools than RTS where you can access RTS from any JAVA application in order to manipulate your rule project.

You are 100% correct there is no way to tell the J2SE connection what is the server URL and hence no way to run your rules from the server.
Hope it helps.

0
On

adding below files in the same folder of *.dsar worked for me creation_date.txt, display_name.txt, properties.txt

0
On

You can absolutely call a Rule Execution Server from J2EE code or as in your case via a remote J2SE call and there is documentation provided to do this. But I do want to clarify a few things regarding the first response.

The Rule Execution Server is the runtime for executing rules. It has a persistence layer (file or database) and a management console that is used to manage it and any other connected Rule Execution Server.

It is this management server you connect to when you using the:

  • server:port/res URL

You do not connect to an actual RES as you can connect many RES to a single management console. The management console has the details about the persistence layer and a way of extracting the ruleset you wish to execute.

To your question. The reason that you are getting an error is that you have not configured which remote rule execution server you wish to pull the ruleset from, which is why you get the error you see.

To configure the remote connection, you use a file called 'ra.xml' and change the settings to point to your remote res/console.

There is a default ra.xml in the '/executionserver/bin' directory (default to ./IBM/ODM87/ODM/executionserver/bin).

The major aspects in that file to consider would be:

  To enable management of Java SE XU instances that are running on different JVM or JMX MBean server, you must configure the  XU MBean plug-in with the TCPIP protocol:
    <config-property>
               <config-property-name>plugins</config-property-name>
               <config-property-type>java.lang.String</config-property-type>
               <config-property-value>{pluginClass=Management,xuName=default,protocol=tcpip,tcpip.port=TCPIP_PORT,tcpip.host=RES_CONSOLE_HOST,tcpip.retryInterval=INTERVAL}
          </config-property-value>
        </config-property>
    where:
RES_CONSOLE_HOST is the host on which the Rule Execution Server console is deployed.
TCPIP_PORT is the TCP/IP port on which the Rule Execution Server console management server is listening.
INTERVAL is the interval of time, in milliseconds, during which the console tries to reconnect to the management server if a connection fails.

As long as the ra.xml is in the classpath of the application you are running the local J2SE engine should make a call to the remote RES console and request the rule app specified in the provide RuleSet path.

For J2EE, this is similar but you actually execute the rule in the remote RES rather than pull the ruleset locally.

If you check the ODM Samples there is both a J2EE and J2SE sample that demonstrates both techniques.