Search in sources :

Example 1 with CamundaResponse

use of org.onap.so.apihandler.camundabeans.CamundaResponse 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 2 with CamundaResponse

use of org.onap.so.apihandler.camundabeans.CamundaResponse in project so by onap.

the class ResponseHandler method getCamundaResponse.

public CamundaResponse getCamundaResponse(ResponseEntity<String> camundaResponse) throws ValidateException {
    String responseBody = camundaResponse.getBody();
    CamundaResponse response = null;
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    try {
        response = mapper.readValue(responseBody, CamundaResponse.class);
    } catch (IOException | NullPointerException e) {
        logger.error("Cannot parse Camunda Response: ", e);
        throw new ValidateException.Builder("Cannot parse Camunda ResponseBody. BPMN HTTP status: " + camundaResponse.getStatusCodeValue(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).build();
    }
    return response;
}
Also used : ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) CamundaResponse(org.onap.so.apihandler.camundabeans.CamundaResponse) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with CamundaResponse

use of org.onap.so.apihandler.camundabeans.CamundaResponse 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 CamundaResponse

use of org.onap.so.apihandler.camundabeans.CamundaResponse in project so by onap.

the class E2EServiceInstances method bpelStatusUpdate.

private Response bpelStatusUpdate(ResponseEntity<String> responseEntity, String version) throws ApiException {
    String apiVersion = version.substring(1);
    responseHandler.acceptedResponse(responseEntity);
    CamundaResponse camundaResponse = responseHandler.getCamundaResponse(responseEntity);
    String response = camundaResponse.getResponse();
    logger.debug(END_OF_THE_TRANSACTION + response);
    return builder.buildResponse(HttpStatus.SC_ACCEPTED, null, response, apiVersion);
}
Also used : CamundaResponse(org.onap.so.apihandler.camundabeans.CamundaResponse)

Example 5 with CamundaResponse

use of org.onap.so.apihandler.camundabeans.CamundaResponse 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

CamundaResponse (org.onap.so.apihandler.camundabeans.CamundaResponse)6 BPMNFailureException (org.onap.so.apihandlerinfra.exceptions.BPMNFailureException)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 IOException (java.io.IOException)3 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)3 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)2 URL (java.net.URL)1 ServiceInstancesResponse (org.onap.so.serviceinstancebeans.ServiceInstancesResponse)1