use of org.onap.so.apihandler.camundabeans.CamundaResponse in project so by onap.
the class RequestHandlerUtils method postBPELRequest.
public Response postBPELRequest(InfraActiveRequests currentActiveReq, RequestClientParameter requestClientParameter, String orchestrationUri, String requestScope) throws ApiException {
ObjectMapper mapper = new ObjectMapper();
ResponseEntity<String> response = postRequest(currentActiveReq, requestClientParameter, orchestrationUri);
ServiceInstancesResponse jsonResponse = null;
int bpelStatus = responseHandler.setStatus(response.getStatusCodeValue());
try {
responseHandler.acceptedResponse(response);
CamundaResponse camundaResponse = responseHandler.getCamundaResponse(response);
String responseBody = camundaResponse.getResponse();
if ("Success".equalsIgnoreCase(camundaResponse.getMessage())) {
jsonResponse = mapper.readValue(responseBody, ServiceInstancesResponse.class);
jsonResponse.getRequestReferences().setRequestId(requestClientParameter.getRequestId());
Optional<URL> selfLinkUrl = buildSelfLinkUrl(currentActiveReq.getRequestUrl(), requestClientParameter.getRequestId());
if (selfLinkUrl.isPresent()) {
jsonResponse.getRequestReferences().setRequestSelfLink(selfLinkUrl.get());
} else {
jsonResponse.getRequestReferences().setRequestSelfLink(null);
}
} else {
BPMNFailureException bpmnException = new BPMNFailureException.Builder(String.valueOf(bpelStatus) + responseBody, bpelStatus, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).build();
updateStatus(currentActiveReq, Status.FAILED, bpmnException.getMessage());
throw bpmnException;
}
} catch (ApiException e) {
updateStatus(currentActiveReq, Status.FAILED, e.getMessage());
throw e;
} catch (IOException e) {
logger.error("Exception caught mapping Camunda JSON response to object: ", e);
updateStatus(currentActiveReq, Status.FAILED, e.getMessage());
throw new ValidateException.Builder("Exception caught mapping Camunda JSON response to object", HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).build();
}
return builder.buildResponse(HttpStatus.SC_ACCEPTED, requestClientParameter.getRequestId(), jsonResponse, requestClientParameter.getApiVersion());
}
Aggregations