Search in sources :

Example 16 with ServiceException

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

the class WorkflowEngineConnectionMapper method toResponse.

@Override
public Response toResponse(WorkflowEngineConnectionException e) {
    logger.error("Workflow Engine Connection Error", e);
    RequestError error = new RequestError();
    ServiceException value = new ServiceException();
    value.setMessageId(ErrorNumbers.SVC_GENERAL_SERVICE_ERROR);
    value.setText(e.getMessage());
    error.setServiceException(value);
    return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build();
}
Also used : RequestError(org.onap.so.serviceinstancebeans.RequestError) ServiceException(org.onap.so.serviceinstancebeans.ServiceException)

Example 17 with ServiceException

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

the class ModelDistributionRequest method buildServiceErrorResponse.

private Response buildServiceErrorResponse(int httpResponseCode, MsoException exceptionType, String text, String messageId, List<String> variables) throws ApiException {
    RequestError re = new RequestError();
    ServiceException se = new ServiceException();
    se.setMessageId(messageId);
    se.setText(text);
    if (variables != null) {
        for (String variable : variables) {
            se.getVariables().add(variable);
        }
    }
    re.setServiceException(se);
    String requestErrorStr;
    try {
        ObjectMapper mapper = new ObjectMapper();
        mapper.setSerializationInclusion(Include.NON_DEFAULT);
        requestErrorStr = mapper.writeValueAsString(re);
    } catch (JsonProcessingException e) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_VALIDATION_ERROR, ErrorCode.DataError).build();
        ValidateException validateException = new ValidateException.Builder("Mapping of request to JSON object failed.  " + e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
        throw validateException;
    }
    return Response.status(httpResponseCode).entity(requestErrorStr).build();
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) RequestError(org.onap.so.serviceinstancebeans.RequestError) ServiceException(org.onap.so.serviceinstancebeans.ServiceException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 18 with ServiceException

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

the class RequestIdFilter method createRequestError.

protected String createRequestError(String requestId, String requestTable) {
    ObjectMapper mapper = new ObjectMapper();
    RequestError error = new RequestError();
    ServiceException serviceException = new ServiceException();
    serviceException.setMessageId(ErrorNumbers.SVC_BAD_PARAMETER);
    serviceException.setText("RequestId: " + requestId + " already exists in the RequestDB " + requestTable + " table");
    error.setServiceException(serviceException);
    String errorMessage = null;
    try {
        errorMessage = mapper.writeValueAsString(error);
    } catch (JsonProcessingException e) {
        return "Unable to write requestError to String when requestId already exists in the RequestDb due to error: " + e.getMessage();
    }
    return errorMessage;
}
Also used : RequestError(org.onap.so.serviceinstancebeans.RequestError) ServiceException(org.onap.so.serviceinstancebeans.ServiceException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 19 with ServiceException

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

the class OrchestrationRequestsTest method testUnlockOrchestrationRequest_invalid_Json.

@Test
public void testUnlockOrchestrationRequest_invalid_Json() throws Exception {
    setupTestUnlockOrchestrationRequest_invalid_Json();
    ObjectMapper mapper = new ObjectMapper();
    String requestJSON = new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/Request.json")));
    HttpHeaders headers = new HttpHeaders();
    headers.set("Accept", MediaType.APPLICATION_JSON);
    headers.set("Content-Type", MediaType.APPLICATION_JSON);
    HttpEntity<String> entity = new HttpEntity<String>(requestJSON, headers);
    UriComponentsBuilder builder;
    ResponseEntity<String> response;
    RequestError expectedRequestError;
    RequestError actualRequestError;
    ServiceException se;
    // Test invalid requestId
    expectedRequestError = new RequestError();
    se = new ServiceException();
    se.setMessageId(ErrorNumbers.SVC_DETAILED_SERVICE_ERROR);
    se.setText("Null response from RequestDB when searching by RequestId " + INVALID_REQUEST_ID);
    expectedRequestError.setServiceException(se);
    builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v6/" + INVALID_REQUEST_ID + "/unlock"));
    response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
    actualRequestError = mapper.readValue(response.getBody(), RequestError.class);
    assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
    assertThat(expectedRequestError, sameBeanAs(actualRequestError));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) RequestError(org.onap.so.serviceinstancebeans.RequestError) HttpEntity(org.springframework.http.HttpEntity) ServiceException(org.onap.so.serviceinstancebeans.ServiceException) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) 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