Search in sources :

Example 6 with ServiceException

use of org.onap.so.serviceinstancebeans.ServiceException in project so by onap.

the class ApiExceptionMapper method buildServiceErrorResponse.

protected RequestError buildServiceErrorResponse(String errorText, String messageId, List<String> variables) {
    RequestError requestError = new RequestError();
    ServiceException serviceException = new ServiceException();
    serviceException.setMessageId(messageId);
    serviceException.setText(errorText);
    if (variables != null) {
        for (String variable : variables) {
            serviceException.getVariables().add(variable);
        }
    }
    requestError.setServiceException(serviceException);
    return requestError;
}
Also used : RequestError(org.onap.so.serviceinstancebeans.RequestError) ServiceException(org.onap.so.serviceinstancebeans.ServiceException)

Example 7 with ServiceException

use of org.onap.so.serviceinstancebeans.ServiceException in project so by onap.

the class ResponseUpdateFilter method updateRequestDBToFailed.

private void updateRequestDBToFailed(ContainerResponseContext responseContext) {
    String requestId = MDC.get(ONAPLogConstants.MDCs.REQUEST_ID);
    if (requestId != null && !Response.Status.Family.familyOf(responseContext.getStatus()).equals(Response.Status.Family.SUCCESSFUL)) {
        InfraActiveRequests currentRequest = infraActiveRequestsClient.getInfraActiveRequestbyRequestId(requestId);
        if (currentRequest != null) {
            Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis());
            RequestError error;
            try {
                error = (RequestError) responseContext.getEntity();
            } catch (Exception e) {
                logger.warn("Error Casting Entity to Request Error, generating unknown Error", e);
                error = new RequestError();
                ServiceException serviceException = new ServiceException();
                serviceException.setText("Unknown Error Occured during processing");
                error.setServiceException(serviceException);
            }
            if (error.getServiceException() != null && error.getServiceException().getText() != null && !error.getServiceException().getText().isEmpty()) {
                currentRequest.setStatusMessage(error.getServiceException().getText());
            } else {
                currentRequest.setStatusMessage("Unknown Error Occured during processing");
            }
            currentRequest.setRequestStatus(Status.FAILED.toString());
            currentRequest.setEndTime(endTimeStamp);
            currentRequest.setProgress(100L);
            infraActiveRequestsClient.updateInfraActiveRequests(currentRequest);
        }
    }
}
Also used : RequestError(org.onap.so.serviceinstancebeans.RequestError) ServiceException(org.onap.so.serviceinstancebeans.ServiceException) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) Timestamp(java.sql.Timestamp) IOException(java.io.IOException) ServiceException(org.onap.so.serviceinstancebeans.ServiceException)

Example 8 with ServiceException

use of org.onap.so.serviceinstancebeans.ServiceException in project so by onap.

the class MsoRequest method buildServiceErrorResponse.

public Response buildServiceErrorResponse(int httpResponseCode, MsoException exceptionType, String errorText, String messageId, List<String> variables, String version) {
    if (errorText.length() > 1999) {
        errorText = errorText.substring(0, 1999);
    }
    RequestError re = new RequestError();
    if ("PolicyException".equals(exceptionType.name())) {
        PolicyException pe = new PolicyException();
        pe.setMessageId(messageId);
        pe.setText(errorText);
        if (variables != null) {
            for (String variable : variables) {
                pe.getVariables().add(variable);
            }
        }
        re.setPolicyException(pe);
    } else {
        ServiceException se = new ServiceException();
        se.setMessageId(messageId);
        se.setText(errorText);
        if (variables != null) {
            for (String variable : variables) {
                se.getVariables().add(variable);
            }
        }
        re.setServiceException(se);
    }
    return builder.buildResponse(httpResponseCode, null, re, version);
}
Also used : RequestError(org.onap.so.serviceinstancebeans.RequestError) ServiceException(org.onap.so.serviceinstancebeans.ServiceException) PolicyException(org.onap.so.serviceinstancebeans.PolicyException)

Example 9 with ServiceException

use of org.onap.so.serviceinstancebeans.ServiceException in project so by onap.

the class ManualTasksTest method completeTaskMappingError.

@Test
public void completeTaskMappingError() throws IOException {
    String invalidRequest = "test";
    RequestError expectedResponse = new RequestError();
    ServiceException se = new ServiceException();
    se.setMessageId("SVC0002");
    se.setText("Mapping of request to JSON object failed: Unrecognized token \u0027test\u0027: was expecting (JSON String, Number, Array, Object or token \u0027null\u0027, \u0027true\u0027 or \u0027false\u0027)\n at [Source: (String)\"test\"; line: 1, column: 5]");
    expectedResponse.setServiceException(se);
    HttpHeaders headers = new HttpHeaders();
    headers.set("Accept", MediaType.APPLICATION_JSON);
    headers.set("Content-Type", MediaType.APPLICATION_JSON);
    headers.set(ECOMP_REQUEST_ID, "987654321");
    headers.set(ONAP_PARTNER_NAME, "VID");
    HttpEntity<String> entity = new HttpEntity<String>(invalidRequest, headers);
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(basePath) + "55" + "/complete");
    ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
    assertThat(realResponse, sameBeanAs(expectedResponse));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) RequestError(org.onap.so.serviceinstancebeans.RequestError) ServiceException(org.onap.so.serviceinstancebeans.ServiceException) HttpEntity(org.springframework.http.HttpEntity) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 10 with ServiceException

use of org.onap.so.serviceinstancebeans.ServiceException in project so by onap.

the class ManualTasksTest method completeTaskBpelResponseError.

@Test
public void completeTaskBpelResponseError() throws IOException {
    wireMockServer.stubFor(post(urlPathEqualTo("/sobpmnengine/task/55/complete")).willReturn(aResponse().withHeader("Content-Type", "application/json").withFault(Fault.EMPTY_RESPONSE)));
    String taskId = "55";
    TasksRequest taskReq = new TasksRequest();
    RequestDetails reqDetail = new RequestDetails();
    RequestInfo reqInfo = new RequestInfo();
    reqInfo.setRequestorId("testId");
    reqInfo.setSource("testSource");
    reqInfo.setResponseValue(ValidResponses.skip);
    reqDetail.setRequestInfo(reqInfo);
    taskReq.setRequestDetails(reqDetail);
    RequestError expectedResponse = new RequestError();
    ServiceException se = new ServiceException();
    se.setMessageId("SVC1000");
    se.setText("Client from http://localhost:" + env.getProperty("wiremock.server.port") + "/sobpmnengine/task/55/complete failed to connect or respond");
    expectedResponse.setServiceException(se);
    HttpHeaders headers = new HttpHeaders();
    headers.set("Accept", MediaType.APPLICATION_JSON);
    headers.set("Content-Type", MediaType.APPLICATION_JSON);
    headers.set(ECOMP_REQUEST_ID, "987654321");
    headers.set(ONAP_PARTNER_NAME, "VID");
    HttpEntity<TasksRequest> entity = new HttpEntity<TasksRequest>(taskReq, headers);
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(basePath) + taskId + "/complete");
    ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
    assertEquals(Response.Status.BAD_GATEWAY.getStatusCode(), response.getStatusCode().value());
    assertThat(realResponse, sameBeanAs(expectedResponse));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) RequestError(org.onap.so.serviceinstancebeans.RequestError) ServiceException(org.onap.so.serviceinstancebeans.ServiceException) HttpEntity(org.springframework.http.HttpEntity) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) TasksRequest(org.onap.so.apihandlerinfra.tasksbeans.TasksRequest) RequestInfo(org.onap.so.apihandlerinfra.tasksbeans.RequestInfo) RequestDetails(org.onap.so.apihandlerinfra.tasksbeans.RequestDetails) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

RequestError (org.onap.so.serviceinstancebeans.RequestError)19 ServiceException (org.onap.so.serviceinstancebeans.ServiceException)19 Test (org.junit.Test)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 HttpEntity (org.springframework.http.HttpEntity)5 HttpHeaders (org.springframework.http.HttpHeaders)5 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 RequestDetails (org.onap.so.apihandlerinfra.tasksbeans.RequestDetails)2 RequestInfo (org.onap.so.apihandlerinfra.tasksbeans.RequestInfo)2 TasksRequest (org.onap.so.apihandlerinfra.tasksbeans.TasksRequest)2 IOException (java.io.IOException)1 Timestamp (java.sql.Timestamp)1 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)1 ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)1 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)1 PolicyException (org.onap.so.serviceinstancebeans.PolicyException)1