Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Classes from "com.sun.*" and "sun.*" packages should not be used Sonar issue for Jersey client

I am using jersey client for rest calls. Imports for my code are:

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;

Everything is working fine. I am using Sonar for checking my Code quality.

sonar is showing a major issue for:

Classes from "com.sun." and "sun." packages should not be used

Is this actually bad practice to use classes from sun?

If yes, what are the alternatives?

like image 611
Dev Avatar asked Sep 22 '15 10:09

Dev


1 Answers

It's better to migrate to JAX-RS 2.0 client classes. Some refactoring would be necessary though. See the migration guide. For example, if you wrote like this before:

Client client = Client.create();
WebResource webResource = client.resource(restURL).path("myresource/{param}");
String result = webResource.pathParam("param", "value").get(String.class);

You should write now like this:

Client client = ClientFactory.newClient();
WebTarget target = client.target(restURL).path("myresource/{param}");
String result = target.pathParam("param", "value").get(String.class);
like image 76
Tagir Valeev Avatar answered Sep 28 '22 09:09

Tagir Valeev