private static RequestEvent event(Integer status, Exception exception, String baseUri, String... uriTemplateStrings) {
Builder builder = new RequestEventImpl.Builder();
ContainerRequest containerRequest = mock(ContainerRequest.class);
when(containerRequest.getMethod()).thenReturn("GET");
builder.setContainerRequest(containerRequest);
ContainerResponse containerResponse = mock(ContainerResponse.class);
when(containerResponse.getStatus()).thenReturn(status);
builder.setContainerResponse(containerResponse);
builder.setException(exception, null);
ExtendedUriInfo extendedUriInfo = mock(ExtendedUriInfo.class);
when(extendedUriInfo.getBaseUri()).thenReturn(
URI.create("http://localhost:8080" + (baseUri == null ? "/" : baseUri)));
List<UriTemplate> uriTemplates = uriTemplateStrings == null ? Collections.emptyList()
: Arrays.stream(uriTemplateStrings).map(uri -> new UriTemplate(uri))
.collect(Collectors.toList());
// UriTemplate are returned in reverse order
Collections.reverse(uriTemplates);
when(extendedUriInfo.getMatchedTemplates()).thenReturn(uriTemplates);
builder.setExtendedUriInfo(extendedUriInfo);
return builder.build(Type.FINISHED);
}
@Override
public void onEvent(RequestEvent paramRequestEvent)
{
if (paramRequestEvent.getType() == Type.ON_EXCEPTION)
{
log.info("a REST call failed with an exception", paramRequestEvent.getException());
}
}
/**
* <p>getType.</p>
*
* @return a {@link org.glassfish.jersey.server.monitoring.RequestEvent.Type} object.
*/
public Type getType() {
return event.getType();
}