0

我正在尝试克服由特定要求引起的挑战,该要求需要几个规则查询数据库并根据从 SELECT 语句获得的值返回结果。虽然我知道让 JRules 连接到数据库本身并不是“最佳实践”,但在这个阶段它实际上是必需的。

我在 XOM 中创建了一个包装类,生成了它的 BOM 等价物,并描述了它的构造函数和方法,如下所示。虽然我从规则引擎中得到了一个 NPE 异常,但我似乎无法弄清楚为什么。

此外,当在单独的 java 项目中使用时,包含查询数据库的语言化方法的类工作正常,没有任何错误。

任何人都知道为什么在调用规则时会引发异常?

规则集参数:

姓名-- | 类型 | 方向 | 默认值 | 语言化

合同 | 模型.合同 | 输入 | (无)| 收到的合同

会费 | java.math.BigDecimal | 输出 | (无)| 会费

代理引擎 | wrapper.AgencyCampEngine | 输出 | (无)| 在引擎中

规则流程

规则流

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;
        }
}

例外:

[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
4

1 回答 1

0

我不完全清楚您的方法何时何地getAdvanceDuesAmount执行。但是查看您的代码,我怀疑该方法应该static在 Java 代码中:它不引用您类中的任何(对象)变量。

于 2013-09-28T10:32:43.310 回答