8 Replies Latest reply on Jan 21, 2015 12:29 PM by Maciej Swiderski

    Unable to get ProcessInstance variables from Java Rest  API

    Gianluca Galantucci Newbie

      Hi all,

      I'm currently trying to retrieve variables set on a ProcessInstance at the start phase.

       

      I use the code below to get such variables in a subsequent point of the workflow:

       

      RemoteRuntimeEngineFactory restSessionFactory= new RemoteRestRuntimeEngineFactory(deploymentId, instanceUrl, user, password);

      RemoteRuntimeEngine engine = restSessionFactory.newRuntimeEngine();

      KieSession ksession = engine.getKieSession();

      TaskService taskService = engine.getTaskService();

       

      List<TaskSummary> tasks = taskService.getTasksOwned("USER", "en-UK");

      for (TaskSummary task : tasks) {

                  JaxbTaskSummary taskImpl = (JaxbTaskSummary) task;

                  Task taskData = taskService.getTaskById(taskImpl.getId());

      }

       

      ProcessInstance processInstance = ksession.getProcessInstance(taskImpl.getProcessInstanceId());

      CommandBasedStatefulKnowledgeSession session = (CommandBasedStatefulKnowledgeSession)ksession;

      FindVariableInstancesCommand cmd2 = new FindVariableInstancesCommand(processInstance.getId(), "VAR_NAME");

      Object result2 = session.execute(cmd2);

       

      But I get a silent NullPointerException when I run this code.

       

      org.kie.services.client.api.command.exception.RemoteApiException: NullPointerException thrown with message 'null':

      java.lang.NullPointerException

          at org.jbpm.process.audit.command.FindVariableInstancesCommand.execute(FindVariableInstancesCommand.java:67)

          at org.jbpm.process.audit.command.FindVariableInstancesCommand.execute(FindVariableInstancesCommand.java:30)

          at org.kie.remote.services.cdi.ProcessRequestBean.processCommand(ProcessRequestBean.java:129)

          at org.kie.remote.services.cdi.ProcessRequestBean$Proxy$_$$_WeldClientProxy.processCommand(Unknown Source)

          at org.kie.remote.services.rest.ResourceBase.restProcessJaxbCommandsRequest(ResourceBase.java:73)

          at org.kie.remote.services.rest.RuntimeResource.execute(RuntimeResource.java:104)

          at org.kie.remote.services.rest.RuntimeResource$Proxy$_$$_WeldClientProxy.execute(Unknown Source)

          at sun.reflect.GeneratedMethodAccessor98.invoke(Unknown Source)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

          at java.lang.reflect.Method.invoke(Method.java:606)

          at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137)

          at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296)

          at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250)

          at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:237)

          at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356)

          at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)

          at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)

          at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)

          at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)

          at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)

          at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)

          at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130)

          at org.jboss.solder.servlet.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:65)

          at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)

          at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)

          at org.jboss.solder.servlet.event.ServletEventBridgeFilter.doFilter(ServletEventBridgeFilter.java:74)

          at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)

          at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)

          at org.kie.remote.services.rest.jaxb.DynamicJaxbContextFilter.doFilter(DynamicJaxbContextFilter.java:29)

          at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)

          at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)

          at org.jbpm.designer.web.filter.impl.PluggableFilter.doFilter(PluggableFilter.java:70)

          at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)

          at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)

          at org.uberfire.security.server.UberFireSecurityFilter.doFilter(UberFireSecurityFilter.java:283)

          at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)

          at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)

          at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)

          at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)

          at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)

          at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)

          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)

          at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113)

          at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56)

          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)

          at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51)

          at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)

          at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61)

          at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56)

          at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)

          at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)

          at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)

          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)

          at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)

          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)

          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)

          at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240)

          at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227)

          at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73)

          at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146)

          at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177)

          at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727)

          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)

       

          at org.kie.services.client.api.command.AbstractRemoteCommandObject.executeRestCommand(AbstractRemoteCommandObject.java:438)

          at org.kie.services.client.api.command.AbstractRemoteCommandObject.execute(AbstractRemoteCommandObject.java:120)

          at org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession.execute(CommandBasedStatefulKnowledgeSession.java:498)

       

      Does anyone know if I'm missing something?

       

      Thank you,

      Gianluca

        • 1. Re: Unable to get ProcessInstance variables from Java Rest  API
          Antonio Giambanco Novice

          Hi all,

          I have the same problem . . .

          So I decided to make a simple test, I deployed HR demo project creating some process instances, after that I decided to call them through the fallowing url (REST CALL):

          http://IP:8080/jbpm-console/rest/runtime/org.jbpm:HR:1.0/process/instance/1/variables

           

          What I get is the following

           

           

          <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

          <exception>

              <status>FAILURE</status>

              <url>http://IP:8080/jbpm-console/rest/runtime/org.jbpm:HR:1.0/process/instance/1/variables</url>

              <message>NotFoundException thrown with message 'Could not find resource for full path: http://IP:8080/jbpm-console/rest/runtime/org.jbpm:HR:1.0/process/instance/1/variables'</message>

              <stackTrace>javax.ws.rs.NotFoundException: Could not find resource for full path: http://IP:8080/jbpm-console/rest/runtime/org.jbpm:HR:1.0/process/instance/1/variables

              at org.jboss.resteasy.core.registry.SegmentNode.match(SegmentNode.java:112)

              at org.jboss.resteasy.core.registry.RootNode.match(RootNode.java:43)

              at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48)

              at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:444)

              at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:234)

              at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:171)

              at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)

              at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)

              at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)

              at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)

              at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)

              at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130)

              at org.jboss.solder.servlet.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:65)

              at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)

              at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)

              at org.jboss.solder.servlet.event.ServletEventBridgeFilter.doFilter(ServletEventBridgeFilter.java:74)

              at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)

              at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)

              at org.kie.remote.services.rest.jaxb.DynamicJaxbContextFilter.doFilter(DynamicJaxbContextFilter.java:29)

              at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)

              at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)

              at org.jbpm.designer.web.filter.impl.PluggableFilter.doFilter(PluggableFilter.java:70)

              at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)

              at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)

              at org.uberfire.security.server.UberFireSecurityFilter.doFilter(UberFireSecurityFilter.java:283)

              at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)

              at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)

              at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)

              at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)

              at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)

              at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)

              at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)

              at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113)

              at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56)

              at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)

              at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51)

              at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)

              at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61)

              at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56)

              at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)

              at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)

              at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)

              at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)

              at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)

              at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)

              at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)

              at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240)

              at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227)

              at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73)

              at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146)

              at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177)

              at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727)

              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)

          </stackTrace>

          </exception>

           

          There are no differences between existing process instance id and not, I have the same error.

           

          Is it a bug? Any workaround?

          • 2. Re: Unable to get ProcessInstance variables from Java Rest  API
            Antonio Giambanco Novice

            Hi Maciej Swiderski,

            I found out that there are many post on it and some bugs on jira . . .

            I changed library with those updated but still not working

             

             


            • 3. Re: Unable to get ProcessInstance variables from Java Rest  API
              Maciej Swiderski Master

              what version do you use and what's the exact steps you perform. I'll try to investigate based on this as it should indeed work.

               

              When looking at the source of REST in 6.1 there seems to missing such resource to gather all process variables. Instead you would need to take it by variable name. Mind that this was very quick investigation and might not be complete.

               

              HTH

              • 4. Re: Unable to get ProcessInstance variables from Java Rest  API
                Gianluca Galantucci Newbie

                Hi Maciej,

                 

                We use JBPM 6.1.

                 

                The exect steps we perform are the following:

                 

                To create and start the processInstance:

                 

                RemoteRuntimeEngineFactory restSessionFactory  = new RemoteRestRuntimeEngineFactory(deploymentId, instanceUrl, user, password);

                RemoteRuntimeEngine engine = restSessionFactory.newRuntimeEngine();

                KieSession ksession = engine.getKieSession();

                 

                Map<String, Object> parameters = new HashMap<String, Object>();

                String inputData = "INPUT_DATA";

                parameters.put("VAR_NAME", inputData);

                 

                ProcessInstance processInstance = ksession.startProcess("PROCESS_ID", parameters);

                 

                To retrieve the process variables:

                 

                RemoteRuntimeEngineFactory restSessionFactory= new RemoteRestRuntimeEngineFactory(deploymentId, instanceUrl, user, password);

                RemoteRuntimeEngine engine = restSessionFactory.newRuntimeEngine();

                KieSession ksession = engine.getKieSession();

                TaskService taskService = engine.getTaskService();

                 

                List<TaskSummary> tasks = taskService.getTasksOwned("USER", "en-UK");

                for (TaskSummary task : tasks) {

                            JaxbTaskSummary taskImpl = (JaxbTaskSummary) task;

                            Task taskData = taskService.getTaskById(taskImpl.getId());


                               ProcessInstance processInstance = ksession.getProcessInstance(taskImpl.getProcessInstanceId());

                               CommandBasedStatefulKnowledgeSession session = (CommandBasedStatefulKnowledgeSession)ksession;

                               FindVariableInstancesCommand cmd2 = new FindVariableInstancesCommand(processInstance.getId(), "VAR_NAME");

                               Object result2 = session.execute(cmd2);

                }


                At that point we receive the NullPointerException of the first post.

                 

                Thanks,

                Gianluca

                • 5. Re: Re: Unable to get ProcessInstance variables from Java Rest  API
                  Antonio Giambanco Novice

                  Hi Maciej ,

                  I'm using jbmpm6.1.0Finale that I got from here

                  I deployed demo HR as it is in the examples repository, I started an instance from console inserting a name, then I made these two tests:

                  1. From tool able to make rest call I tryed to execute this command http://IP:8080/jbpm-console/rest/runtime/org.jbpm:HR:1.0/process/instance/1/variables
                    • I was expecting to find at least process variable "name", but I got an exception as mentiond in my last post
                  2. From a java class developed with eclipse executing this code

                  FindVariableInstancesCommand cmd = new FindVariableInstancesCommand(processInstance.getId(), "name");

                  Object result = ksession.execute(cmd);

                   

                  In both cases I get the same exception error

                   

                  Thanks

                  • 6. Re: Re: Re: Unable to get ProcessInstance variables from Java Rest  API
                    Maciej Swiderski Master

                    guys, take a look at attached maven project that simply uses FindVariableInstancesCommand with 6.1.0.Final and it does work fine. It targets jbpm-console installed with jbpm-installer and assumes HR process is deployed.

                     

                    HTH

                    • 7. Re: Unable to get ProcessInstance variables from Java Rest  API
                      Gianluca Galantucci Newbie

                      Hi Maciej,

                      thank you for your response.

                      I executed your code and effectively it does work.

                      I think we had some conflict on the imported libraries of our client project. I will investigate further on this.

                       

                      But if I start my instanceProcess passing in the parameters a generic Object and not a simple string, is it possible to retrieve the effective Object in some way?

                       

                      Something like this:

                       

                      MyObject inputData = new MyObject();

                      parameters.put("VAR_NAME", inputData);


                      and subsequently retrieve MyObject inputData from the processInstance.


                      • 8. Re: Unable to get ProcessInstance variables from Java Rest  API
                        Maciej Swiderski Master

                        you should be able to do it with direct REST operation on /process/instance/{procInstId}/variable/{varName}  and that should return the actual variable serialized with JAXB

                         

                        HTH