3

I'm trying to access a webservice (documentation: http://docs.bittpublic.apiary.io/#reference/public-http-api/ticker/gets-the-current-ticker-data-for-a-given-currency-pair). I need to take an info from this JSON, the field "volume" from the response. But I'm having problems in the client builder. Check my code/error:

Code:

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

Client client = ClientBuilder.newClient();
Entity payload = Entity.json("{  'productPair': 'BTCUSD'}");
Response response = client.target("https://api.bitt.com:8400")
         .path("/ajax/v1/GetTicker")
         .request(MediaType.APPLICATION_JSON_TYPE)
         .post(payload);

System.out.println("status: " + response.toString());

Error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/glassfish/jersey/internal/util/collection/UnsafeValue
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2663)
    at java.lang.Class.getConstructor0(Class.java:3067)
    at java.lang.Class.newInstance(Class.java:408)
    at javax.ws.rs.client.FactoryFinder.newInstance(FactoryFinder.java:118)
    at javax.ws.rs.client.FactoryFinder.find(FactoryFinder.java:225)
    at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:86)
    at javax.ws.rs.client.ClientBuilder.newClient(ClientBuilder.java:114)
    at exchanges.barbados.Bitt.getTicker(Bitt.java:72)
    at exchanges.barbados.Bitt.get24hrVol(Bitt.java:59)
    at exchanges.barbados.Bitt.<init>(Bitt.java:51)
    at main.Main.main(Main.java:363)
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.internal.util.collection.UnsafeValue
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 12 more
Java Result: 1

I have no idea what is org/glassfish/jersey/internal/util/collection/UnsafeValue and all info I found online was about putting one webservice online, not accesing it.

The jars I added:

javax.ws.rs-api-2.0.1.jar

jersey-client-2.17.jar

Ernani
  • 1,009
  • 3
  • 15
  • 26
  • possible duplicate of [Why am I getting a NoClassDefFoundError in Java?](http://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java) – GabrielOshiro Apr 30 '15 at 01:33

1 Answers1

7

You need jersey-common-2.17.jar. You can get it from here: http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.glassfish.jersey.core%22

Whenever you get a NoClassDefFoundError or a ClassNotFoundException on a third-party class, you can Google the class name and find out what jar file it should be in.

Josh Davis
  • 1,793
  • 1
  • 15
  • 21
  • Thanks a lot, this site helped me find 2 missing jars, however, there is other one missing. I now have: hk2-api-2.3.0.jar javax.ws.rs-api-2.0.1.jar jersey-client-2.17.jar jersey-common-2.17.jar jersey-guava-2.17.jar. And now its missing "ClassNotFoundException: com.sun.ws.rs.ext.RuntimeDelegateImpl". I searched online and it says it supposed to be on jersey-client-2.17.jar (http://stackoverflow.com/questions/9666584/com-sun-ws-rs-ext-runtimedelegateimpl-error)....however its not...any idea? – Ernani Apr 30 '15 at 02:03
  • That link is talking about Jersey 1.12. It looks like c.s.w.r.e.RuntimeDelegateImpl was part of jersey-client until 2.0, and then they did away with it. Judging from the jars you have listed there, I can't imagine what might still be referring to it. Are those all of the jars in your classpath? What does your stack trace look like? – Josh Davis Apr 30 '15 at 02:40