Calling Ilog Jrule Rules Execution server from java client

muthu vel picture muthu vel · May 24, 2012 · Viewed 7k times · Source

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.

Answer

Damien picture Damien · May 25, 2012


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.