Crud with simple java REST webservices. Problems with jersey client class

Asked

Viewed 280 times

3

I have this class but it is giving many mistakes do not know what I do today that I try to solve. What I do?

 package manager.client;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.glassfish.jersey.client.ClientConfig;

import model.Cliente;
   public class MyClientGet {

public static void main(String[] args) {

 //ClientConfig config = new ClientConfig();

 Client client = ClientBuilder.newClient();

 WebTarget webTarget = client.target("http://localhost:8080/Test");

 WebTarget resourceWebTarget = webTarget.path("rest");
 WebTarget pathdWebTarget = resourceWebTarget.path("cliente");
 WebTarget pathdWebTargetQuery = pathdWebTarget.queryParam("id", 1);


 Invocation.Builder invocationBuilder = pathdWebTargetQuery.request(MediaType.APPLICATION_JSON_TYPE);

 Response response = invocationBuilder.get();

 //System.out.println(response.getStatus());
 Cliente user =  response.readEntity(Cliente.class);

 System.out.println("status: " + response.getStatus());
 System.out.println("headers: " + response.getHeaders());

 System.out.println(user.getId());
 System.out.println(user.getUserName());
 System.out.println(user.getPassword());

     }
}

You’re making the following mistake:

Exception in thread "main" java.lang.NoSuchMethodError: org.glassfish.jersey.internal.util.collection.Values.lazy(Lorg/glassfish/jersey/internal/util/collection/Value;)Lorg/glassfish/jersey/internal/util/collection/LazyValue;
at org.glassfish.jersey.client.ClientConfig$State.<init>(ClientConfig.java:117)
at org.glassfish.jersey.client.ClientConfig.<init>(ClientConfig.java:452)
at org.glassfish.jersey.client.JerseyClientBuilder.<init>(JerseyClientBuilder.java:94)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at javax.ws.rs.client.FactoryFinder.newInstance(FactoryFinder.java:116)
at javax.ws.rs.client.FactoryFinder.find(FactoryFinder.java:206)
at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:86)
at javax.ws.rs.client.ClientBuilder.newClient(ClientBuilder.java:114)
at manager.client.MyClientGet.main(MyClientGet.java:21)
  • 1

    I created a simple webservice template using the jersey. Take a look to see if it gives you some ideas: https://github.com/giuliana-bezerra/restclient

1 answer

0

Check the jars on your classpath. You must have a Jersey version incompatible with the JAX-RS version or a Jersey package with another Jersey package.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.