2 Replies Latest reply on Aug 11, 2011 10:06 PM by tomcheng76

    jbpm5:Failed to set process variables

    jack pan Newbie

      Customize rest method in gwt-console-server.war:

      @PUT
      @Path("instance/{id}/addInstanceData")
      @Consumes("multipart/form-data")
      public Response addInstanceData(
      @PathParam("id")
      String instanceId,
      Map<String, String> processVars){
        try {
         Map<String,Object> params = new HashMap<String, Object>();
         params.put("testkey", "testValue");
        
         getProcessManagement().setInstanceData(instanceId, params);
         return Response.ok().build();
        } catch (Throwable t) {
         throw new WebApplicationException(t, 500);
        }
      }

      private ProcessManagement getProcessManagement() {
        if (null == this.processManagement) {
         ManagementFactory factory = ManagementFactory.newInstance();
         this.processManagement = factory.createProcessManagement();
         log.debug("Using ManagementFactory impl:"
           + factory.getClass().getName());
        }
        return this.processManagement;
      }

       

       

      Throws the following error:

      2011-06-13 20:17:35,468 INFO  [STDOUT] (http-0.0.0.0-8080-4) Hibernate: select processins0_.InstanceId as InstanceId54_0_, processins0_.lastModificationDate as lastModi2_54_0_, processins0_.lastReadDate as lastRead3_54_0_, processins0_.processId as processId54_0_, processins0_.processInstanceByteArray as processI5_54_0_, processins0_.startDate as startDate54_0_, processins0_.state as state54_0_, processins0_.OPTLOCK as OPTLOCK54_0_ from ProcessInstanceInfo processins0_ where processins0_.InstanceId=?
      2011-06-13 20:17:35,484 INFO  [STDOUT] (http-0.0.0.0-8080-4) Hibernate: update ProcessInstanceInfo set lastModificationDate=?, lastReadDate=?, processId=?, processInstanceByteArray=?, startDate=?, state=?, OPTLOCK=? where InstanceId=? and OPTLOCK=?
      2011-06-13 20:17:35,500 INFO  [STDOUT] (http-0.0.0.0-8080-4) 20:17:35,484 ERROR [SynchronousDispatcher] failed to execute
      javax.ws.rs.WebApplicationException: java.lang.NullPointerException
       at org.jboss.bpm.console.server.CustomFacade.addInstanceData(CustomFacade.java:92)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)
       at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:117)
       at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:260)
       at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:232)
       at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:166)
       at org.jboss.resteasy.core.DispatcherUtilities.getJaxrsResponse(DispatcherUtilities.java:142)
       at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356)
       at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:173)
       at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:93)
       at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:68)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.jboss.bpm.console.server.util.GWTJsonFilter.doFilter(GWTJsonFilter.java:59)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
       at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
       at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
       at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
       at java.lang.Thread.run(Thread.java:619)
      Caused by: java.lang.NullPointerException
       at org.jbpm.process.instance.impl.ProcessInstanceImpl.getProcess(ProcessInstanceImpl.java:67)
       at org.jbpm.process.instance.impl.ProcessInstanceImpl.getContextInstance(ProcessInstanceImpl.java:127)
       at org.jbpm.integration.console.CommandDelegate.setProcessInstanceVariables(CommandDelegate.java:270)
       at org.jbpm.integration.console.ProcessManagement.setInstanceData(ProcessManagement.java:96)
       at org.jboss.bpm.console.server.CustomFacade.addInstanceData(CustomFacade.java:88)
       ... 38 more
      
      

      Any idea anyone?

      Thanks

        • 1. Re: jbpm5:Failed to set process variables
          tomcheng76 Newbie

          Same here.

           

          After tracing the code, i found that the kruntime changed to null suddenly...

           

          kruntime is set previously. but it changed to null when calling getProcess()

           

          To test it:

           

          Add the following to org.jboss.bpm.console.server.ProcessMgmtFacade.java in jbpm-gwt-console-server

            @POST

            @Consumes("multipart/form-data")

            @Path("instance/{id}/data")

            public Response setInstanceData(

                                @Context

                                HttpServletRequest request,

                                @PathParam("id")

                                String instanceId

            )

            {

           

           

                      try {

                          ServletFileUpload upload = new ServletFileUpload();

                          FileItemIterator fileIterator = upload.getItemIterator(request);

                          while (fileIterator.hasNext()) {

                              FileItemStream item = fileIterator.next();

                              log.info("Setting Process instance data: Content-Type: " + item.getContentType() + " Name: " + item.getFieldName());

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

                             

                              if (item.getContentType() == null){

                                  String s = IOUtils.toString(item.openStream());

                                  data.put(item.getFieldName(), s);

                              } else {

                                        File f = File.createTempFile("file-", "");

                                  IOUtils.copy(item.openStream(), new FileOutputStream(f));

                                  data.put(item.getFieldName(), f.getCanonicalPath());

                              }

                              getProcessManagement().setInstanceData(instanceId, data);

                          }

                      } catch (Exception e) {

                    log.info("cannot set instance data", e);

                      }

                ProcessInstanceRef instance = getProcessManagement().getProcessInstance(instanceId);

                return createJsonResponse(instance);

            }

           


          then post something to gwt-console-server/rs/process/instance/{yourinstanceid}/data

           

          NullPointerException @ setInstanceData

          • 2. Re: jbpm5:Failed to set process variables
            tomcheng76 Newbie

            Anyone know why in org.jbpm.integration.console.CommandDelegate

             

            public Map<String, Object> getProcessInstanceVariables(String processInstanceId) {

            ProcessInstance processInstance = ksession.getProcessInstance(new Long(processInstanceId));

             

            The processInstance does not contains kruntime nor process? they are both null.

             

            Why is this happening? i would like to know how to solve this problem since i cannot do any setVariable on it.

             

            can i create kruntime and process and insert back to processInstance ? If i can, please tell me how to do..............

             

            Thanks in advance...

             

            Please help as i am already out of idea....comment is welcomed...