cancel
Showing results for 
Search instead for 
Did you mean: 

Activti-REST - calling via Apache http client

shrey
Champ in-the-making
Champ in-the-making
Hi,

I have been facing 403 exception while using [Spring Rest template + Apache httpClient] to call REST api.  –> rest class.txt
The same call works if I use Spring Rest template + common httpClient. –> rest class - commons.txt

Please find class attached for source code.
Can you please help me understand the difference that may cause the issue?

Thanks,
Shrey
2 REPLIES 2

trademak
Star Contributor
Star Contributor
I don't see any specific code line that would make a difference. I don't think it's the Activiti API causing this issue though, but some faulty REST client call.

Best regards,

shrey
Champ in-the-making
Champ in-the-making
There no change in the rest call once restTemplate Object is returned back.
e.g. Here is POST methods that is used . RestUtil.getRestTemplate() just gets the restTemplate back


<code>
public JSONObject post(String url, JSONObject payload,
   Map<String, String> uriMap) throws Exception {
  logger.info("Executing rest call to url: " + url + ", with payload"
    + payload.toString());
  RestTemplate restTemplate = RestUtil.getRestTemplate();
  HttpHeaders headers = new HttpHeaders();
  headers.setContentType(MediaType.APPLICATION_JSON);
  headers.setAccept(Collections.singletonList(new MediaType(
    "application", "json")));
  HttpEntity<String> request = new HttpEntity<String>(payload.toJSONString(), headers);
  ResponseEntity<String> responseEntity = null;
  if (uriMap != null) {
   responseEntity = restTemplate.postForEntity(url, request,
     String.class, uriMap);
  } else {
   responseEntity = restTemplate.postForEntity(url, request,
     String.class);
  }
  logger.debug("Response Status Code: " + responseEntity.getStatusCode());
  String response = responseEntity.getBody();
  JSONObject wfResponse = null;
  try {
   Object jsonResponse = new JSONParser().parse(response);
   wfResponse = (JSONObject) jsonResponse;
   logger.debug(wfResponse.toJSONString());
  } catch (ParseException e) {
   logger.error(ExceptionUtils.getFullStackTrace(e));
   throw e;
  }
  logger.debug(wfResponse.toJSONString());
  return wfResponse;
}
</code>