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