Example usage for org.springframework.http HttpEntity HttpEntity

List of usage examples for org.springframework.http HttpEntity HttpEntity

Introduction

In this page you can find the example usage for org.springframework.http HttpEntity HttpEntity.

Prototype

public HttpEntity(MultiValueMap<String, String> headers) 

Source Link

Document

Create a new HttpEntity with the given headers and no body.

Usage

From source file:com.mc.printer.model.layout.ws.CommUpdateTask.java

@Override
public Object doBackgrounp() {
    ComResponse<T> response = null;
    try {//  w  ww  .  j a v a2s.c  o  m
        //Spring3 RESTful client?POSThttp?
        response = restTemplate.exchange(URI + serviceId, HttpMethod.POST, new HttpEntity<T>(requestData),
                new ParameterizedTypeReference<ComResponse<T>>() {
                }).getBody();

    } catch (RestClientException e) {
        //logger.error(e.getMessage());
        return e;
    }

    return response;
}

From source file:org.trustedanalytics.servicebroker.gearpump.service.externals.helpers.CfCaller.java

public HttpEntity<String> createJsonRequest() {
    return new HttpEntity<String>(createJsonHeaders());
}

From source file:com.pablinchapin.planz.dailytaskmanager.client.service.TaskServiceBean.java

public TaskServiceDTO update(Long id, TaskServiceDTO task) {
    return restTemplate.exchange(idResource, HttpMethod.PUT, new HttpEntity<>(task), TaskServiceDTO.class, id)
            .getBody();// ww w  .  j a  va 2s.c om
}

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(//  w  w w .  j  av  a2s . co  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: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(/*  w ww. ja va 2 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:org.trustedanalytics.servicebroker.gearpump.service.externals.helpers.CfCaller.java

public HttpEntity<String> createJsonRequest(HttpHeaders headers) {
    return new HttpEntity<String>(headers == null ? createJsonHeaders() : headers);
}

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:com.vinidsl.googleioextended.rest.BaseGet.java

@Override
public T performRequest() {
    HttpEntity<T> requestEntity = new HttpEntity<>(getHeaders());
    RestTemplate restTemplate = getRestTemplate();
    ResponseEntity<T> requestResult = restTemplate.exchange(getUrl(), HttpMethod.GET, requestEntity,
            getResponseClass());/*ww w .  j  a  v a 2 s. com*/
    T result = requestResult.getBody();
    return result;
}

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

@Override
protected List<MushroomDto> 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<MushroomDto[]> responseEntity = restTemplate.exchange(
            RestClient.SERVER_URL + "pa165/rest/mushroom/", HttpMethod.GET, request, MushroomDto[].class);
    MushroomDto[] mushroomDtoArray = responseEntity.getBody();
    List<MushroomDto> mushroomDtoList = new ArrayList<>();
    mushroomDtoList.addAll(Arrays.asList(mushroomDtoArray));
    return mushroomDtoList;
}

From source file:pl.hycom.jira.plugins.gitlab.integration.dao.CommitRepository.java

@Override
public List<Commit> getNewCommits(ConfigEntity configEntity, int perPage, int pageNumber) {
    HttpEntity<?> requestEntity = new HttpEntity<>(
            new TemplateFactory().getHttpHeaders().setAuth(configEntity.getClientId()).build());
    ResponseEntity<List<Commit>> response = new TemplateFactory().getRestTemplate().exchange(
            configEntity.getLink() + COMMIT_URL, HttpMethod.GET, requestEntity,
            new ParameterizedTypeReference<List<Commit>>() {
            }, configEntity.getLink(), Integer.toString(perPage), Integer.toString(pageNumber));

    return response.getBody();
}