0

I am trying to overcome a challenge arising from a specific requirement which necessitates a couple of rules query a database and return results according to values obtained from the SELECT statement. Although I know that it is not a "best practice" to have JRules connect to the database itself, but it is actually required at this stage.

I created a wrapper class in the XOM, produced its BOM equivalent, and verbalized its constructor and method which is below. I get a NPE exception from the rule engine though and I can't seem to figure out why.

Moreover the class containing the verbalized methods querying the database works fine without any errors when used as is in a separate java project.

Anyone with any idea why an exception would be thrown when calling the rule?

Ruleset Parameters:

Name -- | Type | Direction | Default value | Verbalization

contract | model.Contract | IN | (none) | incoming contract

dues | java.math.BigDecimal | OUT | (none) | dues

agencyEngine | wrapper.AgencyCampEngine | OUT | (none) | in the engine

The Rule flow

ruleflow

package wrapper;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import model.Contract;

public class AgencyCampEngine implements java.io.Serializable {

        private static final long serialVersionUID = -8566255507310739728L;

        private Contract contract;

        public AgencyCampEngine(Contract contract) {

                this.contract = contract;
        }

        public java.math.BigDecimal getAdvanceDuesAmount(int contractNumber) {

                System.out.println("Looking up dues for Contract no: "+contractNumber);
                java.math.BigDecimal result = new java.math.BigDecimal("-1.00");

                Connection conn = null;
                   PreparedStatement pstmt = null;
                   try{              
                      conn = Connector.getConnection();

                      String sql = "SELECT * FROM CONTRACTS WHERE Contract_NO = ?";
                      pstmt = conn.prepareStatement(sql);
                      pstmt.setInt(1, contractNumber);
                      ResultSet rs = pstmt.executeQuery();
                      while (rs.next()) {
                            System.out.println(rs.getInt("Contract_NO")+" found in CONTRACTS :)");
                              result = (rs.getBigDecimal("AMOUNT")!=null?rs.getBigDecimal("AMOUNT"):result);        
                      }

                      rs.close();
                      conn.close();
                      pstmt.close();

                   }catch(SQLException se){

                              se.printStackTrace();
                           }catch(Exception e){

                              e.printStackTrace();

                           }finally{
                              s
                              try{
                                 if(pstmt!=null)
                                    pstmt.close();
                              }catch(SQLException se2){
                    se2.printStackTrace();
                              }
                              try{
                                 if(conn!=null)
                                    conn.close();
                              }catch(SQLException se){
                                 se.printStackTrace();
                              }//end finally try
                           }//end try    

                return result;
        }
}

The exception:

[9/27/13 11:26:34:542 EEST] 0000006b SystemErr     R ilog.rules.res.session.IlrSessionException: An error occurred while the rule session was called:
com.ibm.rules.res.xu.internal.XUException: XU Client error
ilog.rules.res.xu.IlrLocalizedResourceException: GBRXU0001E: The interaction ruleEngine.execute has failed
javax.resource.ResourceException: com.ibm.rules.res.xu.internal.XUException: GBRXU0411E: Ruleset execution error
com.ibm.rules.res.xu.internal.XUException: GBRXU0411E: Ruleset execution error
ilog.rules.engine.IlrUserRuntimeException: null object when invoking public java.math.BigDecimal wrapper.AgencyCampEngine.getAdvanceDuesAmount(int)
        at action part of rule 'rulePackage.aidat_tutari'
        at call to 'mainRuleflow#rulePackage rule task body' 
        at call to 'mainRuleflow flow task body' 
        at call to 'execute' 
java.lang.NullPointerException: null object when invoking public java.math.BigDecimal wrapper.AgencyCampEngine.getAdvanceDuesAmount(int)

[9/27/13 11:26:34:542 EEST] 0000006b SystemErr     R         at ilog.rules.res.session.impl.IlrStatefulSessionBase.execute(IlrStatefulSessionBase.java:483)
[9/27/13 11:26:34:542 EEST] 0000006b SystemErr     R         at ilog.rules.res.session.impl.IlrStatefulSessionBase.execute(IlrStatefulSessionBase.java:203)
[9/27/13 11:26:34:542 EEST] 0000006b SystemErr     R         at ilog.rules.res.session.impl.IlrStatelessSessionBase.execute(IlrStatelessSessionBase.java:64)
[9/27/13 11:26:34:542 EEST] 0000006b SystemErr     R         at com.odmhelper.rulecontroller.RuleTestController.executeRules1(RuleTestController.java:181)
[9/27/13 11:26:34:543 EEST] 0000006b SystemErr     R         at com.odmhelper.rulecontroller.RuleTestController.executeRuleOnce(RuleTestController.java:148)
[9/27/13 11:26:34:543 EEST] 0000006b SystemErr     R         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[9/27/13 11:26:34:543 EEST] 0000006b SystemErr     R         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
[9/27/13 11:26:34:543 EEST] 0000006b SystemErr     R         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
[9/27/13 11:26:34:543 EEST] 0000006b SystemErr     R         at java.lang.reflect.Method.invoke(Method.java:611)
[9/27/13 11:26:34:543 EEST] 0000006b SystemErr     R         at org.apache.el.parser.AstValue.invoke(AstValue.java:266)
[9/27/13 11:26:34:543 EEST] 0000006b SystemErr     R         at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
[9/27/13 11:26:34:543 EEST] 0000006b SystemErr     R         at org.apache.myfaces.view.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:83)
[9/27/13 11:26:34:543 EEST] 0000006b SystemErr     R         at javax.faces.component._MethodExpressionToMethodBinding.invoke(_MethodExpressionToMethodBinding.java:88)
[9/27/13 11:26:34:543 EEST] 0000006b SystemErr     R         at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:100)
[9/27/13 11:26:34:543 EEST] 0000006b SystemErr     R         at javax.faces.component.UICommand.broadcast(UICommand.java:120)
[9/27/13 11:26:34:543 EEST] 0000006b SystemErr     R         at javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:973)
[9/27/13 11:26:34:543 EEST] 0000006b SystemErr     R         at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:275)
[9/27/13 11:26:34:543 EEST] 0000006b SystemErr     R         at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1285)
[9/27/13 11:26:34:543 EEST] 0000006b SystemErr     R         at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:711)
[9/27/13 11:26:34:543 EEST] 0000006b SystemErr     R         at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:34)
[9/27/13 11:26:34:543 EEST] 0000006b SystemErr     R         at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:171)
[9/27/13 11:26:34:543 EEST] 0000006b SystemErr     R         at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
[9/27/13 11:26:34:543 EEST] 0000006b SystemErr     R         at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
[9/27/13 11:26:34:544 EEST] 0000006b SystemErr     R         at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1224)
[9/27/13 11:26:34:544 EEST] 0000006b SystemErr     R         at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:774)
[9/27/13 11:26:34:544 EEST] 0000006b SystemErr     R         at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:456)
[9/27/13 11:26:34:544 EEST] 0000006b SystemErr     R         at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
[9/27/13 11:26:34:544 EEST] 0000006b SystemErr     R         at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1032)
[9/27/13 11:26:34:544 EEST] 0000006b SystemErr     R         at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
[9/27/13 11:26:34:544 EEST] 0000006b SystemErr     R         at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:895)
[9/27/13 11:26:34:544 EEST] 0000006b SystemErr     R         at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
[9/27/13 11:26:34:544 EEST] 0000006b SystemErr     R         at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
[9/27/13 11:26:34:544 EEST] 0000006b SystemErr     R         at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
[9/27/13 11:26:34:544 EEST] 0000006b SystemErr     R         at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
[9/27/13 11:26:34:544 EEST] 0000006b SystemErr     R         at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
[9/27/13 11:26:34:544 EEST] 0000006b SystemErr     R         at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
[9/27/13 11:26:34:544 EEST] 0000006b SystemErr     R         at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
[9/27/13 11:26:34:544 EEST] 0000006b SystemErr     R         at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
[9/27/13 11:26:34:544 EEST] 0000006b SystemErr     R         at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
[9/27/13 11:26:34:544 EEST] 0000006b SystemErr     R         at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
[9/27/13 11:26:34:544 EEST] 0000006b SystemErr     R         at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
[9/27/13 11:26:34:544 EEST] 0000006b SystemErr     R         at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
[9/27/13 11:26:34:544 EEST] 0000006b SystemErr     R         at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
[9/27/13 11:26:34:545 EEST] 0000006b SystemErr     R         at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1690)
[9/27/13 11:26:34:545 EEST] 0000006b SystemErr     R Caused by: com.ibm.rules.res.xu.internal.XUException: XU Client error
[9/27/13 11:26:34:545 EEST] 0000006b SystemErr     R         at com.ibm.rules.res.xu.client.internal.XUSession.executeOperation(XUSession.java:170)
[9/27/13 11:26:34:545 EEST] 0000006b SystemErr     R         at com.ibm.rules.res.xu.client.internal.XURuleEngineSession.executeRuleEngineOperation(XURuleEngineSession.java:60)
[9/27/13 11:26:34:545 EEST] 0000006b SystemErr     R         at com.ibm.rules.res.xu.client.internal.XURuleEngineSession.execute(XURuleEngineSession.java:550)
[9/27/13 11:26:34:545 EEST] 0000006b SystemErr     R         at ilog.rules.res.session.impl.IlrStatefulSessionBase.execute(IlrStatefulSessionBase.java:529)
[9/27/13 11:26:34:545 EEST] 0000006b SystemErr     R         at ilog.rules.res.session.impl.IlrStatefulSessionBase.execute(IlrStatefulSessionBase.java:468)
[9/27/13 11:26:34:545 EEST] 0000006b SystemErr     R         ... 43 more
[9/27/13 11:26:34:545 EEST] 0000006b SystemErr     R Caused by: ilog.rules.res.xu.IlrLocalizedResourceException: GBRXU0001E: The interaction ruleEngine.execute has failed
[9/27/13 11:26:34:545 EEST] 0000006b SystemErr     R         at ilog.rules.res.xu.cci.IlrXUInteraction.execute(IlrXUInteraction.java:277)
[9/27/13 11:26:34:545 EEST] 0000006b SystemErr     R         at com.ibm.rules.res.xu.client.internal.XUSession.executeOperation(XUSession.java:156)
[9/27/13 11:26:34:545 EEST] 0000006b SystemErr     R         ... 47 more
[9/27/13 11:26:34:545 EEST] 0000006b SystemErr     R Caused by: javax.resource.ResourceException: com.ibm.rules.res.xu.internal.XUException: GBRXU0411E: Ruleset execution error
[9/27/13 11:26:34:545 EEST] 0000006b SystemErr     R         at ilog.rules.res.xu.spi.IlrManagedXUConnection.createResourceException(IlrManagedXUConnection.java:827)
[9/27/13 11:26:34:545 EEST] 0000006b SystemErr     R         at ilog.rules.res.xu.spi.IlrManagedXUConnection.engineExecute(IlrManagedXUConnection.java:809)
[9/27/13 11:26:34:545 EEST] 0000006b SystemErr     R         at ilog.rules.res.xu.cci.IlrXUConnection.engineExecute(IlrXUConnection.java:375)
[9/27/13 11:26:34:545 EEST] 0000006b SystemErr     R         at ilog.rules.res.xu.cci.IlrXUInteraction.engineExecute(IlrXUInteraction.java:485)
[9/27/13 11:26:34:546 EEST] 0000006b SystemErr     R         at ilog.rules.res.xu.cci.IlrXUInteraction.dispatchExecution(IlrXUInteraction.java:92)
[9/27/13 11:26:34:546 EEST] 0000006b SystemErr     R         at ilog.rules.res.xu.cci.IlrXUInteraction.execute(IlrXUInteraction.java:262)
[9/27/13 11:26:34:546 EEST] 0000006b SystemErr     R         ... 48 more
[9/27/13 11:26:34:546 EEST] 0000006b SystemErr     R Caused by: com.ibm.rules.res.xu.internal.XUException: GBRXU0411E: Ruleset execution error
[9/27/13 11:26:34:546 EEST] 0000006b SystemErr     R         at com.ibm.rules.res.xu.engine.cre.internal.CREManager.performExecute(CREManager.java:172)
[9/27/13 11:26:34:546 EEST] 0000006b SystemErr     R         at com.ibm.rules.res.xu.engine.internal.BaseEngineManager.execute(BaseEngineManager.java:576)
[9/27/13 11:26:34:546 EEST] 0000006b SystemErr     R         at ilog.rules.res.xu.spi.IlrManagedXUConnection.engineExecute(IlrManagedXUConnection.java:803)
[9/27/13 11:26:34:546 EEST] 0000006b SystemErr     R         ... 52 more
[9/27/13 11:26:34:546 EEST] 0000006b SystemErr     R Caused by: ilog.rules.engine.IlrUserRuntimeException: null object when invoking public java.math.BigDecimal wrapper.AgencyCampEngine.getAdvanceDuesAmount(int)
        at action part of rule 'rulePackage.aidat_tutari'
        at call to 'mainRuleflow#rulePackage rule task body' 
        at call to 'mainRuleflow flow task body' 
        at call to 'execute' 
[9/27/13 11:26:34:546 EEST] 0000006b SystemErr     R         at ilog.rules.engine.e.handleException(Unknown Source)
[9/27/13 11:26:34:546 EEST] 0000006b SystemErr     R         at ilog.rules.inset.IlrExecMethodValue.getValue(Unknown Source)
[9/27/13 11:26:34:546 EEST] 0000006b SystemErr     R         at ilog.rules.inset.IlrExecSimpleAssign.execute(Unknown Source)
[9/27/13 11:26:34:546 EEST] 0000006b SystemErr     R         at ilog.rules.engine.x.execute(Unknown Source)
[9/27/13 11:26:34:546 EEST] 0000006b SystemErr     R         at ilog.rules.engine.IlrRuleMem.a(Unknown Source)
[9/27/13 11:26:34:546 EEST] 0000006b SystemErr     R         at ilog.rules.engine.IlrRuleInstance.fire(Unknown Source)
[9/27/13 11:26:34:546 EEST] 0000006b SystemErr     R         at ilog.rules.engine.IlrEngine.a(Unknown Source)
[9/27/13 11:26:34:546 EEST] 0000006b SystemErr     R         at ilog.rules.engine.IlrAgenda.if(Unknown Source)
[9/27/13 11:26:34:546 EEST] 0000006b SystemErr     R         at ilog.rules.engine.IlrDefaultAgenda.if(Unknown Source)
[9/27/13 11:26:34:547 EEST] 0000006b SystemErr     R         at ilog.rules.engine.IlrAgenda.a(Unknown Source)
[9/27/13 11:26:34:547 EEST] 0000006b SystemErr     R         at ilog.rules.engine.IlrEngine.fireAgendaRules(Unknown Source)
[9/27/13 11:26:34:547 EEST] 0000006b SystemErr     R         at ilog.rules.inset.IlrExecRuleTask.a(Unknown Source)
[9/27/13 11:26:34:547 EEST] 0000006b SystemErr     R         at ilog.rules.inset.IlrExecRuleTask.execute(Unknown Source)
[9/27/13 11:26:34:547 EEST] 0000006b SystemErr     R         at ilog.rules.inset.IlrExecTask.run(Unknown Source)
[9/27/13 11:26:34:547 EEST] 0000006b SystemErr     R         at ilog.rules.engine.IlrTaskEngine.execute(Unknown Source)
[9/27/13 11:26:34:547 EEST] 0000006b SystemErr     R         at ilog.rules.inset.IlrExecTaskInstance.execute(Unknown Source)
[9/27/13 11:26:34:547 EEST] 0000006b SystemErr     R         at ilog.rules.engine.IlrTaskEngine.executeItem(Unknown Source)
[9/27/13 11:26:34:547 EEST] 0000006b SystemErr     R         at ilog.rules.engine.IlrTaskEngine.executeSubFlow(Unknown Source)
[9/27/13 11:26:34:547 EEST] 0000006b SystemErr     R         at ilog.rules.inset.IlrExecFlowTask.execute(Unknown Source)
[9/27/13 11:26:34:547 EEST] 0000006b SystemErr     R         at ilog.rules.inset.IlrExecTask.run(Unknown Source)
[9/27/13 11:26:34:547 EEST] 0000006b SystemErr     R         at ilog.rules.engine.IlrTaskEngine.execute(Unknown Source)
[9/27/13 11:26:34:547 EEST] 0000006b SystemErr     R         at ilog.rules.inset.IlrExecTaskInstance.execute(Unknown Source)
[9/27/13 11:26:34:547 EEST] 0000006b SystemErr     R         at ilog.rules.engine.IlrTaskEngine.executeItem(Unknown Source)
[9/27/13 11:26:34:547 EEST] 0000006b SystemErr     R         at ilog.rules.engine.IlrTaskEngine.if(Unknown Source)
[9/27/13 11:26:34:547 EEST] 0000006b SystemErr     R         at ilog.rules.engine.IlrTaskEngine.a(Unknown Source)
[9/27/13 11:26:34:547 EEST] 0000006b SystemErr     R         at ilog.rules.engine.IlrContext.a(Unknown Source)
[9/27/13 11:26:34:547 EEST] 0000006b SystemErr     R         at ilog.rules.engine.IlrContext.execute(Unknown Source)
[9/27/13 11:26:34:547 EEST] 0000006b SystemErr     R         at com.ibm.rules.res.xu.engine.cre.internal.CREManager.performExecute(CREManager.java:161)
[9/27/13 11:26:34:547 EEST] 0000006b SystemErr     R         ... 54 more
[9/27/13 11:26:34:548 EEST] 0000006b SystemErr     R Caused by: java.lang.NullPointerException: null object when invoking public java.math.BigDecimal wrapper.AgencyCampEngine.getAdvanceDuesAmount(int)
[9/27/13 11:26:34:548 EEST] 0000006b SystemErr     R         at ilog.rules.inset.IlrExecMethodValue.getValue(Unknown Source)
[9/27/13 11:26:34:548 EEST] 0000006b SystemErr     R         ... 80 more
kc2001
  • 5,008
  • 4
  • 51
  • 92
fledglingCoder
  • 402
  • 9
  • 24
  • Note to the editors: After IBM acquired iLog Jrules, the product was renamed "Websphere iLog Jrules" and then "Websphere Operational Decision Management" and finally rebranded the product as "IBM Operational Decision Manager". Reconsider disapproving the Websphere tag. Newbies will seek info using keywords such as Websphere, WODM and ODM, FYI. Webpshere is a brand of IBM not limited to application servers. – fledglingCoder Sep 30 '13 at 08:05

1 Answers1

0

I'm not entirely clear as to when and where your method getAdvanceDuesAmountis executed. But looking at your code, I suspect that the method should be static in the Java code: it doesn't refer to any of the (object) variables in your class.

Miichi
  • 1,739
  • 1
  • 14
  • 16
  • Miichi, very interesting suggestion. Other rules (in the same class or not) work just fine without being made static. Are you suggesting that from within Jrules a method has to be strictly static to be able to make a successful JDBC call? – fledglingCoder Sep 30 '13 at 08:07
  • No, it was just a suspicion based on your code never really referring to the object and on the stack trace. According to the stack trace the only thing that could be null is the implicit parameter (i.e., internally to the rules engine something like `AgencyCampEngine ace=null; ace.getAdvanceDuesAmount(42);` must happen. – Miichi Sep 30 '13 at 19:36
  • Couldn't `conn = Connector.getConnection();` returns null? Seems to me like the only spot where you could get a `null` value that would trigger a NullPointerException – ratiaris Aug 18 '14 at 20:03