use of org.openkilda.messaging.error.MessageError in project open-kilda by telstra.
the class MetersResource method getMeters.
// FIXME(surabujin): is it used anywhere?
@Get("json")
@SuppressWarnings("unchecked")
public Map<Long, Object> getMeters() {
Map<Long, Object> response = new HashMap<>();
String switchId = (String) this.getRequestAttributes().get("switch_id");
logger.debug("Get meters for switch: {}", switchId);
ISwitchManager switchManager = (ISwitchManager) getContext().getAttributes().get(ISwitchManager.class.getCanonicalName());
try {
OFMeterConfigStatsReply replay = switchManager.dumpMeters(DatapathId.of(switchId));
logger.debug("Meters from switch {} received: {}", switchId, replay);
if (replay != null) {
for (OFMeterConfig entry : replay.getEntries()) {
response.put(entry.getMeterId(), entry);
}
}
} catch (IllegalArgumentException | SwitchOperationException exception) {
String messageString = "No such switch";
logger.error("{}: {}", messageString, switchId, exception);
MessageError responseMessage = new MessageError(DEFAULT_CORRELATION_ID, System.currentTimeMillis(), ErrorType.PARAMETERS_INVALID.toString(), messageString, exception.getMessage());
response.putAll(MAPPER.convertValue(responseMessage, Map.class));
}
return response;
}
use of org.openkilda.messaging.error.MessageError in project open-kilda by telstra.
the class TopologyBasicAuthenticationEntryPoint method commence.
/**
* {@inheritDoc}
*/
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
String realm = String.format("Basic realm=%s", getRealmName());
response.addHeader(HttpHeaders.WWW_AUTHENTICATE, realm);
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
MessageError error = new MessageError(request.getHeader(CORRELATION_ID), System.currentTimeMillis(), HttpStatus.UNAUTHORIZED.value(), HttpStatus.UNAUTHORIZED.getReasonPhrase(), ErrorType.AUTH_FAILED.toString(), exception.getClass().getSimpleName());
response.getWriter().print(MAPPER.writeValueAsString(error));
}
use of org.openkilda.messaging.error.MessageError in project open-kilda by telstra.
the class TopologyExceptionHandler method handleMessageException.
/**
* Handles MessageException exception.
*
* @param exception the MessageException instance
* @param request the WebRequest caused exception
* @return the ResponseEntity object instance
*/
@ExceptionHandler(MessageException.class)
protected ResponseEntity<Object> handleMessageException(MessageException exception, WebRequest request) {
HttpStatus status;
switch(exception.getErrorType()) {
case NOT_FOUND:
status = HttpStatus.NOT_FOUND;
break;
case DATA_INVALID:
case PARAMETERS_INVALID:
status = HttpStatus.BAD_REQUEST;
break;
case ALREADY_EXISTS:
status = HttpStatus.CONFLICT;
break;
case AUTH_FAILED:
status = HttpStatus.UNAUTHORIZED;
break;
case OPERATION_TIMED_OUT:
case INTERNAL_ERROR:
default:
status = HttpStatus.INTERNAL_SERVER_ERROR;
break;
}
MessageError error = new MessageError(request.getHeader(CORRELATION_ID), exception.getTimestamp(), status.value(), status.getReasonPhrase(), exception.getMessage(), exception.getClass().getSimpleName());
return super.handleExceptionInternal(exception, error, new HttpHeaders(), status, request);
}
use of org.openkilda.messaging.error.MessageError in project open-kilda by telstra.
the class FlowControllerTest method getNonExistingFlow.
@Test
@WithMockUser(username = USERNAME, password = PASSWORD, roles = ROLE)
public void getNonExistingFlow() throws Exception {
MvcResult result = mockMvc.perform(get("/flows/{flow-id}", ERROR_FLOW_ID).header(CORRELATION_ID, DEFAULT_CORRELATION_ID).contentType(APPLICATION_JSON_VALUE)).andExpect(status().isNotFound()).andExpect(content().contentType(APPLICATION_JSON_UTF8_VALUE)).andReturn();
MessageError response = MAPPER.readValue(result.getResponse().getContentAsString(), MessageError.class);
assertEquals(NOT_FOUND_ERROR, response);
}
use of org.openkilda.messaging.error.MessageError in project open-kilda by telstra.
the class FlowControllerTest method emptyCredentials.
@Test
public void emptyCredentials() throws Exception {
MvcResult result = mockMvc.perform(get("/flows/path/{flow-id}", TestMessageMock.FLOW_ID).header(CORRELATION_ID, DEFAULT_CORRELATION_ID).contentType(APPLICATION_JSON_VALUE)).andExpect(status().isUnauthorized()).andExpect(content().contentType(APPLICATION_JSON_UTF8_VALUE)).andReturn();
MessageError response = MAPPER.readValue(result.getResponse().getContentAsString(), MessageError.class);
assertEquals(AUTH_ERROR, response);
}
Aggregations