1
votes

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

" "Unexpected HTTP response code when requesting URI

'http://localhost:8080/kie-server/services/rest/server/containers/QuoteManagedRules_1.0.0-SNAPSHOT/processes/QuoteManagedRules.quoteManagedRules/instances'!

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\"","

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);
}

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 ?

2

2 Answers

0
votes

You have to add the Custom class in the Kie-deployment-descriptor.xml under remoteable classes like

<remoteable-classes>
     <remoteable-class>com.myspace.quotemanagedrules.QuoteDto</remoteable-class>
</remoteable-classes>

In case JBPM does not find the the class to be mapped either in Kjars,dependencies or under remoteable, it tries to treat the de -serialized object as a hashmap and hence the error

0
votes

You have to define the input object as a Data structure and add it as a variable in the Process model