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.garyclayburg.UserRestSmokeTest.java

@Test
public void testHalJsonApache() throws Exception {
    RestTemplate rest = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
    SimpleUser user1 = new SimpleUser();
    user1.setFirstname("Tommy");
    user1.setLastname("Deleteme");
    user1.setId("112" + (int) (Math.floor(Math.random() * 10000)));

    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Content-Type", "application/hal+json");
    //        HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
    HttpEntity<?> requestEntity = new HttpEntity(user1, requestHeaders);

    ResponseEntity<SimpleUser> simpleUserResponseEntity = rest.exchange(
            "http://" + endpoint + "/audited-users/auditedsave", HttpMethod.POST, requestEntity,
            SimpleUser.class);

    //        ResponseEntity<SimpleUser> userResponseEntity =
    //            rest.postForEntity("http://" + endpoint + "/audited-users/auditedsave",user1,SimpleUser.class);
    log.info("got a response");
    MatcherAssertionErrors.assertThat(simpleUserResponseEntity.getStatusCode(),
            Matchers.equalTo(HttpStatus.OK));

}

From source file:eu.agilejava.javaonedemo.api.CookBookResource.java

@RequestMapping(method = RequestMethod.POST, consumes = APPLICATION_JSON_VALUE)
public ResponseEntity<CookBook> create(@RequestBody CookBook cookBook) {
    cookBookService.create(cookBook);//from   w ww .  j  a v  a2s .  c  o m

    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.add("Location", ServletUriComponentsBuilder.fromCurrentRequestUri()
            .pathSegment(String.valueOf(cookBook.getId())).build().toUriString());
    return new ResponseEntity<>(responseHeaders, HttpStatus.CREATED);

}

From source file:rest.DependenciaRestController.java

@RequestMapping(value = "/dependencia/", method = RequestMethod.POST)
public ResponseEntity<Void> createDependencia(@RequestBody DependenciaBean dependencia,
        UriComponentsBuilder ucBuilder) {
    System.out.println("Registrar una Dependencia");
    if (dependenciaService.isDependenciaExist(dependencia)) {
        System.out.println("La dependencia con Nombre " + dependencia.getDesDep() + " ya existe.");
        return new ResponseEntity<Void>(HttpStatus.CONFLICT);
    }//  ww  w.  j a va 2s. co m
    dependenciaService.save(dependencia);

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(
            ucBuilder.path("/dependencia/{codDep}").buildAndExpand(dependencia.getCodDep()).toUri());
    return new ResponseEntity<Void>(headers, HttpStatus.CREATED);
}

From source file:com.iata.ndc.trial.controllers.DefaultController.java

@RequestMapping(value = "/ba", method = RequestMethod.GET)
public String getCal() {

    RestTemplate restTemplate = new RestTemplate();
    List<HttpMessageConverter<?>> converters = new ArrayList<>();
    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    converter.getObjectMapper().configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
    converters.add(converter);//from  w w w. j av a 2 s  .c om
    restTemplate.setMessageConverters(converters);

    HttpHeaders headers = new HttpHeaders();
    headers.add("client-key", "zmd9apqgg2jwekf8zgqg5ybf");
    headers.setContentType(MediaType.APPLICATION_JSON);

    ResponseEntity<BALocationsResponseWrapper> baLocationsResponse = restTemplate.exchange(
            "https://api.ba.com/rest-v1/v1/balocations", HttpMethod.GET, new HttpEntity<Object>(headers),
            BALocationsResponseWrapper.class);
    System.out.println(baLocationsResponse.getBody().getGetBALocationsResponse().getCountry().size());
    return "index";
}

From source file:com.mycompany.springrest.controllers.UserController.java

@RequestMapping(value = "/user/", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Void> createUser(@RequestBody User user, UriComponentsBuilder ucBuilder) {
    logger.info("Creating User " + user.getUserName());
    if (userService.isUserExist(user)) {
        logger.info("A User with name " + user.getUserName() + " already exist");
        return new ResponseEntity<Void>(HttpStatus.CONFLICT);
    }/*from w w w  .ja  v a 2s  .  c om*/
    userService.addUser(user);

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(ucBuilder.path("/user/{id}").buildAndExpand(user.getId()).toUri());
    return new ResponseEntity<Void>(headers, HttpStatus.CREATED);
}

From source file:com.biz.report.controller.ItemDashBoardController.java

@ResponseBody
@RequestMapping(value = "sales/{year}/read", method = RequestMethod.POST, headers = {
        "Content-type=application/json" })
public ResponseEntity<List<SalesDTO>> readItemByType(@RequestBody Map map, @PathVariable("year") String year) {
    Assert.notNull(year, "Year is null.");
    Assert.notNull(map, "Type is null.");
    String itemName = map.get("item").toString();
    String month = map.get("month") != null ? map.get("month").toString() : null;
    HttpHeaders headers = new HttpHeaders();
    headers.add("success", "Success");
    return new ResponseEntity<List<SalesDTO>>(itemDashBoardService.readByItemName(itemName, year, month),
            headers, HttpStatus.OK);//from w  w  w .  j  a v a  2s  .c  om
}

From source file:com.biz.report.controller.ReportController.java

@ResponseBody
@RequestMapping(value = "items/{year}/read", method = RequestMethod.POST, headers = {
        "Content-type=application/json" })
public ResponseEntity<List<ItemDTO>> readItemByType(@RequestBody Map map, @PathVariable("year") String year) {
    Assert.notNull(year, "Year is null.");
    Assert.notNull(map, "Type is null.");
    String type = map.get("type").toString();
    String month = map.get("month") != null ? map.get("month").toString() : null;
    HttpHeaders headers = new HttpHeaders();
    headers.add("success", "Success");
    return new ResponseEntity<List<ItemDTO>>(reportService.readItemByType(type, year, month), headers,
            HttpStatus.OK);/* w w w. jav  a 2  s . c o  m*/
}

From source file:ca.qhrtech.services.implementations.BGGServiceImpl.java

private HttpEntity<?> buildXmlHttpHeader() {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Accept", MediaType.APPLICATION_XML_VALUE);
    return new HttpEntity<>(headers);
}

From source file:com.msyla.usergreeter.user.web.UserPreferenceResource.java

@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<UserPreferenceDto> create(
        @NotNull(message = "{userPreference.null}") @Valid @RequestBody UserPreferenceDto dto,
        UriComponentsBuilder builder) {/*from   w w w  . j ava 2  s. c o  m*/
    UserPreferenceDto savedDto = service.create(dto);

    Link link = ControllerLinkBuilder.linkTo(UserPreferenceResource.class).slash(savedDto.getKey())
            .withSelfRel();
    savedDto.add(link);

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(builder.path("/api/user/preferences/{id}").buildAndExpand(savedDto.getKey()).toUri());
    return new ResponseEntity<>(savedDto, headers, HttpStatus.CREATED);
}