Mapping error after connector

Hi Community

I am starting off with Bonita BPM. The following case is just a test for me to get started with the software. So it does not have to make sense :slight_smile:

I have written a connector for calling a REST API.
In the process, I have added a Task with Type Service where I added the Connector in the “Connectors In” tab.
The returned value of the connector is then mapped to a pool variable. Both have the type “TagiResultat” which has been defined as a Business Data Model (BDM).

When the connector is being tested, It throws the following error:

java.lang.reflect.InvocationTargetException
com.thoughtworks.xstream.converters.ConversionException: org.mycompany.model.TagiResultat : org.mycompany.model.TagiResultat
---- Debugging information ----
message : org.mycompany.model.TagiResultat
cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : org.mycompany.model.TagiResultat
class : java.util.HashMap
required-type : java.util.HashMap
converter-type : com.thoughtworks.xstream.converters.collections.MapConverter
path : /map/entry/org.mycompany.model.TagiResultat
line number : 5
version : null
–.–.–.–.–.–.–.–.–.–.–.–.–.
com.thoughtworks.xstream.mapper.CannotResolveClassException: org.mycompany.model.TagiResultat

The Business Data Model is set up as this:

  • TagiResultat
    ** comments: TagiComment, Multiple
    ** name: STRING
    ** firstname: STRING
  • TagiComment
    ** articleId: STRING
    ** lastName: STRING
    ** city: STRING

If I interpret the error correctly, it has a problem to map the returned value of the connector to the pool variable. But why? They have the same BDM/JavaClass behind it. I have also not used any (Hash)Map. The only thing close to a Map are the comments. They are of type list. In the connector the comments are populated as an ArrayList, which implements the List interface. So I do not understand why there is a problem during the mapping process. Can somebody support me here?

And is it the right approach to call a custom connector in a Service Typed Task?

Thank you for any help!

I think the reason is that the Bonita Studio test component tries to show you the result, but does not know how to present it. In process runtime it should work.

You can convert the test result yourself by changing connector output to script mode and, for example jsonize it:
new JsonBuilder(result).toPrettyString()

Thank you mmichalak for the response.
The process is also not working. I thought that is because of the error as described above.
I also tried to add the total result of the REST call to the BDM as a STRING or TEXT. But fields on BDM’s are restricted to a length of 255 characters. And the return value of the call is way longer than that.

To add some more flesh to the bone:

My Process
In my process, I added the contract definition and a form with 2 text inputs (name and firstname, just for testing) to the pool. I also added the actors.

After that I want to perform the REST call. So I added a task with the Task Type set to Service. In the Connectors In, I added my connector.
The connector binds the results to a Pool variable. It returns a TagiResult as described in the first post, with the name and firstname from the first form, and the comments from the REST call.

After the Task with the Type Service, I added a new Human Task for a user to choose one object of the list returned by the connector. Therefore I added the contract definition and another form.

And at the end is an End Event.

Problem
When I run the process from within Bonita, I get the first form. When I submit that form, I get redirected to the Portal, but no Task is added to the Portal for the second Human Task.

No errors can be found in the engine log.
So if the error is not related to my custom connector, what am I doing wrong here?
Do I understand it correctly, that a Task should be added after the first form has been submitted and the connector has been invoked (before the second human task)?

Hey mmichalak

I did not understand your advice at first. But I tried it now.
In the output operations, I defined the following groovy script to map the TagiResultat to a STRING variable:

import groovy.json.JsonBuilder

new JsonBuilder(data).toPrettyString()

When I test the connector with this configuration, I get a popup after the connector is executed and it shows the serialized content of the TagiResultat.
At the top of the popup, it states: “For unserializable output, you can transform it into a serializable object using the output expression editor.”
But I think I don’t have to worry about this message…

I also tried to add a groovy script that does the mapping between the returned TagiResultat to the TagiResultat of the BDM with the following script:

import groovy.json.JsonBuilder
import org.mycompany.model.TagiComment
import org.mycompany.model.TagiResultat

def mappedData = new TagiResultat()
for (comment in data.getComments()) {
def tempComment = new TagiComment()
tempComment.articleId = comment.articleId
tempComment.lastName = comment.lastName
tempComment.city = comment.city
mappedData.comments.add(tempComment)
}
return mappedData

But then the same error pops up as shown in the first post. But this was kind of expected.

This indicates to me, that the connector is working. What is wrong then?

What I forgot the mention…
I fired up Wireshark once to check, when I run the process, if the REST call is executed. And it is not. When I test the connector, the REST call is shown in Wireshark.

ok I am so sorry. This is kind of embarrassing. But it is working now, and I do not know what I have changed to got it running…
The connector is still returning a TagiResultat and it is mapped by Bonita, without a Groovy script. In Wireshark I see that the request is fired. It needs some seconds to show up in the Portal. But it is working…

mmichalak, thank you very much for your help. Really appreciated!

I got another question now. Trying to display the comments in a Table in a UIForm. Should I state my question here, so we keep the context of my setup, or should I create a new Q?

Kind regards

  1. You can increase the acceptable length of strings in your BDM
  2. Your process flow seems to be fine, although you could probably get rid of the service task by moving the connector instantiating TagiResult to pool’s Connector In.
  3. Did you fix the error described in your first post? Did you understand and try solution proposed by me? After resolving it you would be able to detect other potential errors by testing this connector.