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:at.ac.tuwien.dsg.cloud.utilities.gateway.registry.RestUtilities.java

public <T> ResponseEntity<T> simpleRestExchange(RequestEntity reg, Class<T> respType) {
    HttpStatus failedCode;//from   ww  w  . ja v  a2s.c o m
    try {
        RestTemplate restTemplate = new RestTemplate();
        return restTemplate.exchange(reg, respType);
    } catch (HttpStatusCodeException e) {
        String serverResp = e.getResponseBodyAsString();
        failedCode = e.getStatusCode();
        logger.error(String.format(
                "Exception from server! " + "With status code %s! " + "Following body was responded %s",
                failedCode.toString(), serverResp), e);
    }

    //todo: think of throwing an exception instead of returning a null object
    return new ResponseEntity(null, failedCode);
}

From source file:com.xpanxion.restclientexample.Application.java

public User createUser(User user) {
    RestTemplate rt = new RestTemplate();
    List<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters.add(new MappingJacksonHttpMessageConverter());
    rt.setMessageConverters(converters);
    return rt.postForObject("http://localhost:8080/UserProjectHibernate/rest/user", user, User.class);
}

From source file:org.jtalks.tests.jcommune.mail.pochta.PochtaClient.java

/**
 * Gets list of messages metadata/*w  w w . j a v a 2s. c  o  m*/
 *
 * @return the list of messages metadata
 * @throws CouldNotGetMessagesException
 */
public static String getMessages() throws CouldNotGetMessagesException {
    RestTemplate client = new RestTemplate();
    try {
        return client.getForObject(new URI(mailtrapMessagesUri()), String.class);
    } catch (Exception e) {
        throw new CouldNotGetMessagesException(e);
    }
}

From source file:com.develcom.cliente.Cliente.java

public void buscarArchivo() throws FileNotFoundException, IOException {

    CodDecodArchivos cda = new CodDecodArchivos();
    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    //        Bufer bufer = new Bufer();
    byte[] buffer = null;
    ResponseEntity<byte[]> response;

    restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
    headers.setAccept(Arrays.asList(MediaType.ALL));
    HttpEntity<String> entity = new HttpEntity<>(headers);

    response = restTemplate.exchange(/*from   ww w. jav  a2 s  . c  o m*/
            "http://localhost:8080/ServicioDW4J/expediente/buscarFisicoDocumento/21593", HttpMethod.GET, entity,
            byte[].class);

    if (response.getStatusCode().equals(HttpStatus.OK)) {
        buffer = response.getBody();
        FileOutputStream output = new FileOutputStream(new File("c:/documentos/archivo.cod"));
        IOUtils.write(response.getBody(), output);
        cda.decodificar("c:/documentos/archivo.cod", "c:/documentos/archivo.pdf");
    }

}

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

public void Registrar(Envio envio) {
    RestTemplate restTemplate = new RestTemplate();
    RequestTrackingAddPackage req = new RequestTrackingAddPackage(envio.getId().toString(),
            envio.getCliente().getId().toString(), envio.getDestino().getId().toString(), envio.getFechaEnvio(),
            false);/*  w  w w. j av a2 s  . c om*/
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity<RequestTrackingAddPackage> entity = new HttpEntity<>(req, headers);
    restTemplate.postForObject(ConfigController.getInstance().getURLAddTracking(), entity, void.class);
}

From source file:com.develcom.reafolder.ClienteBajaArchivo.java

public void buscarArchivo() throws FileNotFoundException, IOException {

    CodDecodArchivos cda = new CodDecodArchivos();
    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    Bufer bufer = new Bufer();
    byte[] buffer = null;
    ResponseEntity<byte[]> response;

    restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
    headers.setAccept(Arrays.asList(MediaType.ALL));
    HttpEntity<String> entity = new HttpEntity<>(headers);

    response = restTemplate.exchange(//from ww  w.  j  a  va 2s.  c o m
            "http://localhost:8080/ServicioDW4J/expediente/buscarFisicoDocumento/21593", HttpMethod.GET, entity,
            byte[].class);

    if (response.getStatusCode().equals(HttpStatus.OK)) {
        buffer = response.getBody();
        FileOutputStream output = new FileOutputStream(new File("c:/documentos/archivo.cod"));
        IOUtils.write(response.getBody(), output);
        cda.decodificar("c:/documentos/archivo.cod", "c:/documentos/archivo.pdf");
    }

}

From source file:org.zkybase.cmdb.connector.impl.ZkybaseTemplate.java

public ZkybaseTemplate(String baseUri) {
    RestTemplate restTemplate = new RestTemplate();
    this.applicationTemplate = new ApplicationTemplate(restTemplate, baseUri);
}

From source file:com.github.ffremont.microservices.springboot.node.ApplicationConfiguration.java

@Bean
public RestTemplate getRestTemplate() {
    RestTemplate rTemplate = new RestTemplate();
    List<ClientHttpRequestInterceptor> interceptors = Collections.<ClientHttpRequestInterceptor>singletonList(
            new BasicAuthorizationInterceptor(this.username, this.password));
    rTemplate.setRequestFactory(//from   w  w w  . ja v  a 2s  .c o  m
            new InterceptingClientHttpRequestFactory(rTemplate.getRequestFactory(), interceptors));

    return rTemplate;
}

From source file:pl.hycom.jira.plugins.gitlab.integration.util.TemplateFactory.java

public RestTemplate getRestTemplate() {
    RestTemplate restTemplate = new RestTemplate();

    return restTemplate;
}

From source file:com.iflytek.rest.demo.UserServiceTest.java

public static String requestAccessToken() {
    RestTemplate restTemplate = new RestTemplate();
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    form.add("client_id", "Hb0YhmOo");
    form.add("client_secret", "R7odNVS0KPtgXJ1TKQbHAxFP6EHdSW5d");
    form.add("grant_type", "client_credentials"); //?password & client_credentials

    //grant_typeclient_credentials????username & password?
    form.add("username", "admin_test_333");
    form.add("password", "passw0rd");

    String result = restTemplate.postForObject(OAUTH_SERVER_URL, form, String.class);
    System.out.println(result);/* w ww.j ava  2  s.  c o m*/
    String access_token = JSON.parseObject(result).getString("access_token");
    return access_token;
}