rest icon indicating copy to clipboard operation
rest copied to clipboard

@Provider annotation on client on server-side

Open marekkopecky opened this issue 6 years ago • 4 comments

According to the spec, it seems that ClientRequestFilter with @Provider annotation should be used with Client without registration. This behaviour currently doesn't work on Jersey, RESTEasy fix this on server side (see RESTEASY-2084, RESTEASY-2163)

I suggest to make clear in the spec, that this can work on server side, but not on standalone client application (outside of the container).

Example of server-side client usage:

@Provider
public class TestClientRequestFilter implements ClientRequestFilter {
    public void filter(ClientRequestContext clientRequestContext) {
        System.out.println("Hello from ClientRequestFilter");    
    }
}
@Path("/a")
public class Resource {
    @GET
    @Path("/a")
    public String a() {
        return "ok";
    }
    @Path("/b")
    @GET
    public String b() {
        Client client = ClientBuilder.newBuilder().build();
        final WebTarget target = client.target("http://127.0.0.1:8080/jaxrs-wf/a/a");
        final Response response = target.request().get();
        System.out.println(response.getStatus());
        System.out.println(response.readEntity(String.class));
        System.out.println();
        return "ok";
    }
}

The same situation is for ClientResponseFilter, MessageBodyReader, MessageBodyWriter, AsyncClientResponseProvider, ReaderInterceptor, WriterInterceptor, DynamicFeature

marekkopecky avatar Feb 22 '19 07:02 marekkopecky

Yes, I agree this needs to be clarified. Generally speaking, support for @Provider requires a form of class scanning which is normally supported in server environments, and the mechanism was originally crafted to locate providers connected to the server API.

spericas avatar Feb 22 '19 14:02 spericas

#751 could be a vehicle to get this done

mkarg avatar Apr 25 '19 11:04 mkarg

A related (I think) issue has come up in the MicroProfile REST Client group. MP REST Client defines a class, ClientHeadersFactory, which is, essentially, a provider, and the proposed 1.4 spec says that CDI and @Context injection should work for ClientHeadersFactory's. The thing is, ClientHeadersFactory's are part of a MP REST Client environment, and the JAX-RS spec says that all but two @Context injectable classes are only for the server side. So, if a MP REST Client is running in a JAX-RS resource, should it have access to the server side @Context injectable classes? More generally, should a MP REST Client running in a JAX-RS resource have access to the server environemt? I think the answer depends on the answer to the same question for JAX-RS Clients.

ronsigal avatar Jan 30 '20 11:01 ronsigal

Also related: https://github.com/eclipse-ee4j/jaxrs-api/issues/842.

ronsigal avatar Dec 16 '20 01:12 ronsigal