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:eu.agilejava.javaonedemo.api.CookBookResource.java

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

    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:org.osiam.resources.controller.UserController.java

@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody/*from   w ww  .  j  av a2 s  .c  om*/
public User create(HttpServletRequest request, HttpServletResponse response) throws IOException {
    User user = jsonInputValidator.validateJsonUser(request);
    User createdUser = scimUserProvisioning.create(user);

    String requestUrl = request.getRequestURL().toString();
    URI uri = new UriTemplate("{requestUrl}{internalId}").expand(requestUrl + "/", createdUser.getId());
    response.setHeader("Location", uri.toASCIIString());
    Meta newMeta = new Meta.Builder(createdUser.getMeta()).setLocation(uri.toASCIIString()).build();

    return new User.Builder(createdUser).setMeta(newMeta).build();
}

From source file:za.ac.cput.project.universalhardwarestorev2.api.ItemApi.java

@RequestMapping(value = "/item/create", method = RequestMethod.POST)
public ResponseEntity<Void> createItem(@RequestBody Item item, UriComponentsBuilder ucBuilder) {
    System.out.println("Creating Item " + item.getName());

    //     USE THIS IF YOU WANT TO CHECK UNIQUE OBJECT
    //      if (ItemService.isItemExist(Item)) {
    //            System.out.println("A Item with name " + Item.getName() + " already exist");
    //            return new ResponseEntity<Void>(HttpStatus.CONFLICT);
    //        }//  www .  j av  a2  s.c  om

    service.save(item);

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

From source file:org.ow2.proactive.workflow_catalog.rest.controller.WorkflowRevisionController.java

@ApiOperation(value = "Creates a new workflow revision")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Bucket not found"),
        @ApiResponse(code = 422, message = "Invalid XML workflow content supplied") })
@RequestMapping(value = "/buckets/{bucketId}/workflows/{workflowId}/revisions", consumes = {
        MediaType.MULTIPART_FORM_DATA_VALUE }, method = POST)
@ResponseStatus(HttpStatus.CREATED)
public WorkflowMetadata create(@PathVariable Long bucketId, @PathVariable Long workflowId,
        @ApiParam(value = "Layout describing the tasks position in the Workflow Revision") @RequestParam(required = false) Optional<String> layout,
        @RequestPart(value = "file") MultipartFile file) throws IOException {
    return workflowRevisionService.createWorkflowRevision(bucketId, Optional.of(workflowId), file.getBytes(),
            layout);/*ww  w.  j a  va  2  s  .  c o  m*/
}

From source file:com.github.hateoas.forms.spring.sample.test.ReviewController.java

@Action("ReviewAction")
@RequestMapping(value = "/events/{eventId}", method = RequestMethod.POST, params = { "review", "rating" })
public @ResponseBody ResponseEntity<Void> addReview(@PathVariable int eventId, @RequestParam String review,
        @RequestParam int rating) {
    final HttpHeaders headers = new HttpHeaders();
    headers.setLocation(AffordanceBuilder
            .linkTo(AffordanceBuilder.methodOn(this.getClass()).getReviews(eventId, null)).toUri());
    return new ResponseEntity(headers, HttpStatus.CREATED);
}

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

@RequestMapping(method = RequestMethod.POST, consumes = APPLICATION_JSON_VALUE)
public ResponseEntity<CookBookUser> create(@RequestBody CookBookUser user) {
    cookBookUserService.create(user);//from w w w  .  j  a va2 s. c  o m

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

From source file:nu.yona.server.batch.quartz.JobController.java

@RequestMapping(value = "/{group}/", method = RequestMethod.POST)
@ResponseBody//from  w  ww.j a  va 2 s. c o m
@ResponseStatus(HttpStatus.CREATED)
public JobResource addJob(@PathVariable String group, @RequestBody JobDto job) {
    job.setGroup(group);
    return new JobResourceAssembler().toResource(jobManagementService.addJob(group, job));
}

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

@POST
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)//w ww.  j av a  2s .  c  om
@Produces(MediaType.APPLICATION_JSON)
public Response add(@PathParam("id") int id, UserCaseCommentBo userCaseComment) throws Exception {
    HttpStatus status = HttpStatus.CREATED;
    String response = StringUtils.EMPTY;

    if (!checkParam(userCaseComment)) {
        status = HttpStatus.BAD_REQUEST;
        response = FailResult.toJson(Code.PARAM_ERROR, "?");
    } else {
        userCaseCommentService.add(id, userCaseComment);
    }
    return Response.status(status.value()).entity(response).build();
}

From source file:gateway.test.AlertTriggerTests.java

/**
 * Test POST /trigger// w  ww .jav  a 2  s . c om
 * 
 * @throws JsonProcessingException
 */
@Test
public void testCreateTrigger() throws JsonProcessingException {
    // Mock Response
    when(restTemplate.postForObject(anyString(), any(), eq(String.class))).thenReturn(any(String.class));

    // Test
    ResponseEntity<?> response = alertTriggerController.createTrigger(new Trigger(), user);

    // Verify
    assertTrue(response.getStatusCode().equals(HttpStatus.CREATED));

    // Test Exception
    when(restTemplate.postForObject(anyString(), any(), eq(String.class)))
            .thenThrow(new RestClientException("Trigger Error"));
    response = alertTriggerController.createTrigger(new Trigger(), user);
    assertTrue(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR));
    assertTrue(response.getBody() instanceof ErrorResponse);
    assertTrue(((ErrorResponse) response.getBody()).message.contains("Trigger Error"));
}

From source file:com.marklogic.samplestack.web.ContributorsController.java

/**
 * Creates a new contributor based on data in the request body
 * @param contributor The request body, marshalled into a Contributor object.
 * @return The newly persisted Contributor, with automated data added.
 *//* w w w  .ja  va  2s .  c o  m*/
@RequestMapping(value = "contributors", method = RequestMethod.POST)
public @ResponseBody @PreAuthorize("hasRole('ROLE_ADMINS')") @ResponseStatus(HttpStatus.CREATED) Contributor newContributor(
        @RequestBody Contributor contributor) {
    contributor.setId(UUID.randomUUID().toString());
    service.store(contributor);
    return contributor;
}