/** {@inheritDoc} */ public void onEvent(RequestEvent reqEvt) { if (RequestEvent.Type.ON_EXCEPTION.equals(reqEvt.getType())) { logger.error("An error occured when processing " + reqEvt.getContainerRequest().getRequestUri(), reqEvt.getException() ); logger.error(" + Type : " + reqEvt.getException().getClass().getName()); logger.error(" + Message : " + reqEvt.getException().getMessage()); } else { logger.debug(reqEvt.getContainerRequest().getRequestUri() + "[" + reqEvt.getType() + "]"); } }
@Override public int hashCode() { int result = type.hashCode(); result = 31 * result + method.hashCode(); return result; } }
@Test public void onEvent_for_RequestEvent_handles_REQUEST_MATCHED_only_and_sets_HTTP_ROUTE_to_result_of_route_method() { for (RequestEvent.Type type : RequestEvent.Type.values()) { // given doReturn(type).when(requestEventMock).getType(); boolean expectHandled = (type == RequestEvent.Type.REQUEST_MATCHED); String routeMethodResult = "route-" + UUID.randomUUID().toString(); doReturn(routeMethodResult).when(implSpy).route(any(ContainerRequest.class)); // when implSpy.onEvent(requestEventMock); // then if (expectHandled) { verify(requestMock).setProperty(KnownZipkinTags.HTTP_ROUTE, routeMethodResult); } else { verifyZeroInteractions(requestMock); } } }
@Test public void onRequest_retunrs_self_for_START_otherwise_null() { for (RequestEvent.Type type : RequestEvent.Type.values()) { // given doReturn(type).when(requestEventMock).getType(); boolean expectNonNullResult = (type == RequestEvent.Type.START); // when RequestEventListener result = implSpy.onRequest(requestEventMock); // then if (expectNonNullResult) { assertThat(result).isSameAs(implSpy); } else { assertThat(result).isNull(); } } }
public void onEvent(final RequestEvent event) { if (event.getType().equals(Type.ON_EXCEPTION)) { logger.error("REST Exception", event.getException()); } }