I have Springboot app that talks to Alfresco Enterprise Activiti using REST calls.
I want to start the process instance using REST call but I am getting 400 bed request. however the same request works with postman.
String url = "http://localhost:9091/activiti-app/api/enterprise/process-instances";
RestTemplate restTemplate = new RestTemplate();
restTemplate.getInterceptors().add(new BasicAuthorizationInterceptor("admin@app.activiti.com", "admin"));
HttpHeaders headers = new HttpHeaders();
headers.setContentType(org.springframework.http.MediaType.APPLICATION_JSON);
HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);CreateProcessInstanceRepresentation cpir = new CreateProcessInstanceRepresentation ();
cpir.setName("ClientReview");
cpir.setProcessDefinitionId("ClientReview:7:15103");
ObjectMapper mapper = mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
json = mapper.writeValueAsString(cpir);
JsonNode jsonNode = mapper.readTree(json);restTemplate.exchange(url, HttpMethod.POST, entity, Object.class, jsonNode); // Throws 400 Bad Request
Please help..
Thank you in advance...
Solved! Go to Solution.
Hi,
Please find below some working code snippet for the starting of Activiti Process instance using REST.
Code:
String urlString = "http://localhost:8080/activiti-app/api/enterprise/process-instances";
String propertiesJson = ""; //If you have any form fields to start the form
PostMethod mPost = null;
HttpClient client = new HttpClient();
mPost = new PostMethod(urlString);
String encoding = Base64.getEncoder().encodeToString("admin@app.activiti.com:admin".getBytes());
mPost.setRequestHeader("Authorization", "Basic " + encoding);
mPost.setRequestHeader("Content-Type", "application/json");
mPost.setRequestEntity(new ByteArrayRequestEntity(propertiesJson.getBytes()));
int statusCode = client.executeMethod(mPost);
System.out.println("Response Code:::"+statusCode);
===========================================
Imports:
import org.apache.commons.httpclient.HttpClient;
import java.util.Base64;
import org.apache.commons.httpclient.methods.PostMethod;
Hope this helps.
Thanks,
Naveen
Hi,
Please find below some working code snippet for the starting of Activiti Process instance using REST.
Code:
String urlString = "http://localhost:8080/activiti-app/api/enterprise/process-instances";
String propertiesJson = ""; //If you have any form fields to start the form
PostMethod mPost = null;
HttpClient client = new HttpClient();
mPost = new PostMethod(urlString);
String encoding = Base64.getEncoder().encodeToString("admin@app.activiti.com:admin".getBytes());
mPost.setRequestHeader("Authorization", "Basic " + encoding);
mPost.setRequestHeader("Content-Type", "application/json");
mPost.setRequestEntity(new ByteArrayRequestEntity(propertiesJson.getBytes()));
int statusCode = client.executeMethod(mPost);
System.out.println("Response Code:::"+statusCode);
===========================================
Imports:
import org.apache.commons.httpclient.HttpClient;
import java.util.Base64;
import org.apache.commons.httpclient.methods.PostMethod;
Hope this helps.
Thanks,
Naveen
Ask for and offer help to other Alfresco Process Services and Activiti Users and members of the Alfresco team.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.