I've a Jersey based REST Client and a GET call defined as this :
The code doesn't come out after the client.get() call. A null pointer exception is hit on the client.get() call , this is the initialization logic from the class which calls the REST client :
Student.java :
public class Student {
private static RestClient client;
@SuppressWarnings("static-access")
public Student(Client client) {
this.client = new RestClient(client, "xyz");
}
public static RestClient getClient() {
return client;
}
public static void addStudent() throws Exception {
try {
String addStudentUri = "https://www.zebapi.com/api/v1/market/ticker-new/btc/inr";
ClientResponse js_response = getClient().get(URI.create(addStudentUri));
String s = js_response.getEntity(String.class);
System.out.println(s);
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) {
try {
addStudent();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
RestClient.java
public class RestClient {
private Client client;
private String randomHeader = "";
public RestClient(Client jerseyClient) {
this.client = jerseyClient;
}
public RestClient(Client jerseyClient, String random) {
this.client = jerseyClient;
this.randomHeader = random;
}
public String getRandomHeader() {
return randomHeader;
}
public void setRandomHeader(String randomHeader) {
this.randomHeader = randomHeader;
}
public RestClient() {
}
public ClientResponse get(URI uri)
{
return client.resource(uri)
.get(ClientResponse.class);
}
public ClientResponse post(URI uri)
{
return client.resource(uri)
.type(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.post(ClientResponse.class);
}
}
Can you please help?