Example usage for org.springframework.http HttpStatus CREATED

List of usage examples for org.springframework.http HttpStatus CREATED

Introduction

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

Prototype

HttpStatus CREATED

To view the source code for org.springframework.http HttpStatus CREATED.

Click Source Link

Document

201 Created .

Usage

From source file:com.seabee.snapdragon.controller.BlogController.java

@RequestMapping(value = "/new", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public void addBlogEntry(@Valid @RequestBody BlogEntry entry) {
    dao.addBlogEntry(entry);
}

From source file:technology.tikal.customers.service.ContactService.java

@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public void createContact(@PathVariable final Long customerId, @Valid @RequestBody final Contact data,
        final BindingResult result, final HttpServletRequest request, final HttpServletResponse response) {
    if (result.hasErrors()) {
        throw new NotValidException(result);
    }//from  w  w w . ja  v a2 s  .  co m
    Contact created = customersController.createContact(customerId, data);
    response.setHeader("Location", request.getRequestURI() + "/" + created.getId());
}

From source file:com.thesoftwareguild.capstoneblog.controller.HomeController.java

@RequestMapping(value = "/post", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody/* w w w  .  j  a  va  2s  . c o m*/
public Post createPost(@Valid @RequestBody Content content) {
    // persist the incoming post
    if (content.getTitle() == null || content.getTitle().isEmpty()) {
        content.setTitle("Untitled");
    }

    // parse categories into a list of strings
    List<String> categoriesList = new ArrayList<>();
    if (!content.getCategories().isEmpty()) {
        String[] categoriesArr = content.getCategories().split(",");
        categoriesList.addAll(Arrays.asList(categoriesArr));
    }

    // parse tags into a list of strings
    List<String> tagsList = new ArrayList<>();
    String[] tagsArr = content.getTags().split(",");
    tagsList.addAll(Arrays.asList(tagsArr));

    // TODO: parse comments
    Post p = new Post(content.getAuthor(), content.getTitle(), content.getText(), LocalDate.now() // date created
            , LocalDate.now() // date posted (set to created for now)
            , categoriesList // categories
            , tagsList // tags
            , new ArrayList<>()); // TODO: comments

    dao.addPost(p);
    return p;
}

From source file:com.xpanxion.userprojecthibernate.controllers.RESTController.java

@RequestMapping(value = "/user", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody//from w w w .j a  v a  2  s. c  om
public UserBean createUser(@RequestBody UserBean userToCreate) {
    userService.addUser(userToCreate);
    return userToCreate;
}

From source file:com.cocktail.controller.CocktailController.java

@RequestMapping(value = "/cocktails/cocktail", method = RequestMethod.POST)
public ResponseEntity<?> addCocktail(@RequestBody CocktailResource cocktailDTO,
        UriComponentsBuilder ucBuilder) {

    Cocktail cocktail = cocktailService.addCocktail(cocktailDTO);

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

From source file:com.agroservices.restcontrollers.CampesinoRest.java

@RequestMapping(value = "/{id}/productosEnVenta", method = RequestMethod.POST)
public ResponseEntity<?> guardarProductoEnVenta(@PathVariable int id, @RequestBody ProductoEnVenta pv) {
    System.out.println("Post a campesinos productosEnVenta " + id);
    System.out.println(pv);/*from  w w w  .  j a  v  a2  s  .c om*/
    try {
        cf.guardarProductoEnVentaParaCampesino(id, pv);
        return new ResponseEntity<>(HttpStatus.CREATED);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }
}

From source file:com.swcguild.bluraymvc.controller.DisplayController.java

@RequestMapping(value = "/movie", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
//indicates that the content gets sent to client; not returninng a jsp destination but an object
//that's what @ResponseBody indicates
@ResponseBody//www . jav  a  2  s. c om
public Movie createMovie(@RequestBody Movie movie) {
    dao.createMovie(movie);
    return movie;
}

From source file:de.sainth.recipe.backend.rest.controller.FoodController.java

@Secured("ROLE_ADMIN")
@RequestMapping(method = RequestMethod.POST)
HttpEntity<Food> add(@Valid @RequestBody Food food) {
    Food f = repository.save(food);/*from   w  w w  .  j  av a  2s  .  c  om*/
    return new ResponseEntity<>(f, HttpStatus.CREATED);
}

From source file:net.eusashead.hateoas.conditional.interceptor.SyncTestController.java

@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<Void> post() {
    return new ResponseEntity<Void>(HttpStatus.CREATED);
}

From source file:net.eusashead.hateoas.response.impl.PostResponseBuilderImpl.java

@Override
public ResponseEntity<Void> build() {
    if (this.headers.getLocation() == null) {
        throw new RuntimeException("Location header must be set before calling create().");
    }//from  w ww  . j av a2s  .  co m
    return new ResponseEntity<Void>(headers, HttpStatus.CREATED);
}