Java – HTTP GET request using Jersey client v1.17.1

This method is making a GET HTTP request to an URL an receive an XML response. It binds the XML response to an entity list.

public List<Entity> makeAGetRequest(String URL) {

 Client client = Client.create();
 WebResource webResource = client.resource(URL);
 ClientResponse response = webResource.accept("application/xml").get(ClientResponse.class);

 if (response.getStatus() != 200) {
 throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
 }

 GenericType<List<Entity>> genericTypeOfListOfEntities = new GenericType<List<Entity>>() {
 };
 List<Entity> result = response.getEntity(genericTypeOfListOfEntities);
 return result;
 }