使用自定义流程变量启动JBPM流程中的问题 [英] Issue in Starting JBPM process with custom process variable
问题描述
我已经在JBPM中创建了具有规则和人工任务的业务流程的工作流.工作流接受过程变量,该过程变量是客户对象(类名Quote).如果我使用Kie Workbech启动工作流程,则可以正常工作,但是当我尝试从Client API的REST API启动流程时,会向我发送错误消息
I have created a workflow in JBPM with business flow having rules and Human task . The workflow accepts a process variable which is a customer object ( Class name Quote) . If I start the workflow using Kie Workbech ,it works fine but when I am trying to start the process from REST API of the Client API , is sends me error as
"请求URI时出现意外的HTTP响应代码
" "Unexpected HTTP response code when requesting URI
错误代码:500,消息:\无法创建响应:[QuoteManagedRules.quoteManagedRules:181-收到的报价:7]-无法将java.util.LinkedHashMap强制转换为com.myspace.quotemanagedrules.QuoteDto \","
Error code: 500, message: \"Unable to create response: [QuoteManagedRules.quoteManagedRules:181 - Quote received:7] -- java.util.LinkedHashMap cannot be cast to com.myspace.quotemanagedrules.QuoteDto\"","
我尝试调试并发现它不是自定义对象,如果我使用String或任何其他文字,则可以正常工作,但将过程变量用作Object,则显示错误
I have tried debugging and turn out that instead of a custom object , if I using String or any other literals it works fine but with the process variable as an Object , it shows error
public static final String SERVER_URL="http://localhost:8080/kie-server/services/rest/server";
public static final String LOGIN="wbadmin";
public static final String PASSWORD="wbadmin";
public static final String CONTAINER="QuoteManagedRules_1.0.0-SNAPSHOT";
public static final String processId="QuoteManagedRules.quoteManagedRules";
public static void startProcess() {
//Client configuration setup
KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(SERVER_URL, LOGIN, PASSWORD);
//Add custom classes, such as Obj.class, to the configuration
Set<Class<?>> extraClassList = new HashSet<Class<?>>();
extraClassList.add(QuoteDto.class);
config.addExtraClasses(extraClassList);
config.setMarshallingFormat(MarshallingFormat.JSON);
// ProcessServicesClient setup
KieServicesClient client = KieServicesFactory.newKieServicesClient(config);
ProcessServicesClient processServicesClient = client.getServicesClient(ProcessServicesClient.class);
// Create an instance of the custom class
QuoteDto obj = new QuoteDto();
obj.setAccountId("1");
obj.setCorrelationId("1");
obj.setId("12");
obj.setOppurtunityId("123");
obj.setOppurtunityName("sattu");
obj.setPrice(123);
obj.setRevision(12);
obj.setVersion("12");
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("quote", obj);
// Start the process with custom class
processServicesClient.startProcess(CONTAINER, processId, variables);
}
以上代码应启动该过程.请让我知道如何解决此问题.我是否还需要在其他任何地方都引用Quote类,以便像在kmodule.xml中那样正确地映射它?
The above code should start the process . Please let me know how to fix this . Do I need to mention the Quote Class anywhere else as well in order to map it correctly like in kmodule.xml or so ?
推荐答案
您必须将输入对象定义为Data结构,并将其添加为Process模型中的变量
You have to define the input object as a Data structure and add it as a variable in the Process model
这篇关于使用自定义流程变量启动JBPM流程中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!