Sunday, April 27, 2014

sample for "calling ruleset using ejb ,i.e., "Calling a ruleset using an EJB factory and a stateful session"

The first step is to create a connection to the RES via EJB I signal as below: Mapconexao = new HashMap(); IlrEJB3SessionFactory sessionFactory = new IlrEJB3SessionFactory(); String jndiName="ilog.rules.res.session.impl.ejb3.IlrStatelessSessionRemote"; //default JNDI in WAS sessionFactory.setStatelessRemoteJndiName(jndiName); sessionFactory.setRemote(true); IlrPath rulesetPath=null; try{ rulesetPath = IlrPath.parsePath("/HelloWorldRuleApp/HelloWorld"); }catch (IlrFormatException e1){ e1.printStackTrace(); } conexao.put("sessionFactory", sessionFactory); conexao.put("jndiName", jndiName); conexao.put("rulesetPath", rulesetPath); Then you will connect to RES from EJB created and will query the ruleset. Remember that you will be working with an object. In the example below I use the object person. IlrSessionResponse response=null; IlrSessionRequest request = sessionFactory.createRequest(); request.setRulesetPath(rulesetPath); Person person = new Person(); person.setName(name); request.setInputParameter("person", person); request.getTraceFilter().setInfoTotalRulesFired(true); request.setTraceEnabled(true); try{ IlrStatelessSession session = sessionFactory.createStatelessSession(); System.out.println("created session " + IlrJNDIConstants.STATELESS_SESSION_EJB3_NAME); response = session.execute(request);

No comments: