1

I am upgrading my extension to quarkus 2.9.0 and migrating to resteasy reactive.

Some of existing builditems in resteasy classic do not exist anymore in reactive implementation. I was using ResteasyJaxrsProviderBuildItem to record an ExceptionMapper and a ClientRequestFilter.

For my ExceptionMapper, I use now an ExceptionMapperBuildItem without any problem. But for my ClientRequestFilter, I do not know which builditem i have to choose (there is no such a ClientRequestFilterBuildItem)

Maybe am I missing something obvious ? Thanks

godo57
  • 508
  • 2
  • 24

2 Answers2

1

ClientRequestFilter for the REST Client are registered via @RegisterProvider, so no build item is needed

geoand
  • 60,071
  • 24
  • 172
  • 190
  • Thanks, can you explain why is it a difference between registering ClientRequestFilter and for example ContainerRequestFilter which needs a build item ? – godo57 May 18 '22 at 14:08
  • Can you elaborate a little more on the quesion? I don't really understand what you are asking – geoand May 18 '22 at 15:39
  • Why is there a BuiltItem for a ContainerRequestFilter and not for a ClientRequestFilter ? – godo57 May 25 '22 at 13:04
  • Because the latter is never needed – geoand May 27 '22 at 05:48
  • But if I am writing a QuarkusApplication, I can have a ClientRequestFilter registered in the application that will modify requests without annotating the interfaces (which aren't under my control - I could inherit from them, but I rather wouldn't have that boilerplate code), whereas I'm not sure I can do that with code coming from an extension? – Gregor Petrin Jan 24 '23 at 08:33
  • You can certainly open an issue asking for the feature – geoand Jan 24 '23 at 12:37
0

I had a similar issue; I wanted to use an extension to instrument an application and add request and response filters. For the ContainerResponseFilter, I used a ContainerResponseFilterBuildItem to register it.

For the ClientRequestFilter, I was a bit stuck. I eventually had success using a RegisterProviderAnnotationInstanceBuildItem. What this process is doing is an extension-side version of what the manual process would be; find classes annotated with @RestClient, and add a @RegisterProvider(ClientFilter.class):

    private static final DotName CLIENT_FILTER = DotName.createSimple(ClientFilter.class.getName());
    private static final DotName REGISTER_REST_CLIENT = DotName.createSimple("org.eclipse.microprofile.rest.client.inject.RegisterRestClient");


    @BuildStep
    void clientFilterSupport(CombinedIndexBuildItem indexBuildItem, BuildProducer<GeneratedBeanBuildItem> generatedBean,
                             BuildProducer<RegisterProviderAnnotationInstanceBuildItem> producer) {

        Collection<AnnotationInstance> instances = indexBuildItem.getIndex().getAnnotations(REGISTER_REST_CLIENT);
        for (AnnotationInstance instance : instances) {

            final AnnotationValue valueAttr = createClassValue(CLIENT_FILTER);

            String targetClass = instance.target().asClass().name().toString();
            producer.produce(new RegisterProviderAnnotationInstanceBuildItem(targetClass, AnnotationInstance.create(
                    DotNames.REGISTER_PROVIDER, instance.target(), List.of(valueAttr))));
        }
    }

The helper for making annotation values is just

    private AnnotationValue createClassValue(DotName filter) {
        return AnnotationValue.createClassValue("value",
                Type.create(filter, Type.Kind.CLASS));
    }

I also told CDI about the filter:

    @BuildStep
    void beans(BuildProducer<AdditionalBeanBuildItem> producer) {
          producer.produce(AdditionalBeanBuildItem.unremovableOf(ClientFilter.class));
    }
Holly Cummins
  • 10,767
  • 3
  • 23
  • 25