task complete using spring rest template

854 views
Skip to first unread message

kashya...@gmail.com

unread,
Mar 10, 2015, 5:52:14 AM3/10/15
to camunda-...@googlegroups.com
Hi,

I am trying to complete a task using rest template. below is the code that i am using.

restTemplate = (RestTemplate)this.getApplicationContext().getBean("restTemplate");
messageConverters = new ArrayList<HttpMessageConverter<?>>();
con = new MappingJacksonHttpMessageConverter();
messageConverters.add(con);
restTemplate.setMessageConverters(messageConverters);

JSONObject procVars = new JSONObject().put("variables", userMap);
HttpEntity response = restTemplate.postForObject(url, procVars, HttpEntity.class);

Here JSONObject is camunda json object. userMap is the map in which I am passing all the process variables.

While executing this code I am getting the exception mentioned below:

org.springframework.web.client.RestClientException: Could not write request: no suitable HttpMessageConverter found for request type [org.camunda.bpm.engine.impl.util.json.JSONObject]

Problem is that MappingJacksonHttpMessageConverter converts the data into javax JsonObject but i need it to convert the data in camunda JSONObject.

Is there any converter class that can solve my problem or is there any other way to do this.

Thanks in advance.

thorben....@camunda.com

unread,
Mar 10, 2015, 6:09:21 AM3/10/15
to camunda-...@googlegroups.com
Hi,

Please do not use the engine-internal class JSONObject for your purpose. It is not intended to be used in that way and is internal, meaning that its structure may change in future releases.

What happens if you replace the JSONObject by a plain java map?

Cheers,
Thorben

anish kashyap

unread,
Mar 10, 2015, 6:41:28 AM3/10/15
to camunda-...@googlegroups.com
When i am using a java map, i am getting propertynotfound exception. All the variables are  present in the map then too i am getting this exception. 


In the above link i found that camunda rest api expects a json object with name 'variables' to complete a task.

thorben....@camunda.com

unread,
Mar 10, 2015, 6:52:46 AM3/10/15
to camunda-...@googlegroups.com
Hi,

Though both named "json object", the term refers in the REST API to a different thing than the class JSONObject in the Java project.

In the REST API, "json object" refers to a HTTP request body that contains a JSON object, that means a body like

{
  variables : {"variableName" : {"value" : "aStringValue"}}
}

The JSONObject class is used internally to represent serialized JSON but it is not designed to be used with client libraries like Spring RestTemplate.

To me it occurs that your problem is rather related to RestTemplate. You need to figure out how to post JSON and in particular a JSON object that serializes to the format in the above example. This is a problem unrelated to Camunda and we cannot really help you here due to lack of experience with RestTemplate.

Cheers,
Thorben
Reply all
Reply to author
Forward
0 new messages