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.citrix.g2w.webdriver.dependencies.AccountServiceQAIImpl.java

/**
 * constructor to initialize instance variables.
 *///from w  ww .  j  ava 2s.  co  m
public AccountServiceQAIImpl() {
    this.restTemplate = new RestTemplate();
    this.objectMapper = new ObjectMapper();
    this.g2wUtils = new G2WUtility();

    this.accountSvcHeaders = new HttpHeaders();
    this.accountSvcHeaders.add("Content-Type", "application/json");
    this.accountSvcHeaders.add("Accept", "application/json");
    this.accountSvcHeaders.add("ClientName", "test_provisioner");
}

From source file:com.cloudera.nav.plugin.client.NavApiCient.java

/**
 * Call the Navigator API and retrieve all available sources
 *
 * @return a collection of available sources
 *//* www .j ava  2 s .  com*/
public Collection<Source> getAllSources() {
    RestTemplate restTemplate = new RestTemplate();
    String url = getSourceUrl();
    HttpHeaders headers = getAuthHeaders();
    HttpEntity<String> request = new HttpEntity<String>(headers);
    ResponseEntity<SourceAttrs[]> response = restTemplate.exchange(url, HttpMethod.GET, request,
            SourceAttrs[].class);
    Collection<Source> sources = Lists.newArrayList();
    for (SourceAttrs info : response.getBody()) {
        sources.add(info.createSource());
    }
    return sources;
}

From source file:com.opensearchserver.hadse.index.IndexTest.java

@Test
public void t03_exists() {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

    RestTemplate template = new RestTemplate();

    ResponseEntity<String> entity = template.exchange("http://localhost:8080/my_index", HttpMethod.GET, null,
            String.class);

    assertEquals(HttpStatus.FOUND, entity.getStatusCode());
}

From source file:com.atwelm.aezwidget.responses.generic.GenericCell.java

private static RestTemplate getRestTemplate() {
    if (mRestTemplate == null) {
        mRestTemplate = new RestTemplate();
    }/*from  w w w .j  a  v  a  2s  . c  o  m*/
    return mRestTemplate;
}

From source file:com.hatta.consumer.App.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private static void listAllCustomers(AuthTokenInfo tokenInfo) {

    Assert.notNull(tokenInfo, "Authenticate first please......");

    RestTemplate restTemplate = new RestTemplate();
    ///*from   w w w  .j  a va2 s . c  o m*/
    //        HttpHeaders headers = new HttpHeaders();
    //        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

    HttpEntity<String> request = new HttpEntity<String>(getHeaders());
    ResponseEntity<List> response = restTemplate.exchange(
            REST_SERVICE_URI + "/api/user" + QPM_ACCESS_TOKEN + tokenInfo.getAccess_token(), HttpMethod.GET,
            request, List.class);
    List<LinkedHashMap<String, Object>> customerMap = (List<LinkedHashMap<String, Object>>) response.getBody();
    //         
    //        List<LinkedHashMap<String, Object>> customerMap = restTemplate.getForObject(REST_SERVICE_URI + "/api/user", List.class);

    if (customerMap != null) {
        System.out.println("Retrieve all customers:");
        for (LinkedHashMap<String, Object> map : customerMap) {
            System.out.println("Customer : id=" + map.get("id") + ", Name=" + map.get("name") + ", Address="
                    + map.get("email") + ", Email=" + map.get("password") + map.get("enabled"));
        }
    } else {
        System.out.println("No customer exist----------");
    }
}

From source file:com.goldengekko.meetr.itest.AuthITest.java

public AuthITest() {
    restTemplate = new RestTemplate();
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();

    MappingJacksonHttpMessageConverter jacksonHttpMessageConverter = new MappingJacksonHttpMessageConverter();
    ObjectMapper jacksonMapper = new ObjectMapper();
    jacksonMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    jacksonHttpMessageConverter.setObjectMapper(jacksonMapper);

    messageConverters.add(jacksonHttpMessageConverter);
    messageConverters.addAll(restTemplate.getMessageConverters());

    restTemplate.setMessageConverters(messageConverters);
}

From source file:com.crown.passthrough.controller.test.PassthroughControllerTest.java

/**
 * @throws java.lang.Exception/*  w  ww .  j ava2s. c o  m*/
 */
@Before
public void setUp() throws Exception {
    this.restTemplate = new RestTemplate();
    this.restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());

    this.uRIPrefix = "http://Localhost:8080/PassThrough";
}

From source file:ca.qhrtech.services.implementations.BGGServiceImpl.java

/**
 * Consumes a BGG XML API End Point and converts the response to a usable
 * POJO using the passed converter/*from  w w w.  j  ava  2  s .co  m*/
 *
 * @param <T> - Class the response should expect
 * @param <K> - Class the converter produces
 * @param uri - end point
 * @param t - Class the response should expect
 * @param converter - converts T to K
 * @return - results of the conversion
 */
private <T, K> K consumeBggApi(URI uri, Class<T> t, Converter<T, K> converter) {
    RestTemplate template = new RestTemplate();
    ResponseEntity<T> response;
    response = template.exchange(uri, HttpMethod.GET, buildXmlHttpHeader(), t);
    return converter.convert(response.getBody());
}

From source file:hu.fnf.devel.wishbox.gateway.GatewayREST.java

@RequestMapping(value = "/persistence/**", method = RequestMethod.GET)
public @ResponseBody String proxy(HttpServletRequest request) {
    String req = "";
    StringBuilder content = new StringBuilder();
    try {/*from   w  w w  . j  a  va  2  s .  co  m*/
        while (request.getReader().ready()) {
            content.append(request.getReader().readLine());
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    req = "user";
    try {
        req = request.getRequestURL().toString().split("/gateway/persistence")[1];
    } catch (ArrayIndexOutOfBoundsException e) {
        req = "/";
    }
    System.out.println(request.getRequestURL());

    System.out.println("Proxy call: " + req);
    System.out.println("Conent: " + content);

    RestTemplate restTemplate = new RestTemplate();
    try {
        return restTemplate.getForObject("http://localhost:9090/" + req, String.class);
    } catch (HttpClientErrorException e) {
        throw new HttpClientErrorException(e.getStatusCode());
    }
}