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:com.unito.controller.PageController.java

@RequestMapping(value = { "/logout", "/logoutapp" }, method = GET)
public String logout(@AuthenticationPrincipal User customUser) {
    UserDetails userDetails;/*ww w.  ja v  a 2 s.  c om*/
    RestTemplate restTemplate = new RestTemplate();

    LOG.info("logout");
    LOG.info("ustom user = " + customUser);

    userDetails = userDetailsRepository.find(customUser.getUsername());
    if (userDetails != null) {
        LOG.info("GET:" + REVOKE_URL + userDetails.getAccesstoken());
        restTemplate.getForObject(REVOKE_URL + userDetails.getAccesstoken(), String.class);
    } else
        return "redirect: logoutws?googleinssuccess"; //was a problem with google session login
    return "redirect: logoutws";
}

From source file:org.syncope.core.rest.AbstractTest.java

protected RestTemplate anonymousRestTemplate() {
    return new RestTemplate();
}

From source file:fm.last.lastfmlive.service.TwitterClient.java

private static List<Tweet> checkForHashTaggedTweets(String hashTag) {
    log.debug("Searching Twitter for tweets containing #" + hashTag);

    RestTemplate restTemplate = new RestTemplate();
    Map<?, ?> tweets = restTemplate.getForObject(searchUrl + "{hashTag}", Map.class, "#" + hashTag);
    List<?> results = (List<?>) tweets.get("results");

    log.info("Tweets found: {}", results.size());
    return Lists.transform(results, ExtractTweet.INSTANCE);
}

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

@Bean
public RestTemplate unisportRestTemplate() {
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.setMessageConverters(getConverters());
    restTemplate.setInterceptors(Lists.newArrayList(new LoggingInterceptor()));
    return restTemplate;
}

From source file:bq.tutorial.netflix.hystrix.DynamicTest.java

@Test(invocationCount = 2000, threadPoolSize = 20)
public void testStatusRejected() {
    String commandName = "name" + (int) (Math.random() * 100);
    float failPercent = (float) Math.random();
    float timeoutPercent = (float) Math.random();
    int percentToBreakCircuit = (int) (Math.random() * 50 + 50);

    String queryString = "?name=" + commandName + "&failPercent=" + failPercent + "&timeoutPercent="
            + timeoutPercent + "&percentToBreakCircuit=" + percentToBreakCircuit;

    RestTemplate client = new RestTemplate();
    String result = client.getForObject("http://localhost:8080/netflix_hystrix/mvc/dynamic" + queryString,
            String.class);
    System.out.println(result);/*from w  w w  .ja v a  2  s.c om*/
}

From source file:io.fabric8.che.starter.client.WorkspaceClient.java

public List<Workspace> listWorkspaces(String cheServerUrl) {
    String url = CheRestEndpoints.LIST_WORKSPACES.generateUrl(cheServerUrl);
    RestTemplate template = new RestTemplate();
    ResponseEntity<List<Workspace>> response = template.exchange(url, HttpMethod.GET, null,
            new ParameterizedTypeReference<List<Workspace>>() {
            });/*  w  w  w  .  ja  v  a2  s  .  c o m*/

    return response.getBody();
}

From source file:io.pivotal.tzolov.gemfire.GemfireHawqAdapterService.java

@SuppressWarnings("rawtypes")
@Override//from   w ww .  j  a v  a 2  s . co  m
public void run(String... args) throws Exception {

    List rows = new RestTemplate().getForObject(
            "http://{hostname}:{port}/gemfire-api/v1/queries/adhoc?q={query}", List.class, hostName, port,
            oqlQuery);

    for (Object row : rows) {

        String outputRow = "";

        if (row instanceof String) {
            outputRow = (String) row;
        } else if (row instanceof Map) {

            Map mapItem = ((Map) row);

            int i = 0;
            for (Object value : mapItem.values()) {
                i++;
                String columnValue = toColumnValue(value);
                outputRow = (i == 1) ? columnValue : outputRow + columnDelimiter + columnValue;
            }
        } else {
            throw new IllegalStateException("Unsupported return class type: " + row.getClass());
        }

        System.out.println(outputRow);
    }
}

From source file:com.unknown.pkg.TwintipCustomProfileApplicationIT.java

@Test
public void isConfigured() {

    String endpointUrl = "http://localhost:" + port + "/.well-known/schema-discovery";
    LOG.info("ENDPOINT_URL : {}", endpointUrl);

    RestTemplate template = new RestTemplate();
    ResponseEntity<String> entity = template.getForEntity(endpointUrl, String.class);
    HttpStatus statusCode = entity.getStatusCode();
    String body = entity.getBody();

    Assertions.assertThat(statusCode).isEqualTo(HttpStatus.OK);
    Assertions.assertThat(body).contains("swagger-unreleased");

    LOG.info("BODY : {}", body);

}

From source file:org.jasig.i18n.translate.AutoTranslationService.java

public AutoTranslationService() {
    this.restTemplate = new RestTemplate();
    List<HttpMessageConverter<?>> converters = Collections
            .<HttpMessageConverter<?>>singletonList(new MappingJacksonHttpMessageConverter());
    this.restTemplate.setMessageConverters(converters);
}

From source file:com.bodybuilding.argos.discovery.ClusterListDiscoveryTest.java

@Test
public void testGetClusters() {
    String mockBody = "" + "[\n" + "{\n" + "\"name\": \"test1\",\n" + "\"link\": \"http://meh.com\",\n"
            + "\"turbineStream\": \"http://meh.com/turbine/turbine.stream?cluster=test1\"\n" + "},\n" + "{\n"
            + "\"name\": \"test2\",\n" + "\"link\": \"http://meh2.com\",\n"
            + "\"turbineStream\": \"http://meh2.com:8080/turbine/turbine.stream?cluster=test2\"\n" + "}" + "]";

    RestTemplate restTemplate = new RestTemplate();
    MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate);
    mockServer.expect(requestTo("http://127.0.0.1")).andExpect(method(HttpMethod.GET))
            .andRespond(withSuccess(mockBody, MediaType.APPLICATION_JSON));
    ClusterListDiscovery discovery = new ClusterListDiscovery(Sets.newHashSet("http://127.0.0.1"),
            restTemplate);//from   w w  w  .  j av a2s.c  o  m
    Collection<Cluster> clusters = discovery.getCurrentClusters();
    mockServer.verify();
    assertNotNull(clusters);
    assertEquals(2, clusters.size());
}