Example usage for org.springframework.web.client RestTemplate RestTemplate

List of usage examples for org.springframework.web.client RestTemplate RestTemplate

Introduction

In this page you can find the example usage for org.springframework.web.client RestTemplate RestTemplate.

Prototype

public RestTemplate() 

Source Link

Document

Create a new instance of the RestTemplate using default settings.

Usage

From source file:fi.helsinki.opintoni.config.UsefulLinksConfiguration.java

@Bean
public RestTemplate linkUrlLoaderRestTemplate() {
    return new RestTemplate();
}

From source file:sample.mustache.WelcomeController.java

@RequestMapping("/")
public String welcome(Map<String, Object> model) {
    Name name = new RestTemplate().getForObject(backend, Name.class);

    model.put("time", new Date());
    model.put("message", String.format("Hello %s", name.fullName()));

    return "welcome";
}

From source file:demo.client.EventClient.java

public EventClient(String hostUri) {
    resourceUri = hostUri + ResourcePaths.TASK_PATH;
    restTemplate = new RestTemplate();
    restTemplate.setErrorHandler(new DefaultResponseErrorHandler());
}

From source file:com.mattjtodd.sample.RandomWhaleTest.java

@Test
public void checkService() {
    RestTemplate restTemplate = new RestTemplate();
    Whale whale = restTemplate.getForObject(getProperty("log.url"), Whale.class);

    assertNotNull(whale.getName());/*from  w  ww. j  ava  2  s .  c  o m*/
}

From source file:com.bytebybyte.mapquest.geocoding.service.standard.MapQuestTest.java

@Test
public void getGoogleMap() {
    String API_KEY = "AIzaSyAv9WhULXF0Ri_C19NGyV2-rCUh50nMNA4";

    RestTemplate restTemplate = new RestTemplate();
    String url = "https://maps.googleapis.com/maps/api/geocode/json?address=11480 Sunset Hills Road, Reston, VA 20190&key="
            + API_KEY;/*  w w w.j a va2  s . co  m*/

    String result = restTemplate.getForObject(url, String.class);
    System.out.println("Result : " + result);

    /*HttpEntity<String> newentity = new HttpEntity<String>(headers);
    ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, newentity, String.class);
    System.out.println("Response : " + response);*/

    JsonElement jelement = new JsonParser().parse(result);
    JsonObject jobject = jelement.getAsJsonObject();
    JsonArray jarray = jobject.getAsJsonArray("results");
    jobject = jarray.get(0).getAsJsonObject();

    System.out.println(jobject.get("geometry"));

    JsonElement je = new JsonParser().parse(jobject.get("geometry").toString());
    JsonObject jo = je.getAsJsonObject();
    jo = jo.getAsJsonObject("location");
    System.out.println("Lat : " + jo.get("lat"));
    System.out.println("Lon : " + jo.get("lng"));
}

From source file:cn.org.once.cstack.utils.RestUtils.java

@SuppressWarnings("rawtypes")
public static String sendPostCommand(String url, String volume) {

    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.add("Accept", "text/plain");
    MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
    params.add("Binds", volume);
    @SuppressWarnings("unchecked")
    HttpEntity request = new HttpEntity(params, headers);
    ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class);
    return response.toString();
}

From source file:com.mycompany.story.StoryEditor.java

private void initData() throws IOException {
    RestTemplate restTemplate = new RestTemplate();
    Properties properties = new Properties();
    properties.load(new InputStreamReader(getClass().getResourceAsStream("/story.ini")));
    String host = properties.getProperty("host");
    String url = host + "/story";
    restTemplate.getForObject(host, TopicResult.class, ImmutableMap.of("topicId", "1"));
}

From source file:org.jtalks.tests.jcommune.mail.mailtrap.MailtrapClient.java

/**
 * Gets list of messages metadata/*  ww w. ja  va 2s .c  o m*/
 *
 * @return the list of messages metadata
 * @throws CouldNotGetMessagesException
 */
public static String getMessages() throws CouldNotGetMessagesException {
    RestTemplate client = new RestTemplate();
    try {
        String data = client.getForObject(
                new URI(API_INBOXES_URL + JTALKS_AUTOTESTS_MESSAGES + API_TOKEN_PARAM), String.class);
        return data;
    } catch (Exception e) {
        throw new CouldNotGetMessagesException(e);
    }
}

From source file:com.github.harti2006.Neo4jServerIT.java

@Test
public void testNeo4jServerIsRunning() throws Exception {
    final RestTemplate restTemplate = new RestTemplate();
    final RequestEntity<Void> request = RequestEntity.get(create(System.getProperty("neo4j-server.url")))
            .accept(APPLICATION_JSON).build();
    final ResponseEntity<String> responseEntity = restTemplate.exchange(request, String.class);

    assertEquals(OK, responseEntity.getStatusCode());
    System.out.println(responseEntity);
}

From source file:com.nebhale.gpxconverter.Application.java

@Bean
RestOperations restOperations() {
    return new RestTemplate();
}