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:wheelmap.org.request.RequestProcessor.java

public RequestProcessor() {
    restTemplate = new RestTemplate();
    restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
}

From source file:com.mycompany.trader.TradingConnect.java

private static void loginAndSaveJsessionIdCookie(final String user, final String password,
        final HttpHeaders headersToUpdate) {

    String url = "http://localhost:" + port + "/blueprint-trading-services/login.html";

    new RestTemplate().execute(url, HttpMethod.POST, new RequestCallback() {
        @Override/*from  www  . j  ava  2 s.c o  m*/
        public void doWithRequest(ClientHttpRequest request) throws IOException {
            MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
            map.add("username", user);
            map.add("password", password);
            new FormHttpMessageConverter().write(map, MediaType.APPLICATION_FORM_URLENCODED, request);
        }
    }, new ResponseExtractor<Object>() {
        @Override
        public Object extractData(ClientHttpResponse response) throws IOException {
            headersToUpdate.add("Cookie", response.getHeaders().getFirst("Set-Cookie"));
            return null;
        }
    });
}

From source file:cz.muni.fi.mushroomhunter.restclient.AllLocationSwingWorker.java

@Override
protected List<LocationDto> doInBackground() throws Exception {
    String plainCreds = RestClient.USER_NAME + ":" + RestClient.PASSWORD;
    byte[] plainCredsBytes = plainCreds.getBytes();
    byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
    String base64Creds = new String(base64CredsBytes);

    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Basic " + base64Creds);

    HttpEntity<String> request = new HttpEntity<>(headers);
    RestTemplate restTemplate = new RestTemplate();
    ResponseEntity<LocationDto[]> responseEntity = restTemplate.exchange(
            RestClient.SERVER_URL + "pa165/rest/location/", HttpMethod.GET, request, LocationDto[].class);
    LocationDto[] locationDtoArray = responseEntity.getBody();
    List<LocationDto> locationDtoList = new ArrayList<>();
    locationDtoList.addAll(Arrays.asList(locationDtoArray));
    return locationDtoList;
}

From source file:io.pivotal.dockerhub.client.DockerHubTemplate.java

public DockerHubTemplate(String dockerHubHost) {
    this(dockerHubHost, new RestTemplate());
}

From source file:org.meruvian.yama.social.google.GooglePlusService.java

public GooglePlusService(OAuth2ConnectionFactory<Google> google) {
    super(google);
    restTemplate = new RestTemplate();
}

From source file:id.co.teleanjar.ppobws.restclient.RestClientService.java

public User getUser(String username) {
    RestTemplate restTemplate = new RestTemplate();

    //User user = restTemplate.getForObject("http://localhost:8080/ppobws/api/user?username=" + username, User.class);

    String uri = "http://localhost:8080/ppobws/api/user?username=" + username;

    ResponseEntity<User> respEntity = restTemplate.exchange(uri, HttpMethod.GET,
            new HttpEntity<String>(createHeaders("superuser", "passwordku")), User.class);

    return respEntity.getBody();
}

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

/**
 * more test thread pool size than command thread pool, to cause many rejected error
 *///from   w ww.j ava 2  s. com
@Test(invocationCount = 2000, threadPoolSize = 20)
public void testStatusRejected() {
    RestTemplate client = new RestTemplate();
    String result = client.getForObject("http://localhost:8080/netflix_hystrix/mvc/pressure", String.class);
    System.out.println(result);
}

From source file:com.github.shirashiki.exspring.test.integration.AbstractIntegrationTest.java

/**
 * GreetingController implements the path greeting, which should return an echo message.
 * This is using Jackson (https://github.com/FasterXML/jackson) to convert JSON
 * to object/*  w ww .ja  v a  2s. c o m*/
 * @throws Exception
 */
@Test
public void testGreetingEcho() throws Exception {
    RestTemplate restTemplate = new RestTemplate();

    // Checks if returns the default greeting
    Greeting emptyGreeting = restTemplate.getForObject(SERVER + "/greeting", Greeting.class);
    assertEquals(1, emptyGreeting.getId());
    assertEquals("Hello, World!", emptyGreeting.getContent());

    // Checks if generates the greeting with parameters 
    String echoStr = "Montreal Canadiens";
    Greeting myGreeting = restTemplate.getForObject(SERVER + "/greeting?name=" + echoStr, Greeting.class);
    assertEquals(1, myGreeting.getId());
    assertEquals("Hello, " + echoStr + "!", myGreeting.getContent());
}

From source file:org.cloudfoundry.identity.uaa.login.UaaChangePasswordServiceTest.java

@Before
public void setUp() throws Exception {
    RestTemplate uaaTemplate = new RestTemplate();
    mockUaaServer = MockRestServiceServer.createServer(uaaTemplate);
    subject = new UaaChangePasswordService(uaaTemplate, "http://uaa.example.com/uaa");
}

From source file:edu.fing.tagsi.db4o.business.CiudadesController.java

public Recorrido ObtenerRecorrido(Ciudad origen, Ciudad destino) {
    RestTemplate restTemplate = new RestTemplate();
    RequestRecorrido req = new RequestRecorrido(origen.getNombre(), destino.getNombre());
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity<RequestRecorrido> entity = new HttpEntity<>(req, headers);
    RecorridoREST recorrido = restTemplate.postForObject(URL, entity, RecorridoREST.class);

    if (recorrido.getCiudades() != null) {
        NodoCamino[] ciudades = new NodoCamino[recorrido.getCiudades().length];
        for (int i = 0; i < ciudades.length; i++) {
            if (i == 0) {
                ciudades[i] = new NodoCamino(ObtenerCiudad(recorrido.getCiudades()[i].getName()), true, 0,
                        null);/*from www. j  a  va 2s  .c om*/
            } else {
                Tramo tramo = recorrido.getRutas()[i - 1];
                ciudades[i] = new NodoCamino(ObtenerCiudad(recorrido.getCiudades()[i].getName()), false,
                        tramo.getDistancia(), tramo.getRutas());
            }
        }
        Recorrido resultado = new Recorrido(recorrido.getDistanciaTotal(), ciudades);
        return resultado;
    } else {
        return null;
    }

}