List of usage examples for org.springframework.http HttpHeaders setAccept
public void setAccept(List<MediaType> acceptableMediaTypes)
From source file:com.cisco.cta.taxii.adapter.httpclient.HttpHeadersAppender.java
public void appendTo(HttpHeaders headers) { headers.setContentType(MediaType.APPLICATION_XML); headers.setAccept(ImmutableList.of(MediaType.APPLICATION_XML)); headers.set("X-Taxii-Accept", "urn:taxii.mitre.org:message:xml:1.1"); headers.set("X-TAXII-Content-Type", "urn:taxii.mitre.org:message:xml:1.1"); headers.set("X-Taxii-Protocol", "urn:taxii.mitre.org:protocol:https:1.0"); headers.set("X-TAXII-Services", "urn:taxii.mitre.org:services:1.1"); headers.set("User-Agent", "taxii-log-adapter-" + Version.getImplVersion()); }
From source file:comsat.sample.mustache.SampleWebMustacheApplicationTests.java
@Test public void testMustacheErrorTemplate() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity<String> requestEntity = new HttpEntity<String>(headers); ResponseEntity<String> responseEntity = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/does-not-exist", HttpMethod.GET, requestEntity, String.class); assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); assertTrue("Wrong body:\n" + responseEntity.getBody(), responseEntity.getBody().contains("Something went wrong: 404 Not Found")); }
From source file:comsat.sample.freemarker.SampleWebFreeMarkerApplicationTests.java
@Test public void testFreeMarkerErrorTemplate() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity<String> requestEntity = new HttpEntity<String>(headers); ResponseEntity<String> responseEntity = new TestRestTemplate().exchange( "http://localhost:" + port + "/does-not-exist", HttpMethod.GET, requestEntity, String.class); assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); assertTrue("Wrong body:\n" + responseEntity.getBody(), responseEntity.getBody().contains("Something went wrong: 404 Not Found")); }
From source file:comsat.sample.velocity.SampleWebVelocityApplicationTests.java
@Test public void testVelocityErrorTemplate() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity<String> requestEntity = new HttpEntity<String>(headers); ResponseEntity<String> responseEntity = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/does-not-exist", HttpMethod.GET, requestEntity, String.class); assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); assertTrue("Wrong body:\n" + responseEntity.getBody(), responseEntity.getBody().contains("Something went wrong: 404 Not Found")); }
From source file:com.example.SampleWebFreeMarkerApplicationTests.java
@Test public void testFreeMarkerErrorTemplate() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity<String> requestEntity = new HttpEntity<String>(headers); ResponseEntity<String> responseEntity = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/" + contextPath + "/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"); }
From source file:com.bradley.musicapp.test.restapi.PersonRestControllerTest.java
private HttpEntity<?> getHttpEntity() { HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAccept(Collections.singletonList(new MediaType("application", "json"))); HttpEntity<?> requestEntity = new HttpEntity<>(requestHeaders); restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter()); return requestEntity; }
From source file:movies.spring.jdbc.SampleMovieApplicationTests.java
@Test public void testMovie() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(asList(MediaType.APPLICATION_JSON)); TestRestTemplate template = new TestRestTemplate(); template.setMessageConverters(//w w w. jav a 2s . c o m Arrays.<HttpMessageConverter<?>>asList(new MappingJackson2HttpMessageConverter())); ResponseEntity<Map> entity = template.getForEntity("http://localhost:" + this.port + "/movie/{title}", Map.class, "The Matrix"); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals("The Matrix", entity.getBody().get("title")); }
From source file:edu.infsci2560.LoginIT.java
@Test public void testLoginPage() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.GET, new HttpEntity<>(headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("_csrf"); }
From source file:edu.infsci2560.LoginIT.java
@Test public void testLoginPageValid() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.GET, new HttpEntity<>(headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); PageHtmlValidator.validatePage(entity.getBody()); }
From source file:com.alcatel.hello.actuator.ui.SampleActuatorUIApplicationTests.java
@Test public void testHome() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port, HttpMethod.GET, new HttpEntity<Void>(headers), String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(), entity.getBody().contains("<title>Hello")); }