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:de.hska.ld.content.controller.FolderControllerIntegrationTest.java

@Test
public void testCreateFolderUsesHttpCreatedOnPersist() throws Exception {
    Folder folder = new Folder("Test");
    HttpResponse response = UserSession.user().post(RESOURCE_FOLDER, folder);
    Assert.assertEquals(HttpStatus.CREATED, ResponseHelper.getStatusCode(response));
    folder = ResponseHelper.getBody(response, Folder.class);
    Assert.assertNotNull(folder.getId());
}

From source file:com.tsg.cms.StaticPageController.java

@RequestMapping(value = "/staticPage/{id}", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody/*from w w  w.  jav a  2s.  co m*/
public StaticPage updateStaticPage(@PathVariable("id") int id, @RequestBody StaticPage staticPage) {

    if (staticPage.getCategoryIdFK() == -1) {
        staticPage.setCategoryIdFK(null);
    }
    if (staticPage.getStatus() == null) {
        staticPage.setStatus(Status.DRAFT);
    }
    staticPage.setPageId(id);
    staticPageDao.updateStaticPage(staticPage);
    return staticPage;
}

From source file:io.openshift.booster.service.FruitController.java

@ResponseBody
@ResponseStatus(HttpStatus.CREATED)
@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public Fruit post(@RequestBody(required = false) Fruit fruit) {
    verifyCorrectPayload(fruit);/*from   ww  w  .ja va 2s .  com*/

    return repository.save(fruit);
}

From source file:ca.qhrtech.controllers.UserController.java

@ApiMethod(description = "Add a new User to BGL")
@RequestMapping(value = "/user", method = RequestMethod.POST)
public ResponseEntity<BGLUser> createUser(@RequestBody BGLUser user) {
    if (!userService.doesUserExist(user)) {
        user.setJoinDate(LocalDateTime.now());
        String hash = new BCryptPasswordEncoder().encode(user.getPassword());
        user.setPassword(hash);//from   w  ww  .  j ava2  s.  c  om
        BGLUser newUser = userService.saveUser(user);
        return new ResponseEntity<>(newUser, HttpStatus.CREATED);
    }
    return new ResponseEntity<>(HttpStatus.CONFLICT);
}

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

@Test
public void testBuildUriTemplate() throws Exception {
    ResponseEntity<Void> response = builder.location("/url/to/{entity}", "blah").build();
    Assert.assertNotNull(response);/*w ww.  j  a  va 2 s  .co m*/
    Assert.assertEquals(HttpStatus.CREATED, response.getStatusCode());
    Assert.assertNull(response.getBody());
    Assert.assertNotNull(response.getHeaders().getLocation());
    Assert.assertEquals(new URI("/url/to/blah"), response.getHeaders().getLocation());
    Assert.assertNull(response.getHeaders().getETag());
    Assert.assertEquals(-1l, response.getHeaders().getLastModified());
    Assert.assertNull(response.getHeaders().getCacheControl());
    Assert.assertEquals(-1l, response.getHeaders().getExpires());
    Assert.assertEquals(-1l, response.getHeaders().getDate());
}

From source file:io.github.microcks.web.ImportController.java

@RequestMapping(value = "/import", method = RequestMethod.POST)
public ResponseEntity<?> importRepository(@RequestParam(value = "file") MultipartFile file) {
    log.debug("Importing new services and resources definitions");
    if (!file.isEmpty()) {
        log.debug("Content type of " + file.getOriginalFilename() + " is " + file.getContentType());
        if (MediaType.APPLICATION_JSON_VALUE.equals(file.getContentType())) {
            try {
                byte[] bytes = file.getBytes();
                String json = new String(bytes);
                importExportService.importRepository(json);
            } catch (Exception e) {
                log.error(e.getMessage());
            }/* w  ww. j a va 2  s. c o m*/
        }
    }
    return new ResponseEntity<Object>(HttpStatus.CREATED);
}

From source file:de.escalon.hypermedia.spring.sample.ReviewController.java

@RequestMapping(value = "/events/{eventId}", method = RequestMethod.POST)
public @ResponseBody ResponseEntity<Void> addReview(@PathVariable int eventId, @RequestBody Review review) {
    Assert.notNull(review);/*w w  w .  j  a v  a 2 s . c om*/
    Assert.notNull(review.getReviewRating());
    Assert.notNull(review.getReviewRating().getRatingValue());
    final HttpHeaders headers = new HttpHeaders();
    headers.setLocation(
            AffordanceBuilder.linkTo(AffordanceBuilder.methodOn(this.getClass()).getReviews(eventId)).toUri());
    return new ResponseEntity(headers, HttpStatus.CREATED);
}

From source file:edu.eci.arsw.pacm.controllers.PacmRESTController.java

@RequestMapping(path = "/{salanum}/protectores", method = RequestMethod.PUT)
public ResponseEntity<?> agregarProtector(@PathVariable(name = "salanum") String salanum,
        @RequestBody Player p) {//  ww  w  . j  a  v a  2 s.  c o m
    synchronized (this) {
        try {
            if (services.getProtectores(Integer.parseInt(salanum)).size() < 4) {
                services.registrarJugadorProtector(Integer.parseInt(salanum), p);
            }
        } catch (ServicesException ex) {
            Logger.getLogger(PacmRESTController.class.getName()).log(Level.SEVERE, null, ex);
            return new ResponseEntity<>(ex.getLocalizedMessage(), HttpStatus.BAD_REQUEST);
        }
        return new ResponseEntity<>(HttpStatus.CREATED);
    }
}

From source file:com.salmon.security.xacml.demo.springmvc.rest.controller.MarketPlaceQueryController.java

@RequestMapping(method = RequestMethod.GET, value = "xxx")
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody/*from  w  w w. ja va 2s  .  c  o  m*/
public DriverList createDrivers() {
    LOG.info("REST Driver LIST");
    marketPlaceController.registerDriver(new Driver("BARAK", "OBAMA", "OBAMALIC2015"));
    marketPlaceController.registerDriver(new Driver("DAVID", "CAMERON", "CAMERONLIC2014"));
    marketPlaceController.registerDriver(new Driver("HUGO", "CHAVEZ", "CHAVEZLIC2016"));

    return marketPlaceController.listDrivers();
}

From source file:com.boxedfolder.carrot.web.client.AnalyticsResource.java

@JsonView(View.Meta.class)
@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value = "/logs/{appKey}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public AnalyticsLog createAnalyticsLogs(@RequestBody @Valid AnalyticsLog log,
        @PathVariable("appKey") String appKey) {
    return service.save(log, UUID.fromString(appKey));
}