1

If I follow this I can add a ContainerRequestFilter and it gets picked up by Quarkus and runs as expected. However, I'm writing an extension to take advantage of a ContainerRequestFilter written by another team. I'm unsure of how to get Quarkus to use this filter. I've tried adding it as an AdditionalBeanBuildItem

@BuildStep
public void producer(BuildProducer<AdditionalBeanBuildItem> additionalBeans) {    
  additionalBeans.produce(AdditionalBeanBuildItem.unremovableOf(3rdPartyFilter.class));
}

But this doesn't work and the filter doesn't run on requests.

Matt Berteaux
  • 763
  • 4
  • 12

2 Answers2

1

You can take a look at how other extensions do this, for example how the quarkus-smallrye-opentracing does it.

Essentially all you need is to add a JAX-RS DynamicFeature in the runtime module of your application.

@Provider
public class QuarkusSmallRyeTracingStandaloneVertxDynamicFeature implements DynamicFeature {

    @Override
    public void configure(ResourceInfo resourceInfo, FeatureContext context) {
        context.register(MyFilter.class);
    }

    public static class MyFilter implements ContainerRequestFilter {
        // whatever
    }
}
maxday
  • 1,322
  • 1
  • 16
  • 32
geoand
  • 60,071
  • 24
  • 172
  • 190
  • Is there something special way to get bean injected to a Filter that is registered this way? I am trying to inject some beans but they are showing up as null in the Filter. However, if I inject those same beans into a REST resource class they are injected just fine. – Matt Berteaux Jan 11 '20 at 20:17
  • 1
    You can't inject into the Filter using `@Inject`, however you can use `Arc.container().instance(...)` to obtain whatever bean you need – geoand Jan 13 '20 at 08:51
0

In addition to @geoand's answer, I think you also need to add a @BuildStep in the deployment part of your extension.

import io.quarkus.resteasy.common.spi.ResteasyJaxrsProviderBuildItem;

class MyProcessor {

    @BuildStep
    ResteasyJaxrsProviderBuildItem createOpentracingFilter() {
        return new ResteasyJaxrsProviderBuildItem(MyFilter.class.getName());
    }
}
maxday
  • 1,322
  • 1
  • 16
  • 32