Commit f52cd298 authored by Joel Widmer's avatar Joel Widmer 💬

Move fetch to separate method

parent 7b3330ce
......@@ -29,19 +29,19 @@ public class ApiControlBean {
public ApiControlBean(){
ClientConfig config = new ClientConfig().connectorProvider(new ApacheConnectorProvider());
client = ClientBuilder.newClient(config);
updateEntries();
}
public List<EntryBean> getEntries() {
if(entries == null) {
System.out.println("Requesting data");
Response response = client.target(BASE_URL).path(ALL_USERS).request(MediaType.APPLICATION_JSON_TYPE).get();
response.bufferEntity();
System.out.println("Parsing response");
InputStreamReader inputStreamReader = new InputStreamReader((InputStream) response.getEntity());
this.entries = gson.fromJson(inputStreamReader, new TypeToken<ArrayList<EntryBean>>() {
}.getType());
}
private void updateEntries(){
System.out.println("Requesting data");
Response response = client.target(BASE_URL).path(ALL_USERS).request(MediaType.APPLICATION_JSON_TYPE).get();
response.bufferEntity();
System.out.println("Parsing response");
InputStreamReader inputStreamReader = new InputStreamReader((InputStream) response.getEntity());
this.entries = gson.fromJson(inputStreamReader, new TypeToken<ArrayList<EntryBean>>() {}.getType());
}
public List<EntryBean> getEntries() {
return entries;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment