use of org.jboss.resteasy.reactive.server.ServerResponseFilter in project quarkus by quarkusio.
the class QuarkusSmallRyeTracingStandaloneContainerResponseFilter method filter.
// this needs to be executed after ServerTracingFilter
@ServerResponseFilter(priority = Priorities.HEADER_DECORATOR - 1)
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext, Throwable t) {
Object wrapperObj = requestContext.getProperty(SpanWrapper.PROPERTY_NAME);
if (!(wrapperObj instanceof SpanWrapper)) {
return;
}
SpanWrapper wrapper = (SpanWrapper) wrapperObj;
Tags.HTTP_STATUS.set(wrapper.get(), responseContext.getStatus());
if (t != null) {
FilterUtil.addExceptionLogs(wrapper.get(), t);
}
}
use of org.jboss.resteasy.reactive.server.ServerResponseFilter in project quarkus by quarkusio.
the class TemplateResponseFilter method filter.
@SuppressWarnings("unchecked")
@ServerResponseFilter
public Uni<Void> filter(ResteasyReactiveContainerRequestContext requestContext, ContainerResponseContext responseContext) {
Object entity = responseContext.getEntity();
if (!(entity instanceof TemplateInstance)) {
return null;
}
MediaType mediaType;
TemplateInstance instance = (TemplateInstance) entity;
Object variantsAttr = instance.getAttribute(TemplateInstance.VARIANTS);
if (variantsAttr != null) {
List<javax.ws.rs.core.Variant> variants = new ArrayList<>();
for (Variant variant : (List<Variant>) variantsAttr) {
variants.add(new javax.ws.rs.core.Variant(MediaType.valueOf(variant.getMediaType()), variant.getLocale(), variant.getEncoding()));
}
javax.ws.rs.core.Variant selected = requestContext.getRequest().selectVariant(variants);
if (selected != null) {
Locale selectedLocale = selected.getLanguage();
if (selectedLocale == null) {
List<Locale> acceptableLocales = requestContext.getAcceptableLanguages();
if (!acceptableLocales.isEmpty()) {
selectedLocale = acceptableLocales.get(0);
}
}
instance.setAttribute(TemplateInstance.SELECTED_VARIANT, new Variant(selectedLocale, selected.getMediaType().toString(), selected.getEncoding()));
mediaType = selected.getMediaType();
} else {
mediaType = responseContext.getMediaType();
}
} else {
mediaType = responseContext.getMediaType();
}
Uni<String> uni = instance.createUni();
if (!engine.useAsyncTimeout()) {
// Make sure the timeout is always used
long timeout = instance.getTimeout();
uni = uni.ifNoItem().after(Duration.ofMillis(timeout)).failWith(() -> new TemplateException(instance + " rendering timeout [" + timeout + "ms] occured"));
}
return uni.chain(r -> {
if (mediaType != null) {
responseContext.setEntity(r, null, mediaType);
} else {
responseContext.setEntity(r);
}
return Uni.createFrom().nullItem();
});
}
use of org.jboss.resteasy.reactive.server.ServerResponseFilter in project quarkus by quarkusio.
the class QuarkusRestMetricsFilter method filter.
@ServerResponseFilter
public void filter(ResourceInfo resourceInfo, Throwable throwable) {
Class<?> resourceClass = resourceInfo.getResourceClass();
Method resourceMethod = resourceInfo.getResourceMethod();
if ((resourceClass == null) || (resourceMethod == null)) {
return;
}
maybeCreateMetrics(resourceClass, resourceMethod);
FilterUtil.finishRequest(System.nanoTime(), resourceInfo.getResourceClass(), resourceInfo.getResourceMethod().getName(), resourceInfo.getResourceMethod().getParameterTypes(), // increment the failure counter rather than the successful calls counter
() -> throwable == null);
}
Aggregations