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:com.interop.webapp.WebAppTests.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.FOUND, entity.getStatusCode());
    assertTrue("Wrong location:\n" + entity.getHeaders(),
            entity.getHeaders().getLocation().toString().endsWith(port + "/login"));
}

From source file:io.github.microcks.web.ExportController.java

@RequestMapping(value = "/export", method = RequestMethod.GET)
public ResponseEntity<?> exportRepository(@RequestParam(value = "serviceIds") List<String> serviceIds) {
    log.debug("Extracting export for serviceIds {}", serviceIds);
    String json = importExportService.exportRepository(serviceIds, "json");

    byte[] body = json.getBytes();
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setContentType(MediaType.APPLICATION_JSON);
    responseHeaders.set("Content-Disposition", "attachment; filename=microcks-repository.json");
    responseHeaders.setContentLength(body.length);

    return new ResponseEntity<Object>(body, responseHeaders, HttpStatus.OK);
}

From source file:com.github.ljtfreitas.restify.http.spring.client.request.RequestEntityConverter.java

private HttpHeaders headersOf(Headers headers) {
    HttpHeaders httpHeaders = new HttpHeaders();

    headers.all().forEach(h -> httpHeaders.add(h.name(), h.value()));

    return httpHeaders;
}

From source file:org.openbaton.vnfm.api.exceptions.GlobalExceptionHandler.java

@ExceptionHandler({ NotFoundException.class, NoResultException.class, NullPointerException.class })
@ResponseStatus(value = HttpStatus.NOT_FOUND)
protected ResponseEntity<Object> handleNotFoundException(Exception e, WebRequest request) {
    log.error("Exception with message " + e.getMessage() + " was thrown");
    ExceptionResource exc = new ExceptionResource("Not Found", e.getMessage());
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);

    return handleExceptionInternal(e, exc, headers, HttpStatus.NOT_FOUND, request);
}

From source file:com.google.cloud.servicebroker.awwvision.RedditScraper.java

@RequestMapping("/reddit")
String getRedditUrls(Model model, RestTemplate restTemplate) throws GeneralSecurityException {
    HttpHeaders headers = new HttpHeaders();
    headers.add(HttpHeaders.USER_AGENT, redditUserAgent);
    RedditResponse response = restTemplate
            .exchange(REDDIT_URL, HttpMethod.GET, new HttpEntity<String>(headers), RedditResponse.class)
            .getBody();/*  www .  j  a  va 2 s .  co m*/

    storeAndLabel(response);

    return "reddit";
}

From source file:com.nebhale.springone2014.web.GamesController.java

@RequestMapping(method = RequestMethod.POST, value = "")
// TODO 2: CREATED Status Code
@ResponseStatus(HttpStatus.CREATED)/*from w ww  .  j  ava 2 s .  co  m*/
HttpHeaders createGame() {
    Game game = this.gameRepository.create();

    HttpHeaders headers = new HttpHeaders();
    // TODO 1: Location: /games/{gameId}
    headers.setLocation(linkTo(GamesController.class).slash(game.getId()).toUri());

    return headers;
}

From source file:org.ala.spatial.web.services.LayerDistancesWSController.java

@RequestMapping(value = "/layers/analysis/inter_layer_association_rawnames.csv", method = RequestMethod.GET)
public ResponseEntity<String> CSVrawnames(HttpServletRequest req) {
    String csv = makeCSV("name");
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setContentType(MediaType.parseMediaType("text/csv"));
    return new ResponseEntity<String>(csv, responseHeaders, HttpStatus.CREATED);
}

From source file:org.openbaton.marketplace.api.exceptions.GlobalExceptionHandler.java

@ExceptionHandler({ NotFoundException.class, ImageRepositoryNotEnabled.class })
@ResponseStatus(value = HttpStatus.NOT_FOUND)
protected ResponseEntity<Object> handleNotFoundException(HttpServletRequest req, Exception e) {
    log.error("Exception with message " + e.getMessage() + " was thrown");
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    Map body = new HashMap<>();
    body.put("error", "Not Found");
    body.put("exception", e.getClass().toString());
    body.put("message", e.getMessage());
    body.put("path", req.getRequestURI());
    body.put("status", HttpStatus.NOT_FOUND.value());
    body.put("timestamp", new Date().getTime());
    ResponseEntity responseEntity = new ResponseEntity(body, headers, HttpStatus.NOT_FOUND);
    return responseEntity;
}

From source file:sample.jetty.SampleJettyApplicationTests.java

@Test
public void testCompression() throws Exception {
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Accept-Encoding", "gzip");
    HttpEntity<?> requestEntity = new HttpEntity<Object>(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 {//from   w  ww. ja v a 2  s  . c o m
        //         assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))).isEqualTo("Hello World");
    } finally {
        inflater.close();
    }
}

From source file:org.cloudfoundry.identity.uaa.integration.PasswordCheckEndpointIntegrationTests.java

@Test
public void passwordPostWithUserDataSucceeds() throws Exception {
    MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
    formData.add("password", "joe@joesplace.blah");
    formData.add("userData", "joe,joe@joesplace.blah,joesdogsname");
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> response = serverRunning.postForMap("/password/score", formData, headers);
    assertEquals(HttpStatus.OK, response.getStatusCode());

    assertTrue(response.getBody().containsKey("score"));
    assertTrue(response.getBody().containsKey("requiredScore"));
    assertEquals(0, response.getBody().get("score"));
}