Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject Client via CDI #749

Open
sdaschner opened this issue Mar 15, 2019 · 5 comments
Open

Inject Client via CDI #749

sdaschner opened this issue Mar 15, 2019 · 5 comments
Labels
api enhancement New feature or request

Comments

@sdaschner
Copy link

It would be a nice addition if the JAX-RS Client type can be injected via @Inject (see #569, #60, #639) which results in the same result as ClientBuilder.newClient(). However, by doing so we facilitate to mock the JAX-RS client out of classes in test scopes.

Additionally, the ClientBuilder could also be injectable, if users want to use injection with further configuration and still enable the implementation to be mocked. The issue with having client calls in test scopes is that the static ClientBuilder.newBuilder() attempts to load via SPI and is hard to mock (being static).

Example for the second suggestion:

public class Foobar {

    @Inject
    ClientBuilder clientBuilder;

    private Client client;

    @PostConstruct
    private void initClient() {
        client = clientBuilder
                .connectTimeout(1, TimeUnit.SECONDS)
                .readTimeout(3, TimeUnit.SECONDS)
                .build();
    }

    // OR via constructor-based injection

    private Client client;
    
    @Inject
    public Foobar(ClientBuilder clientBuilder) {
        client = clientBuilder
                .connectTimeout(1, TimeUnit.SECONDS)
                .readTimeout(3, TimeUnit.SECONDS)
                .build();
    }
}
@mkarg
Copy link
Contributor

mkarg commented Apr 25, 2019

In line with our roadmap we should cover this in JAX-RS 3.0.

@mkarg mkarg added api enhancement New feature or request labels Apr 25, 2019
@jeyvison
Copy link

jeyvison commented Jul 6, 2019

Is this something we could start working on or we should wait 'till 2.2 is out?

@mkarg
Copy link
Contributor

mkarg commented Jul 7, 2019

@jeyvison Great to have you on board! Please find the roadmap in our wiki. CDI will be part of JAX-RS 3.0, which is rather far away. So if you start working on that, it could happen that you need to fix git conflicts from time to time. If you don't fear that, have fun coding! :-)

@kalgon
Copy link

kalgon commented Oct 20, 2019

Could you please foresee in the spec all the extension/configuration points needed by a standalone client (not deployed in a EE container) to use CDI-SE?

@mkarg
Copy link
Contributor

mkarg commented Oct 20, 2019

Could you please foresee in the spec all the extension/configuration points needed by a standalone client (not deployed in a EE container) to use CDI-SE?

I think we could cover that with JAX-RS 3.0. JAX-RS 2.x does not regulate CDI SE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants