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:org.kuali.mobility.emergencyinfo.controllers.EmergencyInfoController.java

@RequestMapping(method = RequestMethod.POST, headers = "Accept=application/json")
public ResponseEntity<String> post(@RequestBody String json) {
    emergencyInfoService.saveEmergencyInfo(emergencyInfoService.fromJsonToEntity(json));
    return new ResponseEntity<String>(HttpStatus.CREATED);
}

From source file:cn.dsgrp.field.stock.rest.TaskRestController.java

@RequestMapping(method = RequestMethod.POST, consumes = MediaTypes.JSON)
public ResponseEntity<?> create(@RequestBody Task task, UriComponentsBuilder uriBuilder) {
    // JSR303 Bean Validator, RestExceptionHandler?.
    BeanValidators.validateWithException(validator, task);

    // ?/*  w w w .  j  a v a  2s .  c o  m*/
    taskService.saveTask(task);

    // Restful?url, ?id.
    BigInteger id = task.getId();
    URI uri = uriBuilder.path("/api/v1/task/" + id).build().toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(uri);

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

From source file:wad.controller.ReceiptController.java

@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ResponseEntity<byte[]> showReceipt(@PathVariable Long expenseId, @PathVariable Long id) {
    Receipt receipt = receiptRepository.findOne(id);
    Expense expense = expenseService.getExpense(expenseId);

    if (expense == null || !expense.isViewableBy(userService.getCurrentUser())) {
        throw new ResourceNotFoundException();
    }//ww  w. jav  a 2 s  . co m

    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.parseMediaType(receipt.getMediaType()));
    headers.setContentLength(receipt.getSize());
    headers.add("Content-Disposition", "attachment; filename=" + receipt.getName());

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

From source file:reconf.server.services.property.UpsertPropertyService.java

@RequestMapping(value = "/product/{prod}/component/{comp}/property/{prop}", method = RequestMethod.PUT)
@Transactional//from   ww  w.  j ava  2s  . co  m
public ResponseEntity<PropertyResult> global(@PathVariable("prod") String product,
        @PathVariable("comp") String component, @PathVariable("prop") String property,
        @RequestBody String value, @RequestParam(value = "desc", required = false) String description,
        HttpServletRequest request, Authentication auth) {

    PropertyKey key = new PropertyKey(product, component, property);
    Property reqProperty = new Property(key, value, description);

    List<String> errors = DomainValidator.checkForErrors(reqProperty);

    if (!errors.isEmpty()) {
        return new ResponseEntity<PropertyResult>(new PropertyResult(reqProperty, errors),
                HttpStatus.BAD_REQUEST);
    }
    if (!products.exists(key.getProduct())) {
        return new ResponseEntity<PropertyResult>(new PropertyResult(reqProperty, Product.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }
    if (!components.exists(new ComponentKey(key.getProduct(), key.getComponent()))) {
        return new ResponseEntity<PropertyResult>(new PropertyResult(reqProperty, Component.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }

    HttpStatus status = null;
    Property dbProperty = properties.findOne(key);
    if (dbProperty != null) {
        dbProperty.setValue(value);
        dbProperty.setDescription(description);
        status = HttpStatus.OK;

    } else {
        dbProperty = reqProperty;
        properties.save(dbProperty);
        status = HttpStatus.CREATED;
    }
    return new ResponseEntity<PropertyResult>(
            new PropertyResult(dbProperty, CrudServiceUtils.getBaseUrl(request)), status);
}

From source file:ch.wisv.areafiftylan.users.controller.UserRestController.java

/**
 * This method accepts POST requests on /users. It will send the input to the {@link UserService} to create a new
 * user/*from www.j  av  a2  s. co  m*/
 *
 * @param input The user that has to be created. It consists of 3 fields. The username, the email and the plain-text
 *              password. The password is saved hashed using the BCryptPasswordEncoder
 *
 * @return The generated object, in JSON format.
 */
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<?> add(HttpServletRequest request, @Validated @RequestBody UserDTO input) {
    User save = userService.create(input, request);

    // Create headers to set the location of the created User object.
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setLocation(ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}")
            .buildAndExpand(save.getId()).toUri());

    return createResponseEntity(HttpStatus.CREATED, httpHeaders,
            "User successfully created at " + httpHeaders.getLocation(), save);
}

From source file:cn.cdwx.jpa.web.account.TaskRestController.java

@RequestMapping(method = RequestMethod.POST, consumes = MediaTypes.JSON)
public ResponseEntity<?> create(@RequestBody Task task, UriComponentsBuilder uriBuilder) {
    // JSR303 Bean Validator, RestExceptionHandler?.
    BeanValidators.validateWithException(validator, task);

    // ?//from   www  .  j a v a 2 s .c  o  m
    taskService.saveTask(task);

    // Restful?url, ?id.
    String id = task.getId();
    URI uri = uriBuilder.path("/api/v1/task/" + id).build().toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(uri);

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

From source file:plbtw.klmpk.barang.hilang.controller.KategoriBarangController.java

@RequestMapping(method = RequestMethod.PUT, produces = "application/json")
public CustomResponseMessage updateKategoriBarang(@RequestBody KategoriBarangRequest kategoriBarangRequest) {
    try {/*from w w w.  j  ava  2 s  .com*/
        KategoriBarang kategoriBarang = kategoriBarangService.getKategoriBarang(kategoriBarangRequest.getId());
        kategoriBarang.setJenis(kategoriBarangRequest.getJenis());
        kategoriBarangService.updateKategoriBarang(kategoriBarang);
        return new CustomResponseMessage(HttpStatus.CREATED, "Update Successfull");
    } catch (Exception ex) {
        return new CustomResponseMessage(HttpStatus.BAD_REQUEST, ex.toString());
    }
}

From source file:com.envision.envservice.rest.EvaluationResource.java

/**
 * ??/*from  w w  w . j  a  v  a  2s .  c  o m*/
 * 
 * */
@POST
@Path("/addEvaluation")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response addEvaluation(EvaluationBo evaluationBo) throws Exception {
    HttpStatus status = HttpStatus.CREATED;
    String response = StringUtils.EMPTY;
    if (!checkParam(evaluationBo)) {
        status = HttpStatus.BAD_REQUEST;
        response = FailResult.toJson(Code.PARAM_ERROR, "?");
    } else {
        response = evaluationService.addEvaluation(evaluationBo).toJSONString();
    }
    return Response.status(status.value()).entity(response).build();
}

From source file:org.jasig.portlet.survey.mvc.SurveyRestController.java

/**
 * Create a new question that is not associated with a survey.
 * /*from   w w w  .  ja v  a2 s .  c om*/
 * @param question
 * @return
 */
@PreAuthorize("hasRole('ADMIN')")
@ApiMethod(description = "Create a new question that is not associated with a survey.", responsestatuscode = "201 - Created")
@RequestMapping(method = RequestMethod.POST, value = "/questions")
public @ApiResponseObject ResponseEntity<QuestionDTO> addQuestion(
        @ApiBodyObject @RequestBody QuestionDTO question) {
    QuestionDTO newQuestion = dataService.createQuestion(question);
    return new ResponseEntity<>(newQuestion, HttpStatus.CREATED);
}

From source file:io.github.howiefh.jeews.modules.sys.controller.RoleController.java

@RequiresPermissions("role:create")
@RequestMapping(value = "", method = RequestMethod.POST)
public ResponseEntity<RoleResource> create(HttpEntity<Role> entity, HttpServletRequest request)
        throws URISyntaxException {
    Role role = entity.getBody();
    roleService.save(role);//from   w  w w  .  j av a  2  s.c  o m
    HttpHeaders headers = new HttpHeaders();
    RoleResource roleResource = new RoleResourceAssembler().toResource(role);
    headers.setLocation(entityLinks.linkForSingleResource(Role.class, role.getId()).toUri());
    ResponseEntity<RoleResource> responseEntity = new ResponseEntity<RoleResource>(roleResource, headers,
            HttpStatus.CREATED);
    return responseEntity;
}