drools – 在TaskClient上调用activate方法时获取java.lang.NullPointerException

前端之家收集整理的这篇文章主要介绍了drools – 在TaskClient上调用activate方法时获取java.lang.NullPointerException前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在客户端对象上调用activate方法获取空指针异常.这是我的代码.
@RequestMapping(value="/loanreq",method=RequestMethod.GET)
  public String loanRequest(HttpServletRequest req,HttpSession session) throws DroolsParserException,IOException,NamingException{

   StatefulKnowledgeSession ksession = processEngine.getKsession();

   ksession.getWorkItemManager().registerWorkItemHandler("Human Task",new WSHumanTaskHandler());

   TaskClient client = new TaskClient(new MinaTaskClientConnector("UserTask",new MinaTaskClientHandler(SystemEventListenerFactory.getSystemEventListener())));

        client.connect("ipaddress",9123);
        BlockingTaskOperationResponseHandler responseHandler =

                new BlockingTaskOperationResponseHandler();
        client.activate(3,"krisv",responseHandler);

        client.start(3,responseHandler);

            client.complete( 3,null,responseHandler );




   Map<String,Object> params=new HashMap();
   params.put("employee","krisv");


   ProcessInstance processInstance =ksession.startProcess("com.vr.controller2",params); 


   System.out.println("id is "+processInstance.getId());

   return "return1";
  }

我得到以下例外

java.lang.NullPointerException
at org.jbpm.task.service.mina.MinaTaskClientConnector.write(MinaTaskClientConnector.java:118)
at org.jbpm.task.service.TaskClient.activate(TaskClient.java:651)
at com.vr.controller.hellocontroller.loanRequest(hellocontroller.java:181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:101)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.authentication.logout.logoutFilter.doFilter(logoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:173)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

我在调试时看到了客户端对象,但它不是null.不知道为什么我收到此错误.我在“client.activate()”行而不是“client.connect()”收到此错误.

解决方法

根据堆栈跟踪,出现此错误,因为MinaTaskClientConnector中的会话为空.据我所知,源代码TaskClientMinaTaskClientConnector,这是因为connect方法失败,在这段代码中:
try {
      connector.getFilterChain().addLast("codec",new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));

      ConnectFuture future1 = connector.connect( address );
      future1.awaitUninterruptibly();
      if (!future1.isConnected()) {
          return false;
      }
      session = future1.getSession();
      return true;
 } catch (Exception e) {
      logger.error(e.getMessage(),e);
      return false;
 }

您可以在日志中找到确切的错误,也可以在catch块中放置断点.

另外我建议检查connect方法的结果(它返回布尔值以指示连接成功)并执行以下操作:

if (client.connect("ipaddress",9123) {
      BlockingTaskOperationResponseHandler responseHandler = new BlockingTaskOperationResponseHandler();
      client.activate(3,responseHandler);
      client.start(3,responseHandler);
      client.complete( 3,responseHandler );
      Map<String,Object> params=new HashMap();
      params.put("employee","krisv");
      ProcessInstance processInstance =ksession.startProcess("com.vr.controller2",params); 
      System.out.println("id is "+processInstance.getId());
      return "return1";
} else {
      //TODO code to report connection error
}
原文链接:https://www.f2er.com/java/128794.html

猜你在找的Java相关文章