use of org.springframework.http.HttpEntity in project spring-security-oauth by spring-projects.
the class RemoteTokenServices method postForMap.
private Map<String, Object> postForMap(String path, MultiValueMap<String, String> formData, HttpHeaders headers) {
if (headers.getContentType() == null) {
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
}
@SuppressWarnings("rawtypes") Map map = restTemplate.exchange(path, HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(formData, headers), Map.class).getBody();
@SuppressWarnings("unchecked") Map<String, Object> result = map;
return result;
}
use of org.springframework.http.HttpEntity in project spring-boot by spring-projects.
the class SampleUndertowApplicationTests method testCompression.
@Test
public void testCompression() throws Exception {
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.set("Accept-Encoding", "gzip");
HttpEntity<?> requestEntity = new HttpEntity<>(requestHeaders);
ResponseEntity<byte[]> entity = this.restTemplate.exchange("/", HttpMethod.GET, requestEntity, byte[].class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
GZIPInputStream inflater = new GZIPInputStream(new ByteArrayInputStream(entity.getBody()));
try {
assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))).isEqualTo("Hello World");
} finally {
inflater.close();
}
}
use of org.springframework.http.HttpEntity in project spring-boot by spring-projects.
the class SampleWebFreeMarkerApplicationTests method testFreeMarkerErrorTemplate.
@Test
public void testFreeMarkerErrorTemplate() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
HttpEntity<String> requestEntity = new HttpEntity<>(headers);
ResponseEntity<String> responseEntity = this.testRestTemplate.exchange("/does-not-exist", HttpMethod.GET, requestEntity, String.class);
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
assertThat(responseEntity.getBody()).contains("Something went wrong: 404 Not Found");
}
use of org.springframework.http.HttpEntity in project spring-boot by spring-projects.
the class SampleWebMustacheApplicationTests method test507Template.
@Test
public void test507Template() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
HttpEntity<String> requestEntity = new HttpEntity<>(headers);
ResponseEntity<String> entity = this.restTemplate.exchange("/insufficientStorage", HttpMethod.GET, requestEntity, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INSUFFICIENT_STORAGE);
assertThat(entity.getBody()).contains("I'm a 507");
}
use of org.springframework.http.HttpEntity in project spring-boot by spring-projects.
the class SampleWebMustacheApplicationTests method test503HtmlResource.
@Test
public void test503HtmlResource() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
HttpEntity<String> requestEntity = new HttpEntity<>(headers);
ResponseEntity<String> entity = this.restTemplate.exchange("/serviceUnavailable", HttpMethod.GET, requestEntity, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE);
assertThat(entity.getBody()).contains("I'm a 503");
}
Aggregations