private static void getEmployees()
{
    final String uri = "http://localhost:8080/springrestexample/employees.xml";
     
    RestTemplate restTemplate = new RestTemplate();
    String result = restTemplate.getForObject(uri, String.class);
     
    System.out.println(result);
}

        

Foo foo = restTemplate
  .getForObject(fooResourceUrl + "/1", Foo.class);
assertThat(foo.getName(), notNullValue());
assertThat(foo.getId(), is(1L));

        

Map<String, String> vars = new HashMap<String, String>();
vars.put("hotel", "42");
vars.put("booking", "21");
String result = restTemplate.getForObject("http://example.com/hotels/{hotel}/bookings/{booking}", String.class, vars);

        

@RequestMapping(value= "/fetchjson/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public Person getForObjectJsonDemo(@PathVariable(value = "id") Integer id) {
	Address address = new Address("Dhananjaypur","Varanasi", "UP");
	return new Person(id,"Ram", address);
} 

        

public class GetForObjectDemoWithJSON {
    public static void main(String args[]) {
        RestTemplate restTemplate = new RestTemplate();
        Person person = restTemplate.getForObject("http://localhost:8080/spring-rest/data/fetchjson/{id}", Person.class, 200);
        System.out.println("ID: " + person.getId());
        System.out.println("Name: " + person.getName());
        System.out.println("Village Name: " + person.getAddress().getVillage());
    }
}

        

public List<StreamFeatured> getFeatured(Optional<Long> limit, Optional<Long> offset) {
	// Endpoint
	String requestUrl = String.format("%s/streams/featured", Endpoints.API.getURL());
	RestTemplate restTemplate = getTwitchClient().getRestClient().getRestTemplate();

	// Parameters
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("limit", limit.orElse(25l).toString()));
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("offset", offset.orElse(0l).toString()));

	// REST Request
	try {
		StreamFeaturedList responseObject = restTemplate.getForObject(requestUrl, StreamFeaturedList.class);

		return responseObject.getFeatured();
	} catch (Exception ex) {
		Logger.error(this, "Request failed: " + ex.getMessage());
		Logger.trace(this, ExceptionUtils.getStackTrace(ex));
	}

	return new ArrayList<StreamFeatured>();
}

        

public ProductInformation byId(String id) {
    Map<String, String> uriParameters = new HashMap<>();
    uriParameters.put("id", id);
    RestTemplate rest = new RestTemplate();
    InventoryItemAmount amount =
            rest.getForObject(piSUBuilder.url("inventory"),
                    InventoryItemAmount.class,
                    uriParameters);
    log.info("amount {}.",amount);
    if ( amount.getAmount() > 0) {
        log.info("There items from {}. We are offering",id);
        return rest.getForObject(piSUBuilder.url("pi"),
                ProductInformation.class,
                uriParameters);
    } else {
        log.info("There are no items from {}. Amount is {}",id,amount);
        return ProductInformation.emptyProductInformation;
    }
}

        

public DataFlowTemplate(URI baseURI, RestTemplate restTemplate) {

	Assert.notNull(baseURI, "The provided baseURI must not be null.");
	Assert.notNull(restTemplate, "The provided restTemplate must not be null.");

	this.restTemplate = prepareRestTemplate(restTemplate);
	final ResourceSupport resourceSupport = restTemplate.getForObject(baseURI, ResourceSupport.class);
	this.runtimeOperations = new RuntimeTemplate(restTemplate, resourceSupport);
	this.appRegistryOperations = new AppRegistryTemplate(restTemplate, resourceSupport);
	this.completionOperations = new CompletionTemplate(restTemplate,
		resourceSupport.getLink("completions/stream"),
		resourceSupport.getLink("completions/task"));
	if (resourceSupport.hasLink(ApplicationTemplate.DEFINITIONS_REL)) {
		this.applicationOperations = new ApplicationTemplate(restTemplate, resourceSupport);
	}
	else {
		this.applicationOperations = null;
	}
}

        

private <T> T request(final String url, final Class<T> deconstructClass) {
    final RestTemplate restTemplate = new RestTemplate();
    T deconstructedResponse = null;

    try {
        deconstructedResponse = restTemplate.getForObject(url, deconstructClass);
    } catch (HttpClientErrorException err) {
        logger.info("[YoutubeReader] [request] Failure To Retrieve YouTube Resource (" + url + ")", err);
    }

    return deconstructedResponse;
}

        

public static boolean isServerListening(final URI url) {
    RestTemplate restTemplate = new RestTemplate();
    try {
        restTemplate.getForObject(url, String.class);
    } catch (RestClientException e) {
        if (e.getCause() instanceof ConnectException) {
            return false;
        }
    }
    return true;
}        
main