Activti-REST - calling via Apache http client

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2015 05:21 AM
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
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
Labels:
- Labels:
-
Archive
2 REPLIES 2

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2015 08:19 AM
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,
Best regards,

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2015 10:00 AM
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>
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>
