Search in sources :

Example 1 with ServerResponseFilter

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);
    }
}
Also used : SpanWrapper(io.smallrye.opentracing.contrib.jaxrs2.internal.SpanWrapper) ServerResponseFilter(org.jboss.resteasy.reactive.server.ServerResponseFilter)

Example 2 with ServerResponseFilter

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();
    });
}
Also used : Locale(java.util.Locale) TemplateException(io.quarkus.qute.TemplateException) ArrayList(java.util.ArrayList) TemplateInstance(io.quarkus.qute.TemplateInstance) Variant(io.quarkus.qute.Variant) MediaType(javax.ws.rs.core.MediaType) ArrayList(java.util.ArrayList) List(java.util.List) ServerResponseFilter(org.jboss.resteasy.reactive.server.ServerResponseFilter)

Example 3 with ServerResponseFilter

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);
}
Also used : Method(java.lang.reflect.Method) ServerResponseFilter(org.jboss.resteasy.reactive.server.ServerResponseFilter)

Aggregations

ServerResponseFilter (org.jboss.resteasy.reactive.server.ServerResponseFilter)3 TemplateException (io.quarkus.qute.TemplateException)1 TemplateInstance (io.quarkus.qute.TemplateInstance)1 Variant (io.quarkus.qute.Variant)1 SpanWrapper (io.smallrye.opentracing.contrib.jaxrs2.internal.SpanWrapper)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Locale (java.util.Locale)1 MediaType (javax.ws.rs.core.MediaType)1