07-25-2017 11:10 AM
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...
07-26-2017 11:48 AM
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
07-26-2017 11:48 AM
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
Explore our Alfresco products with the links below. Use labels to filter content by product module.