Search in sources :

Example 6 with BPMNFailureException

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());
}
Also used : ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) CamundaResponse(org.onap.so.apihandler.camundabeans.CamundaResponse) IOException(java.io.IOException) URL(java.net.URL) BPMNFailureException(org.onap.so.apihandlerinfra.exceptions.BPMNFailureException) ServiceInstancesResponse(org.onap.so.serviceinstancebeans.ServiceInstancesResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException)

Example 7 with BPMNFailureException

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());
}
Also used : BPMNFailureException(org.onap.so.apihandlerinfra.exceptions.BPMNFailureException) HttpServerErrorException(org.springframework.web.client.HttpServerErrorException) Test(org.junit.Test)

Example 8 with BPMNFailureException

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());
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) BPMNFailureException(org.onap.so.apihandlerinfra.exceptions.BPMNFailureException) Test(org.junit.Test)

Aggregations

BPMNFailureException (org.onap.so.apihandlerinfra.exceptions.BPMNFailureException)8 Test (org.junit.Test)4 CamundaResponse (org.onap.so.apihandler.camundabeans.CamundaResponse)4 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)2 URL (java.net.URL)1 Response (javax.ws.rs.core.Response)1 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)1 ServiceInstancesResponse (org.onap.so.serviceinstancebeans.ServiceInstancesResponse)1 HttpServerErrorException (org.springframework.web.client.HttpServerErrorException)1