Example usage for org.springframework.http HttpHeaders HttpHeaders

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

Introduction

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

Prototype

public HttpHeaders() 

Source Link

Document

Construct a new, empty instance of the HttpHeaders object.

Usage

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:com.abixen.platform.core.interfaces.web.common.ImageLibraryController.java

@RequestMapping(value = "layout/{fileName}/", method = RequestMethod.GET)
public ResponseEntity<byte[]> getImage(@PathVariable String fileName) throws IOException {

    log.debug("fileName: " + fileName);

    InputStream in;//from  ww  w  .j ava 2  s  .c o  m
    try {
        in = new FileInputStream(platformResourceConfigurationProperties.getImageLibraryDirectory()
                + "/layout-miniature/" + fileName);
    } catch (FileNotFoundException e) {
        in = new FileInputStream(platformResourceConfigurationProperties.getImageLibraryDirectory()
                + "/layout-miniature/default-layout-icon.png");
    }
    byte[] b = IOUtils.toByteArray(in);

    in.close();

    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.IMAGE_PNG);

    return new ResponseEntity<byte[]>(b, headers, HttpStatus.CREATED);
}

From source file:edu.infsci2560.AboutIT.java

@Test
public void testAboutPageValid() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    ResponseEntity<String> entity = this.restTemplate.exchange("/about.html", HttpMethod.GET,
            new HttpEntity<>(headers), String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
    PageHtmlValidator.validatePage(entity.getBody());
}

From source file:com.baidu.stqa.signet.web.action.BaseAction.java

public HttpHeaders setLocationHeaders(String location) {
    HttpHeaders headers = new HttpHeaders();

    if (StringUtils.isNotBlank(location)) {
        URI uri = UriComponentsBuilder.fromPath(location).build().toUri();
        headers.setLocation(uri);/*from  w ww.j a  v a  2 s .  co  m*/
    }
    return headers;
}

From source file:de.escalon.hypermedia.spring.sample.ReviewController.java

@RequestMapping(value = "/events/{eventId}", method = RequestMethod.POST)
public @ResponseBody ResponseEntity<Void> addReview(@PathVariable int eventId, @RequestBody Review review) {
    Assert.notNull(review);/*from w  ww  . j  a v a 2  s .c  o m*/
    Assert.notNull(review.getReviewRating());
    Assert.notNull(review.getReviewRating().getRatingValue());
    final HttpHeaders headers = new HttpHeaders();
    headers.setLocation(
            AffordanceBuilder.linkTo(AffordanceBuilder.methodOn(this.getClass()).getReviews(eventId)).toUri());
    return new ResponseEntity(headers, HttpStatus.CREATED);
}

From source file:com.orange.ngsi2.client.Ngsi2Client.java

private Ngsi2Client() {
    // set default headers for Content-Type and Accept to application/JSON
    httpHeaders = new HttpHeaders();
    httpHeaders.setContentType(MediaType.APPLICATION_JSON);
    httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
}

From source file:ru.portal.controllers.RestController.java

@RequestMapping(value = { "/random/{id}" })
@ResponseBody//from   ww  w  .ja v  a2s . c om
public DeferredResult<ResponseEntity<String>> random(@PathVariable Long id) {

    DeferredResult<ResponseEntity<String>> deferredResult = new DeferredResult<>();
    String result = String.format("random : %s", ThreadLocalRandom.current().nextLong(id));

    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-type", "application/json;charset=UTF-8");
    ResponseEntity responseEntity = new ResponseEntity<>(result, headers, HttpStatus.OK);

    deferredResult.setResult(responseEntity);

    return deferredResult;

}

From source file:eu.freme.eservices.publishing.ServiceRestController.java

@RequestMapping(value = "/e-publishing/html", method = RequestMethod.POST)
public ResponseEntity<byte[]> htmlToEPub(@RequestParam("htmlZip") MultipartFile file,
        @RequestParam("metadata") String jMetadata)
        throws IOException, InvalidZipException, EPubCreationException, MissingMetadataException {
    Gson gson = new Gson();
    Metadata metadata = gson.fromJson(jMetadata, Metadata.class);
    MultiValueMap<String, String> headers = new HttpHeaders();
    headers.add(HttpHeaders.CONTENT_TYPE, "Application/epub+zip");
    String filename = file.getName();
    headers.add(HttpHeaders.CONTENT_DISPOSITION, "Attachment; filename=" + filename.split("\\.")[0] + ".epub");
    try (InputStream in = file.getInputStream()) {
        return new ResponseEntity<>(epubAPI.createEPUB(metadata, in), headers, HttpStatus.OK);
    }//  www  .j a  v a2s .  c  o m
}

From source file:eu.freme.eservices.epublishing.ServiceRestController.java

@RequestMapping(value = "/e-publishing/html", method = RequestMethod.POST)
public ResponseEntity<byte[]> htmlToEPub(@RequestParam("htmlZip") MultipartFile file,
        @RequestParam("metadata") String jMetadata)
        throws IOException, InvalidZipException, EPubCreationException, MissingMetadataException {
    Gson gson = new Gson();
    Metadata metadata = gson.fromJson(jMetadata, Metadata.class);
    MultiValueMap<String, String> headers = new HttpHeaders();
    headers.add(HttpHeaders.CONTENT_TYPE, "Application/epub+zip");
    try (InputStream in = file.getInputStream()) {
        return new ResponseEntity<>(epubAPI.createEPUB(metadata, in), headers, HttpStatus.OK);
    }//ww  w.  j  av a 2s  .c o m
}

From source file:org.awesomeagile.integrations.hackpad.RestTemplateHackpadClient.java

@Override
public PadIdentity createHackpad(String title) {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.TEXT_PLAIN);
    HttpEntity<String> entity = new HttpEntity<>(title, headers);
    return restTemplate.postForObject(fullUrl(CREATE_URL), entity, PadIdentity.class);
}