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:plbtw.klmpk.barang.hilang.controller.KategoriBarangController.java

@RequestMapping(method = RequestMethod.POST, produces = "application/json")
public CustomResponseMessage addKategoriBarang(@RequestBody KategoriBarangRequest kategoriBarangRequest) {
    try {//from ww  w  .  ja  v a2 s  .c o m
        KategoriBarang kategoriBarang = new KategoriBarang();
        kategoriBarang.setJenis(kategoriBarangRequest.getJenis());
        kategoriBarangService.addKategoriBarang(kategoriBarang);
        return new CustomResponseMessage(HttpStatus.CREATED, "Kategori Barang berhasil di tambahkan");
    } catch (Exception ex) {
        return new CustomResponseMessage(HttpStatus.BAD_REQUEST, ex.toString());
    }

}

From source file:com.auditbucket.registration.endpoint.RegistrationEP.java

@RequestMapping(value = "/", consumes = "application/json", method = RequestMethod.POST)
@ResponseBody/*from  ww  w .  j  a  va  2s  .  c  o  m*/
public ResponseEntity<SystemUser> registerSystemUser(@RequestBody RegistrationBean regBean)
        throws DatagioException {
    // curl -u mike:123 -H "Content-Type:application/json" -X PUT http://localhost:8080/ab/profiles/register -d '{"name":"mikey", "companyName":"Monowai Dev","password":"whocares"}'
    SystemUser su = regService.registerSystemUser(regBean);
    if (su == null)
        return new ResponseEntity<>(su, HttpStatus.INTERNAL_SERVER_ERROR);

    return new ResponseEntity<>(su, HttpStatus.CREATED);
}

From source file:com.example.notes.TagsController.java

@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(method = RequestMethod.POST)
HttpHeaders create(@RequestBody TagInput tagInput) {
    Tag tag = new Tag();
    tag.setName(tagInput.getName());//from   w  w  w.j a  va  2 s  . c o  m

    this.repository.save(tag);

    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setLocation(linkTo(TagsController.class).slash(tag.getId()).toUri());

    return httpHeaders;
}

From source file:com.nebhale.devoxx2013.web.GameController.java

@RequestMapping(method = RequestMethod.POST, value = "")
@Transactional//  www.  j  a v a  2s .  co m
ResponseEntity<Void> create() {
    Game game = this.gameService.create();

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(linkTo(GameController.class).slash(game).toUri());

    return new ResponseEntity<>(headers, HttpStatus.CREATED);
}

From source file:com.moxian.ng.api.user.SignupController.java

@RequestMapping(value = { "/signup" }, method = RequestMethod.POST)
@ResponseBody//from   w ww .java  2s . co  m
public ResponseEntity<Void> signup(@RequestBody @Valid SignupForm form, BindingResult errors,
        HttpServletRequest req) {
    if (log.isDebugEnabled()) {
        log.debug("signup data@" + form);
    }

    if (errors.hasErrors()) {
        throw new InvalidRequestException(errors);
    }

    UserDetails saved = userService.registerUser(form);

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(ServletUriComponentsBuilder.fromContextPath(req)
            .path(Constants.URI_API_PUBLIC + Constants.URI_USERS + "/{id}").buildAndExpand(saved.getId())
            .toUri());

    return new ResponseEntity<>(headers, HttpStatus.CREATED);
}

From source file:org.osiam.auth.oauth_client.ClientManagementController.java

@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody//w w w .  j a va  2  s . c  om
public ClientEntity create(@RequestBody String client) throws IOException {
    return clientDao.create(getClientEntity(client));
}

From source file:de.codecentric.boot.admin.controller.RegistryController.java

/**
 * Register an application within this admin application.
 * //  ww  w .j  ava2s  .  c o  m
 * @param app The application infos.
 * @return The registered application.
 */
@RequestMapping(value = "/api/applications", method = RequestMethod.POST)
public ResponseEntity<Application> register(@RequestBody Application app) {
    LOGGER.debug("Register application {}", app.toString());
    try {
        Application registeredApp = registry.register(app);
        return new ResponseEntity<Application>(registeredApp, HttpStatus.CREATED);
    } catch (ApplicationRegistryConflictException ex) {
        return new ResponseEntity<Application>(HttpStatus.CONFLICT);
    }
}

From source file:org.cloudfoundry.identity.uaa.codestore.CodeStoreEndpoints.java

@RequestMapping(value = { "/Codes" }, method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody//from w w  w .  ja  v  a 2  s  .c  om
public ExpiringCode generateCode(@RequestBody ExpiringCode expiringCode) {
    try {
        return expiringCodeStore.generateCode(expiringCode.getData(), expiringCode.getExpiresAt());
    } catch (NullPointerException e) {
        throw new CodeStoreException("data and expiresAt are required.", HttpStatus.BAD_REQUEST);
    } catch (IllegalArgumentException e) {
        throw new CodeStoreException("expiresAt must be in the future.", HttpStatus.BAD_REQUEST);
    } catch (DataIntegrityViolationException e) {
        throw new CodeStoreException("Duplicate code generated.", HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:technology.tikal.ventas.service.almacen.EntradaService.java

@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public void crear(@PathVariable final Long pedidoId, @Valid @RequestBody final RegistroAlmacenTransient request,
        final BindingResult result, final HttpServletRequest httpRequest,
        final HttpServletResponse httpResponse) {
    if (result.hasErrors()) {
        throw new NotValidException(result);
    }//from   ww  w. j  ava2  s  .  co  m
    Entrada nuevo = entradaController.crear(pedidoId, request);
    httpResponse.setHeader("Location", httpRequest.getRequestURI() + "/" + nuevo.getId());
}

From source file:com.artivisi.belajar.restful.ui.controller.MenuController.java

@RequestMapping(value = "/menu", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public void create(@RequestBody @Valid Menu x, HttpServletRequest request, HttpServletResponse response) {
    belajarRestfulService.save(x);// w  w  w  . j  a va 2 s . c om
    String requestUrl = request.getRequestURL().toString();
    URI uri = new UriTemplate("{requestUrl}/{id}").expand(requestUrl, x.getId());
    response.setHeader("Location", uri.toASCIIString());
}