Search in sources :

Example 1 with BPMNFailureException

use of org.onap.so.apihandlerinfra.exceptions.BPMNFailureException in project so by onap.

the class CamundaClientTest method createBPMNFailureExceptionWithCamundaResponseTest.

@Test
public void createBPMNFailureExceptionWithCamundaResponseTest() throws IOException {
    HttpClientErrorException e = new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR, null, inputStream("/CamundaFailure.json").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 <aetgt:WorkflowException xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\"><aetgt:ErrorMessage>Exception in create execution list 500 </aetgt:ErrorMessage><aetgt:ErrorCode>7000</aetgt:ErrorCode></aetgt:WorkflowException>", ex.getMessage());
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) BPMNFailureException(org.onap.so.apihandlerinfra.exceptions.BPMNFailureException) Test(org.junit.Test)

Example 2 with BPMNFailureException

use of org.onap.so.apihandlerinfra.exceptions.BPMNFailureException in project so by onap.

the class CamundaClient method createBPMNFailureException.

protected BPMNFailureException createBPMNFailureException(HttpStatusCodeException e) {
    ObjectMapper mapper = new ObjectMapper();
    String responseText = null;
    String message = null;
    try {
        CamundaResponse response = mapper.readValue(e.getResponseBodyAsString(), CamundaResponse.class);
        responseText = response.getResponse();
    } catch (IOException ex) {
        responseText = e.getResponseBodyAsString();
    }
    message = String.valueOf(e.getStatusCode());
    if (responseText != null && !responseText.isEmpty()) {
        message = message + " " + responseText;
    }
    BPMNFailureException bpmnException = new BPMNFailureException.Builder(message, responseHandler.setStatus(e.getStatusCode().value()), ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, e.getStatusCode()).build();
    return bpmnException;
}
Also used : CamundaResponse(org.onap.so.apihandler.camundabeans.CamundaResponse) BPMNFailureException(org.onap.so.apihandlerinfra.exceptions.BPMNFailureException) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with BPMNFailureException

use of org.onap.so.apihandlerinfra.exceptions.BPMNFailureException in project so by onap.

the class ServiceIntentApiHandler method postBPELRequest.

private Response postBPELRequest(InfraActiveRequests currentActiveReq, RequestClientParameter parameter, String orchestrationURI, String requestScope) throws ApiException {
    ResponseEntity<String> response = requestHandlerUtils.postRequest(currentActiveReq, parameter, orchestrationURI);
    logger.debug("BPEL response : " + response);
    int bpelStatus = responseHandler.setStatus(response.getStatusCodeValue());
    String jsonResponse;
    try {
        responseHandler.acceptedResponse(response);
        CamundaResponse camundaResponse = responseHandler.getCamundaResponse(response);
        String responseBody = camundaResponse.getResponse();
        if ("Success".equalsIgnoreCase(camundaResponse.getMessage())) {
            jsonResponse = responseBody;
        } else {
            BPMNFailureException bpmnException = new BPMNFailureException.Builder(String.valueOf(bpelStatus) + responseBody, bpelStatus, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).build();
            requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, bpmnException.getMessage());
            throw bpmnException;
        }
    } catch (ApiException e) {
        requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, e.getMessage());
        throw e;
    }
    return builder.buildResponse(HttpStatus.SC_ACCEPTED, parameter.getRequestId(), jsonResponse, parameter.getApiVersion());
}
Also used : CamundaResponse(org.onap.so.apihandler.camundabeans.CamundaResponse) BPMNFailureException(org.onap.so.apihandlerinfra.exceptions.BPMNFailureException) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException)

Example 4 with BPMNFailureException

use of org.onap.so.apihandlerinfra.exceptions.BPMNFailureException in project so by onap.

the class ApiExceptionMapperTest method testBPMNFailureResponse.

@Test
public void testBPMNFailureResponse() {
    BPMNFailureException bpmnException = new BPMNFailureException.Builder("Test Message", HttpStatus.SC_NOT_FOUND, ErrorNumbers.SVC_BAD_PARAMETER).build();
    Response resp = mapper.toResponse((ApiException) bpmnException);
    assertEquals(resp.getStatus(), HttpStatus.SC_NOT_FOUND);
}
Also used : Response(javax.ws.rs.core.Response) BPMNFailureException(org.onap.so.apihandlerinfra.exceptions.BPMNFailureException) Test(org.junit.Test)

Example 5 with BPMNFailureException

use of org.onap.so.apihandlerinfra.exceptions.BPMNFailureException in project so by onap.

the class Onap3gppServiceInstances method postBPELRequest.

private Response postBPELRequest(InfraActiveRequests currentActiveReq, RequestClientParameter parameter, String orchestrationURI, String requestScope) throws ApiException {
    ResponseEntity<String> response = requestHandlerUtils.postRequest(currentActiveReq, parameter, orchestrationURI);
    logger.debug("BPEL response : " + response);
    int bpelStatus = responseHandler.setStatus(response.getStatusCodeValue());
    String jsonResponse;
    try {
        responseHandler.acceptedResponse(response);
        CamundaResponse camundaResponse = responseHandler.getCamundaResponse(response);
        String responseBody = camundaResponse.getResponse();
        if ("Success".equalsIgnoreCase(camundaResponse.getMessage())) {
            jsonResponse = responseBody;
        } else {
            BPMNFailureException bpmnException = new BPMNFailureException.Builder(String.valueOf(bpelStatus) + responseBody, bpelStatus, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).build();
            requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, bpmnException.getMessage());
            throw bpmnException;
        }
    } catch (ApiException e) {
        requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, e.getMessage());
        throw e;
    }
    return builder.buildResponse(HttpStatus.SC_ACCEPTED, parameter.getRequestId(), jsonResponse, parameter.getApiVersion());
}
Also used : CamundaResponse(org.onap.so.apihandler.camundabeans.CamundaResponse) BPMNFailureException(org.onap.so.apihandlerinfra.exceptions.BPMNFailureException) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException)

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