use of org.springframework.http.HttpEntity in project spring-framework by spring-projects.
the class AsyncRestTemplateIntegrationTests method exchangeGetCallback.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void exchangeGetCallback() throws Exception {
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.set("MyHeader", "MyValue");
HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
ListenableFuture<ResponseEntity<String>> responseFuture = template.exchange(baseUrl + "/{method}", HttpMethod.GET, requestEntity, String.class, "get");
responseFuture.addCallback(new ListenableFutureCallback<ResponseEntity<String>>() {
@Override
public void onSuccess(ResponseEntity<String> result) {
assertEquals("Invalid content", helloWorld, result.getBody());
}
@Override
public void onFailure(Throwable ex) {
fail(ex.getMessage());
}
});
waitTillDone(responseFuture);
}
use of org.springframework.http.HttpEntity in project spring-framework by spring-projects.
the class AsyncRestTemplateIntegrationTests method postForLocation.
@Test
public void postForLocation() throws Exception {
HttpHeaders entityHeaders = new HttpHeaders();
entityHeaders.setContentType(new MediaType("text", "plain", StandardCharsets.ISO_8859_1));
HttpEntity<String> entity = new HttpEntity<>(helloWorld, entityHeaders);
Future<URI> locationFuture = template.postForLocation(baseUrl + "/{method}", entity, "post");
URI location = locationFuture.get();
assertEquals("Invalid location", new URI(baseUrl + "/post/1"), location);
}
use of org.springframework.http.HttpEntity in project spring-framework by spring-projects.
the class RestTemplateIntegrationTests method exchangePost.
@Test
public void exchangePost() throws Exception {
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.set("MyHeader", "MyValue");
requestHeaders.setContentType(MediaType.TEXT_PLAIN);
HttpEntity<String> requestEntity = new HttpEntity<>(helloWorld, requestHeaders);
HttpEntity<Void> result = template.exchange(baseUrl + "/{method}", HttpMethod.POST, requestEntity, Void.class, "post");
assertEquals("Invalid location", new URI(baseUrl + "/post/1"), result.getHeaders().getLocation());
assertFalse(result.hasBody());
}
use of org.springframework.http.HttpEntity in project spring-framework by spring-projects.
the class RestTemplateIntegrationTests method postForLocationEntity.
@Test
public void postForLocationEntity() throws URISyntaxException {
HttpHeaders entityHeaders = new HttpHeaders();
entityHeaders.setContentType(new MediaType("text", "plain", StandardCharsets.ISO_8859_1));
HttpEntity<String> entity = new HttpEntity<>(helloWorld, entityHeaders);
URI location = template.postForLocation(baseUrl + "/{method}", entity, "post");
assertEquals("Invalid location", new URI(baseUrl + "/post/1"), location);
}
use of org.springframework.http.HttpEntity in project spring-framework by spring-projects.
the class RestTemplateIntegrationTests method jsonPostForObject.
@Test
public void jsonPostForObject() throws URISyntaxException {
HttpHeaders entityHeaders = new HttpHeaders();
entityHeaders.setContentType(new MediaType("application", "json", StandardCharsets.UTF_8));
MySampleBean bean = new MySampleBean();
bean.setWith1("with");
bean.setWith2("with");
bean.setWithout("without");
HttpEntity<MySampleBean> entity = new HttpEntity<>(bean, entityHeaders);
String s = template.postForObject(baseUrl + "/jsonpost", entity, String.class);
assertTrue(s.contains("\"with1\":\"with\""));
assertTrue(s.contains("\"with2\":\"with\""));
assertTrue(s.contains("\"without\":\"without\""));
}
Aggregations