smeeb
smeeb

Reputation: 29487

Upgrading from Jersey 1.x to 2.x

Please note: There are similar questions to this, but nothing that makes this an exact dupe.


I currently have the following Gradle dependencies:

dependencies {
    compile "com.sun.jersey.contribs:jersey-apache-client4:1.18.1"
    compile "com.sun.jersey:jersey-client:1.18.1"
    compile "com.sun.jersey:jersey-core:1.18.1"
    compile "com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.3.2"
    compile "org.apache.httpcomponents:httpclient:4.3.2"
    compile "org.slf4j:jcl-over-slf4j:1.7.7"
}

I want to upgrade these to the 2.21 versions of Jersey, however:

So I ask, what should all of my 2.21 dependencies be? Where's that Jersey/Apache client hiding out these days?

Upvotes: 2

Views: 4491

Answers (1)

Paul Samsotha
Paul Samsotha

Reputation: 208964

For Jersey client all you need is

compile 'org.glassfish.jersey.core:jersey-client:2.21'

jersey-core no longer exists, though it can be considered analogous to jersey-common. But you don't need to worry about this. jersey-client pulls it in.

As for Apache, Jersey 2 uses connector providers. See Client Transport Connectors. What you want is the Apache connector

compile 'org.glassfish.jersey.connectors:jersey-apache-connector:2.21'

Then just configure the Client

ClientConfig config = new ClientConfig();
config.connectorProvider(new ApacheConnectorProvider());
config.register(JacksonJsonProvider.class);
Client client = ClientBuilder.newClient(config);

You should also get rid of your current httpclient dependency. jersey-apache-connector pulls it in.

For General usage of the new Client API, see Chapter 5. Client API


Your question title is pretty general, though from the looks of your dependencies you are only trying to implement the client. But for anyone else that wants to implement the server, they can check out

Upvotes: 4

Related Questions