Example usage for org.springframework.web.client AsyncRestTemplate postForEntity

List of usage examples for org.springframework.web.client AsyncRestTemplate postForEntity

Introduction

In this page you can find the example usage for org.springframework.web.client AsyncRestTemplate postForEntity.

Prototype

@Override
    public <T> ListenableFuture<ResponseEntity<T>> postForEntity(URI url, @Nullable HttpEntity<?> request,
            Class<T> responseType) throws RestClientException 

Source Link

Usage

From source file:org.apache.servicecomb.demo.springmvc.tests.SpringMvcIntegrationTestBase.java

@Test
public void ableToUploadFileFromConsumer() throws Exception {
    String file1Content = "hello world";
    String file2Content = "bonjour";
    String username = "mike";

    Map<String, Object> map = new HashMap<>();
    map.put("file1", new FileSystemResource(newFile(file1Content).getAbsolutePath()));
    map.put("someFile", new FileSystemResource(newFile(file2Content).getAbsolutePath()));
    map.put("name", username);

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.MULTIPART_FORM_DATA);
    String result = RestTemplateBuilder.create().postForObject(
            "cse://springmvc-tests/codeFirstSpringmvc/upload", new HttpEntity<>(map, headers), String.class);

    assertThat(result, is(file1Content + file2Content + username));
    AsyncRestTemplate cseAsyncRestTemplate = new CseAsyncRestTemplate();
    ListenableFuture<ResponseEntity<String>> listenableFuture = cseAsyncRestTemplate.postForEntity(
            "cse://springmvc-tests/codeFirstSpringmvc/upload", new HttpEntity<>(map, headers), String.class);
    ResponseEntity<String> responseEntity = listenableFuture.get();
    assertThat(responseEntity.getBody(), is(file1Content + file2Content + username));
}