use of org.onap.so.apihandlerinfra.exceptions.BPMNFailureException 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());
}
use of org.onap.so.apihandlerinfra.exceptions.BPMNFailureException in project so by onap.
the class CamundaClientTest method createBPMNFailureExceptionNoResponseBodyTest.
@Test
public void createBPMNFailureExceptionNoResponseBodyTest() {
HttpServerErrorException e = new HttpServerErrorException(HttpStatus.NOT_FOUND);
BPMNFailureException ex = client.createBPMNFailureException(e);
assertEquals(HttpStatus.NOT_IMPLEMENTED.value(), ex.getHttpResponseCode());
assertEquals("Request Failed due to BPEL error with HTTP Status = 404 NOT_FOUND", ex.getMessage());
}
use of org.onap.so.apihandlerinfra.exceptions.BPMNFailureException in project so by onap.
the class CamundaClientTest method createBPMNFailureExceptionTest.
@Test
public void createBPMNFailureExceptionTest() throws IOException {
String response = "Request failed";
HttpClientErrorException e = new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR, null, response.getBytes(), null);
BPMNFailureException ex = client.createBPMNFailureException(e);
assertEquals(HttpStatus.BAD_GATEWAY.value(), ex.getHttpResponseCode());
assertEquals("Request Failed due to BPEL error with HTTP Status = 500 INTERNAL_SERVER_ERROR Request failed", ex.getMessage());
}
Aggregations