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;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s