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

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

Introduction

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

Prototype

@Override
    @Nullable
    public <T> T getForObject(URI url, Class<T> responseType) throws RestClientException 

Source Link

Usage

From source file:uy.edu.ort.fachada.FachadaOperaciones.java

/**
 * Operaciones sobre la Entidad Partida/*from  w  ww  . ja  va 2 s  .  c  o  m*/
 */

public static void generarReportePartidasMes(String mes) {
    String url = ManejoPropiedades.obtenerInstancia().obtenerPropiedad("restService")
            + "restpartida/partidas.htm?mes=" + mes;

    RestTemplate restTemplate1 = new RestTemplate();
    restTemplate1.getMessageConverters().add(new StringHttpMessageConverter());
    restTemplate1.getMessageConverters().add(new MappingJacksonHttpMessageConverter());

    Partida[] partidasResultado = restTemplate1.getForObject(url, Partida[].class);
    System.out.println("\tId \t\tDestino \t\tFecha \t\tDescripcion \t\tBarco \t\tContenedores");
    for (Partida partida : partidasResultado) {
        String fechaString = new SimpleDateFormat("dd-MM-yyyy").format(partida.getFecha());
        String codigoConts = "";
        for (Object c : partida.getContenedores()) {
            codigoConts += " - " + ((LinkedHashMap) c).get("codigo");
        }
        codigoConts += " - ";
        System.out.println("\t" + partida.getId() + "\t\t" + partida.getDestino() + " \t\t" + fechaString
                + " \t\t" + partida.getDescripcion() + " \t\t" + partida.getBarco().getCodigo() + " \t\t"
                + codigoConts);

    }
}

From source file:uy.edu.ort.fachada.FachadaOperaciones.java

public static void generarReportePartidasMesBarco(String mes, String idBarco) {
    String url = ManejoPropiedades.obtenerInstancia().obtenerPropiedad("restService")
            + "restpartida/partidas.htm?mes=" + mes + "&idBarco=" + idBarco;

    RestTemplate restTemplate1 = new RestTemplate();
    restTemplate1.getMessageConverters().add(new StringHttpMessageConverter());
    restTemplate1.getMessageConverters().add(new MappingJacksonHttpMessageConverter());

    Partida[] partidasResultado = restTemplate1.getForObject(url, Partida[].class);
    System.out.println("\tId \t\tDestino \t\tFecha \t\tDescripcion \t\tBarco \t\tContenedores \t\tPeso Total");
    for (Partida partida : partidasResultado) {
        String fechaString = new SimpleDateFormat("dd-MM-yyyy").format(partida.getFecha());
        String codigoConts = "";
        int peso = 0;
        for (Object c : partida.getContenedores()) {
            codigoConts += " - " + ((LinkedHashMap) c).get("codigo");
            Object capacidad = ((LinkedHashMap) c).get("capacidad");
            peso += (Integer) capacidad;
        }/*from  w w w  .j av a 2s  .co  m*/
        codigoConts += " - ";
        System.out.println("\t" + partida.getId() + "\t\t" + partida.getDestino() + " \t\t" + fechaString
                + " \t\t" + partida.getDescripcion() + " \t\t" + partida.getBarco().getCodigo() + " \t\t"
                + codigoConts + " \t\t" + peso);

    }
}

From source file:uy.edu.ort.fachada.FachadaOperaciones.java

public static void listarTrazas() {
    String url = ManejoPropiedades.obtenerInstancia().obtenerPropiedad("restService") + "resttrace/all.htm";

    RestTemplate restTemplate1 = new RestTemplate();
    restTemplate1.getMessageConverters().add(new StringHttpMessageConverter());
    restTemplate1.getMessageConverters().add(new MappingJacksonHttpMessageConverter());

    Trace[] trazas = null;/*from ww  w .j  a v a2 s.c om*/
    try {
        trazas = restTemplate1.getForObject(url, Trace[].class);
    } catch (Exception e) {
        System.out.println(e.getStackTrace().toString());
    }

    System.out.println("\tFecha \t\tDescripcion");
    for (Trace t : trazas) {
        String fechaString = new SimpleDateFormat("dd-MM-yyyy").format(t.getFecha());
        System.out.println("\t" + fechaString + "\t\t" + t.getDescripcion());
    }
}

From source file:de.aikiit.sonaranalysis.Application.java

@Override
public void run(String... strings) throws Exception {
    RestTemplate restTemplate = new RestTemplate();
    Quote quote = restTemplate.getForObject("http://gturnquist-quoters.cfapps.io/api/random", Quote.class);
    log.info(quote.toString());/*  w  ww.  j  a  va2 s . c  om*/
    log.info("Application finished successfully.");
}

From source file:com.anuz.dummyclient.controller.service.ClientService.java

public ModelMap htmtUpdates(String url) {

    RestTemplate restTemplate = new RestTemplate();
    ModelMap map = restTemplate.getForObject(url, ModelMap.class);
    return map;//ww w.j  a  va 2s  .  co m
}

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 ww w.j a  v  a2  s  .c om
}

From source file:com.capgemini.parking.groups.ParkPollGroupService.java

public ParkPollGroups getParkPollGroups() {
    RestTemplate restTemplate = new RestTemplate();
    ParkPollGroups parkPollGroups = restTemplate.getForObject(configuration.getUrl(), ParkPollGroups.class);
    return parkPollGroups;
}

From source file:eu.impress.impressplatform.Services.DHC.RESTManager.java

public String consumePopulation() {

    RestTemplate restTemplate = new RestTemplate();
    String s = restTemplate.getForObject("http://192.168.3.27:8080/population/city/Abenbury", String.class);
    return s;// w w  w  . j a  v a  2  s.  c o  m
}

From source file:ArenaService.WebMapSerivce.java

public Arenas consumeMapInfo() {
    RestTemplate restTemplate = new RestTemplate();
    Arenas response = restTemplate.getForObject(
            "https://api.worldoftanks.eu/wot/encyclopedia/arenas/?application_id=102bb26eb57f82e3b28572f345fef266",
            Arenas.class);
    return response;
}

From source file:io.spring.ScriptTemplateControllerIntegrationTests.java

@Test
public void home() {
    RestTemplate restTemplate = new RestTemplate();
    String result = restTemplate.getForObject("http://localhost:" + port, String.class);
    assertTrue(result.contains("<li>author1 content1</li>"));
}