Search in sources :

Example 6 with CamundaResponse

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());
}
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)

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