Skip to content

Client running in server context #842

@ronsigal

Description

@ronsigal

I don't think the relationship between a Client running inside a JAX-RS resource and the server context has ever been clarified. For example, if a provider is discovered by the server container, should it be available to the client? (See #746, for example.) Similarly, if a provider used by a Client running in a resource does @context injection, should it be able to inject all of the injectable types, or just the two (Configuration and Providers) available to the "client side"?

I propose to extend ClientBuilder to make the server context optionally available to a client. In particular, I propose the following two methods:

       /**
        * Determine if Client can access the content of the JAX-RS server
        * side deployment, if it's running in one. Access defaults to true.
        *
        * @param b
        * @return an updated client builder instance
        */
       public abstract ClientBuilder accessServerContext(boolean b);
      
       /**
        * Deactivate a provider
        *
        * @param providerClass class to be deactivated
        * @return an updated client builder instance
        */
       public abstract ClientBuilder disable(Class<?> providerClass);

Suppose three provider classes are registered with the server, C1, C2, and C3, and only the first two are needed. Then do this:

     ClientBuilder.newClient()
        .accessServerContext(true)
        .disable(C3.class);

Here are a couple of use cases.

  1. The next MicroProfile REST Client spec version 1.4 (https://projects.eclipse.org/projects/technology.microprofile/releases/rest-client-1.4) proposes that it be possible to inject HttpHeaders into a ClientHeadersFactory object.

  2. A client might need access to a security token from a request to propagate it with the client invocation. (Thanks, Bill Burke for that one.)

-Ron

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions