All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.resteasy.runtime.QuarkusRestPathTemplateInterceptor Maven / Gradle / Ivy

There is a newer version: 3.17.0
Show newest version
package io.quarkus.resteasy.runtime;

import java.lang.annotation.Annotation;
import java.util.Set;

import jakarta.annotation.Priority;
import jakarta.enterprise.context.ContextNotActiveException;
import jakarta.inject.Inject;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.Interceptor;
import jakarta.interceptor.InvocationContext;

import io.quarkus.arc.ArcInvocationContext;
import io.quarkus.vertx.http.runtime.CurrentVertxRequest;
import io.vertx.core.http.impl.HttpServerRequestInternal;
import io.vertx.ext.web.RoutingContext;

@SuppressWarnings("unused")
@QuarkusRestPathTemplate
@Interceptor
@Priority(Interceptor.Priority.LIBRARY_BEFORE + 10)
public class QuarkusRestPathTemplateInterceptor {
    @Inject
    CurrentVertxRequest request;

    @AroundInvoke
    Object restMethodInvoke(InvocationContext context) throws Exception {
        QuarkusRestPathTemplate annotation = getAnnotation(context);
        RoutingContext routingContext = null;
        try {
            routingContext = request.getCurrent();
        } catch (ContextNotActiveException ex) {
            // just leave routingContext as null
        }
        if ((annotation != null) && (routingContext != null)) {
            ((HttpServerRequestInternal) request.getCurrent().request()).context().putLocal("UrlPathTemplate",
                    annotation.value());
        }
        return context.proceed();
    }

    @SuppressWarnings("unchecked")
    static QuarkusRestPathTemplate getAnnotation(InvocationContext context) {
        Set annotations = (Set) context.getContextData()
                .get(ArcInvocationContext.KEY_INTERCEPTOR_BINDINGS);

        for (Annotation a : annotations) {
            if (a instanceof QuarkusRestPathTemplate) {
                return (QuarkusRestPathTemplate) a;
            }
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy