rest
rest copied to clipboard
@Provider annotation on client on server-side
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
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.
#751 could be a vehicle to get this done
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.
Also related: https://github.com/eclipse-ee4j/jaxrs-api/issues/842.