14 Replies Latest reply on Mar 26, 2013 7:35 AM by Ouadi BELMOKHTAR

    How to properly use ContentMarshallerHelper for Human Task Output in JBPM5.3?

    Thomas Setiabudi Expert

      Hi,

       

      I have one output on my human task, the output is of type String, and I map this output to one of the process variable.

      The problem is, the mapped value becomes:

      MarshalledContentWrapper{content=[B@342371e7, marshaller=org.drools.marshalling.impl.SerializablePlaceholderResolverStrategy, type=class java.lang.String}

       

      how to make it resolve correctly to the String value?

       

      here is my code

       

      1. Map<String, Object> taskOutput = new HashMap<String, String>(1);

      2.                         taskOutput.put("EvaluationResult",

      3.                                         "good");

      4.  

      5.                         ContentData contentData = new ContentData();

      6. contentData = ContentMarshallerHelper.marshal(taskOutput,

      7.                                         new ContentMarshallerContext(), null);

      8.  

      9. taskClientHelper.completeTask(taskId.longValue(),

      10.                                         userId, contentData);

       

      Any help is appreciated.

       

       

      Best Regards,

      Thomas Setiabudi

        • 1. Re: How to properly use ContentMarshallerHelper for Human Task Output in JBPM5.3?
          Maciej Swiderski Master

          Thomas, please make sure that both sides uses ContentMarshallerHelper to read/write the content. By both sides I mean code that sets the content when completing task and the code that reads it based on the completion event - which is HT work item handler.

           

          HTH

          • 2. Re: How to properly use ContentMarshallerHelper for Human Task Output in JBPM5.3?
            Thomas Setiabudi Expert

            Hi Maciej,

             

            Thank you, I got your point. so because the marshaller and unmarshaller is not the same, the byte array cannot be converted back to String right.

             

            In my case, I use JBPM Console to control the flow. The source code that reads the completion event should be in? AsyncHornetQHTWorkItemHandler?

             

            I still cannot find the code >.<

             

             

            Regards,

            Thomas Setiabudi

            • 3. Re: How to properly use ContentMarshallerHelper for Human Task Output in JBPM5.3?
              Thomas Setiabudi Expert

              I found this lines of code in AsyncWSHumanTaskHandler.java

               

               

               public void execute(Content content) {
                              Object result = ContentMarshallerHelper.unmarshall( content.getContent(), env);
                              results.put("Result", result);
                              if (result instanceof Map) {
                                  @SuppressWarnings("rawtypes")
                   Map<?, ?> map = (Map) result;
                                  for (Map.Entry<?, ?> entry : map.entrySet()) {
                                      if (entry.getKey() instanceof String) {
                                          results.put((String) entry.getKey(), entry.getValue());
                                      }
                                  }
                              }
                              manager.completeWorkItem(task.getTaskData().getWorkItemId(), results);
                      }
              
              

               

               

              If this is the code in jbpm console that listens to the task complete event, it means it uses ContentMarshallerHelper too..

              • 4. Re: How to properly use ContentMarshallerHelper for Human Task Output in JBPM5.3?
                Thomas Setiabudi Expert

                Hi,

                 

                Its solved for me now as I switch to JBPM5.4 Final.

                 

                in JBPM5.3 Final, I think the cause of my problem is the ContentMarshallerHelper takes a second parameter of type ContentMarshallerContext. this parameter value may be different by the one used by the code who handles completed task.

                 

                 

                Regards,

                Thomas Setiabudi

                • 5. Re: How to properly use ContentMarshallerHelper for Human Task Output in JBPM5.3?
                  星兰 蒋 Newbie

                  Hi Thomas,Would you please give me some advice that how you solve this convert issues?I meet the same problems too.

                  • 6. Re: How to properly use ContentMarshallerHelper for Human Task Output in JBPM5.3?
                    Thomas Setiabudi Expert

                    Hi,

                     

                    I moved to jbpm5.4 and it solves the issue since the marshal(..) function only needs 2 arguments now:

                     

                    I refer to this code

                    https://github.com/droolsjbpm/jbpm/blob/master/jbpm-examples/src/main/java/org/jbpm/examples/humantask/HumanTaskExample.java

                     

                    Map<String, Object> results = new HashMap<String, Object>();  
                                results.put("comment", "Agreed, existing laptop needs replacing");
                                results.put("outcome", "Accept");
                                ContentData contentData = ContentMarshallerHelper.marshal(results,  null);
                    
                                taskClient.complete(task1.getId(), "sales-rep", contentData);
                    
                    

                     

                     

                    For JBPM5.3 I am not sure if it can be solved by passing null to second marshal(..) function variable. But maybe you can give that a try.

                     

                    Regards,

                    Thomas Setiabudi

                    • 7. Re: How to properly use ContentMarshallerHelper for Human Task Output in JBPM5.3?
                      星兰 蒋 Newbie

                      Hi, as the example, i get a map like this:

                       

                      contractno = MarshalledContentWrapper{content=[B@53e36ec6, marshaller=org.drools.marshalling.impl.SerializablePlaceholderResolverStrategy, type=class java.lang.String}
                      details = MarshalledContentWrapper{content=[B@787db430, marshaller=org.drools.marshalling.impl.SerializablePlaceholderResolverStrategy, type=class java.lang.String}

                       

                      then,how can i translate them to strings?

                      the "contractno " and "details " are the vars.

                      i'm looking forward your reply.

                       

                      Thanks and Best Regards. 

                      • 8. Re: How to properly use ContentMarshallerHelper for Human Task Output in JBPM5.3?
                        Thomas Setiabudi Expert

                        Hi,

                         

                        How do you marshall them?

                         

                        And how do you unmarshall them?

                         

                        is the unmarshaller JBPM Console? or you create your own application?

                         

                        in my case, I created my own taskClient application that calls ContentMarshallerHelper.marshal(results,  null);
                        then it is the jbpm console who calls ContentMarshallerHelper.unmarshal(result,  env);

                        • 9. Re: How to properly use ContentMarshallerHelper for Human Task Output in JBPM5.3?
                          星兰 蒋 Newbie

                          Thomas,你是在北京吗?我们可能会有点不同。在我的案例中,其实我是想在执行完成任务步骤前获取我启动流程时所传的参数。我没有使用jbpm console

                          • 10. Re: How to properly use ContentMarshallerHelper for Human Task Output in JBPM5.3?
                            星兰 蒋 Newbie

                            您方便留个电话吗?我想电话联系下您沟通一下。

                            • 11. Re: How to properly use ContentMarshallerHelper for Human Task Output in JBPM5.3?
                              Thomas Setiabudi Expert

                              Hi

                               

                              I am sorry I cant understand your languange.

                               

                              If you have different case (used google translate )

                               

                              then maybe you want to open another discussion thread for your case.

                               

                               

                              Regards,

                              Thomas Setiabudi

                              • 12. Re: How to properly use ContentMarshallerHelper for Human Task Output in JBPM5.3?
                                星兰 蒋 Newbie

                                Hi Thomas, I'm sorry i thought you were in Beijing.

                                 

                                In my case,in fact i want to get the vars's value when i get a task by userid. And these values are passed when i start a processinstance.

                                 

                                i set & get values all in myself application. no using the jbpm console.  Also no using marshall and unmarshall.

                                 

                                Set values when start process:

                                 

                                Map<String,Object> params = new HashMap<String,Object>();
                                   params.put("sales", c.getCreateby());
                                   params.put("contractno", c.getContractno());
                                   params.put("details", c.getDetails());
                                   params.put("amount", c.getAmount());
                                   params.put(role.getRole(), leader.getName());
                                   params.put("accoptor", list.get(0).getName());
                                  

                                getSession().startProcess(definitionId, params);

                                 

                                 

                                Get values when get a task by userid:

                                 

                                List<TaskSummary> t = sTaskService.getTasksAssignedAsTaskInitiator(idRef, "en-UK");

                                 

                                   if(null != t && t.size() > 0){
                                   
                                    for(TaskSummary ts : t){
                                     Object obj = getTaskContentInput(ts);
                                     Map<?, ?> map = (Map<?, ?>) obj;           
                                     for (Map.Entry<?, ?> entry : map.entrySet()) {               
                                      System.out.println(entry.getKey() + " = " + entry.getValue());           
                                     }
                                     tasks.add(new TaskRef(ts.getId(), ts.getProcessInstanceId() + "", ts.getProcessId(),
                                       ts.getName(), ts.getCreatedBy().getId(), ts.getStatus() == Status.Suspended, ts.getStatus() != Status.Suspended));
                                    }
                                   
                                   }

                                 

                                And the getTaskContentInput method as blow:

                                 

                                public Object getTaskContentInput(TaskSummary taskSum) {

                                         BlockingGetTaskResponseHandler handlerT = new BlockingGetTaskResponseHandler();

                                         client.getTask(taskSum.getId(), handlerT);

                                         Task task2 = handlerT.getTask();

                                         TaskData taskData = task2.getTaskData();

                                         BlockingGetContentResponseHandler handlerC = new BlockingGetContentResponseHandler();

                                         client.getContent(taskData.getDocumentContentId(), handlerC);

                                         Content content = handlerC.getContent();
                                         ByteArrayInputStream bais = new ByteArrayInputStream(

                                                         content.getContent());

                                         try {

                                                 ObjectInputStream is = new ObjectInputStream(bais);

                                                 Object obj = null;

                                 

                                                 while ((obj = is.readObject()) != null) {

                                                         System.out.println("OBJECT: " + obj);

                                                         return obj;

                                                 }

                                         } catch (Exception e) {

                                                 System.err.print("There was an error reading task input...");

                                                 e.printStackTrace();             

                                                 return null;

                                         }

                                         return null;

                                }

                                 

                                Is My way right or wrong? Would you pls give some advice?

                                 

                                Thanks and Best Regards!

                                • 13. Re: How to properly use ContentMarshallerHelper for Human Task Output in JBPM5.3?
                                  Dhaval Shah Newbie

                                  Hi even i am facing this issue...... i don't know about marshaller or any thing so can u plz help me

                                   

                                  now when it is calling the ftl file on reaCHING HUMAN TASK      it is showing this on jsp page

                                   

                                  Model Number: MarshalledContentWrapper{content=[B@1e0d7c5, marshaller=org.drools.marshalling.impl.SerializablePlaceholderResolverStrategy, type=class java.lang.String} Quantity: MarshalledContentWrapper{content=[B@75ffe5, marshaller=org.drools.marshalling.impl.SerializablePlaceholderResolverStrategy, type=class java.lang.String} Priority: MarshalledContentWrapper{content=[B@f31cdb, marshaller=org.drools.marshalling.impl.SerializablePlaceholderResolverStrategy, type=class java.lang.String}

                                   

                                  and then textboxes and submit button.

                                   

                                  when i submit it.

                                   

                                  i am getting this output on my console.

                                   

                                  Human Task Started....

                                  Exception in thread "Thread-2" java.lang.ClassCastException: java.lang.String cannot be cast to org.jbpm.task.utils.MarshalledContentWrapper

                                            at org.jbpm.task.utils.ContentMarshallerHelper.unmarshall(ContentMarshallerHelper.java:157)

                                            at org.jbpm.process.workitem.wsht.GenericHTWorkItemHandler$TaskCompletedHandler.handleCompletedTask(GenericHTWorkItemHandler.java:208)

                                            at org.jbpm.process.workitem.wsht.GenericHTWorkItemHandler$TaskCompletedHandler$1.run(GenericHTWorkItemHandler.java:187)

                                            at java.lang.Thread.run(Thread.java:679)

                                   

                                   

                                  how to resolve this issue can u plz help me on this

                                  • 14. Re: How to properly use ContentMarshallerHelper for Human Task Output in JBPM5.3?
                                    Ouadi BELMOKHTAR Newbie

                                    I'm also blocked with this problem, can any one help me to resolve it !!

                                     

                                    The problem is described in tis thread :

                                     

                                    https://community.jboss.org/message/804254