Get / Retrieve json response from JAX REST web service

Posted: November 29, 2012 in web

Getting response as List

    public List<Car> findCar(String maker) {
        try {
            return (new ClientRequest("http://localhost/cartest/rest/maker/" + maker)).get(ClientResponse.class).getEntity(
                    new GenericType<List<Car>>() {
                    });
        } catch (Exception e1) {
            return new ArrayList<Car>();
        }
    }

Getting response as String

    public String findCar(String vin) {
        try {
            return (new ClientRequest("http://localhost/cartest/rest/vin/" + vin)).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class).getEntity(String.class);
        } catch (Exception e1) {
            return null;
        }
    }

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s