List of usage examples for org.springframework.http HttpStatus CREATED
HttpStatus CREATED
To view the source code for org.springframework.http HttpStatus CREATED.
Click Source Link
From source file:com.company.eleave.leave.rest.HolidayController.java
@RequestMapping(method = RequestMethod.POST) public ResponseEntity<Long> createNew(@RequestBody HolidayDTO holiday) { final long holidayId = holidayService.createNew(mapper.toEntity(holiday)); HttpHeaders headers = new HttpHeaders(); headers.setLocation(UriComponentsBuilder.fromPath("/leaveTypes/{id}").buildAndExpand(holidayId).toUri()); return new ResponseEntity<>(headers, HttpStatus.CREATED); }
From source file:net.eusashead.hateoas.response.impl.PutResponseBuilderImplTest.java
@Test public void testIsCreate() throws Exception { Entity entity = new Entity("foo"); Date now = new Date(1373571924000l); ResponseEntity<Void> response = builder.entity(entity).etag().lastModified(now).isCreate().build(); Assert.assertNotNull(response);//ww w.j a v a 2 s . c om Assert.assertEquals(HttpStatus.CREATED, response.getStatusCode()); Assert.assertNull(response.getBody()); Assert.assertNotNull(response.getHeaders().getETag()); Assert.assertEquals("W/\"b0c689597eb9dd62c0a1fb90a7c5c5a5\"", response.getHeaders().getETag()); Assert.assertEquals(now.getTime(), response.getHeaders().getLastModified()); }
From source file:org.openbaton.nfvo.api.RestKeys.java
/** * Generate a new Key with the given name for the given project * * @param name : name of the key to be created *//*from w w w. j av a 2s. c o m*/ @RequestMapping(value = "generate", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE) @ResponseStatus(HttpStatus.CREATED) public String generateKey(@RequestHeader(value = "project-id") String projectId, @RequestBody String name) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException, IOException { log.debug("Generating key with name: " + name); return keyManagement.generateKey(projectId, name); }
From source file:com.swcguild.addressbookmvc.controller.HomeController.java
@RequestMapping(value = "/contact", method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) //indicates that the content gets sent to client @ResponseBody/* w w w . j a va 2s.c om*/ public Contact createContact(@RequestBody Contact contact) { dao.addContact(contact); return contact; }
From source file:com.sentinel.web.controllers.RequestController.java
@RequestMapping(value = "", method = RequestMethod.POST) @PreAuthorize(value = "hasRole('SIMPLE_USER_PRIVILEGE')") @ResponseBody/*from ww w. j av a 2 s. c o m*/ public ResponseEntity<Void> createRequest(@RequestBody UserRequest userRequest) { LOG.debug("creating new Request "); try { new ObjectMapper().readValue(userRequest.getRequestDetails().trim(), OrientRequestDetails.class); } catch (Exception e) { LOG.error("Exception while performing operation in createRequest", e); return new ResponseEntity<Void>(HttpStatus.BAD_REQUEST); } UserAuthentication authentication = (UserAuthentication) SecurityContextHolder.getContext() .getAuthentication(); String userEmail = authentication.getName(); User user = userRepository.findByEmail(userEmail); Collection<User> collection = new ArrayList<User>(); collection.add(user); userRequest.setUsers(collection); userRequestRepository.saveAndFlush(userRequest); return new ResponseEntity<Void>(HttpStatus.CREATED); }
From source file:com.github.hateoas.forms.spring.sample.test.ReviewController.java
@RequestMapping(value = "/events/{eventId}", method = RequestMethod.POST) public @ResponseBody ResponseEntity<Void> addReview(@PathVariable int eventId, @RequestBody Review review) { Assert.notNull(review);//from w w w. ja v a 2 s . c o m Assert.notNull(review.getReviewRating()); Assert.notNull(review.getReviewRating().getRatingValue()); 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:ca.qhrtech.controllers.GameController.java
@ApiMethod(description = "Create a new Game") @RequestMapping(value = "/game", method = RequestMethod.POST) public ResponseEntity<Game> createGame(@RequestBody Game game) { if (!gameService.doesGameExist(game)) { Game newGame = gameService.saveGame(game); return new ResponseEntity<>(newGame, HttpStatus.CREATED); }/*from w w w . j a v a 2s . com*/ return new ResponseEntity<>(HttpStatus.CONFLICT); }
From source file:com.appglu.impl.UserTemplateTest.java
@Test public void signup() { responseHeaders.add(UserSessionPersistence.X_APPGLU_SESSION_HEADER, "sessionId"); mockServer.expect(requestTo("http://localhost/appglu/v1/users")).andExpect(method(HttpMethod.POST)) .andExpect(header("Content-Type", jsonMediaType.toString())) .andExpect(content().string(compactedJson("data/user_signup"))) .andRespond(withStatus(HttpStatus.CREATED).body(compactedJson("data/user_auth_response")) .headers(responseHeaders)); Assert.assertFalse(appGluTemplate.isUserAuthenticated()); Assert.assertNull(appGluTemplate.getAuthenticatedUser()); User user = new User(); user.setUsername("username"); user.setPassword("password"); AuthenticationResult result = userOperations.signup(user); Assert.assertTrue(result.succeed()); Assert.assertTrue(appGluTemplate.isUserAuthenticated()); Assert.assertNotNull(appGluTemplate.getAuthenticatedUser()); Assert.assertEquals(new Long(1L), appGluTemplate.getAuthenticatedUser().getId()); Assert.assertEquals("username", appGluTemplate.getAuthenticatedUser().getUsername()); Assert.assertNull(appGluTemplate.getAuthenticatedUser().getPassword()); mockServer.verify();/* w w w . j av a 2s. c o m*/ }
From source file:com.nebhale.letsmakeadeal.web.GamesController.java
@RequestMapping(method = RequestMethod.POST, value = "") ResponseEntity<Void> createGame() { Game game = this.gameRepository.create(); HttpHeaders headers = new HttpHeaders(); headers.setLocation(linkTo(GamesController.class).slash(game.getId()).toUri()); return new ResponseEntity<Void>(headers, HttpStatus.CREATED); }
From source file:com.torchmind.stockpile.server.controller.v1.ProfileController.java
/** * <code>GET /v1/profile/{name}</code> * * Looks up a profile based on its name or identifier. * * @param name a name or identifier.//from w w w .j ava 2 s .com * @return a response entity. */ @Nonnull @RequestMapping(path = "/{name}", method = RequestMethod.GET) public ResponseEntity<PlayerProfile> lookup(@Nonnull @PathVariable("name") String name) { final Profile profile; if (UUID_PATTERN.matcher(name).matches()) { UUID identifier = UUID.fromString(name); profile = this.profileService.get(identifier); } else { profile = this.profileService.find(name); } return new ResponseEntity<>(profile.toRestRepresentation(), (profile.isCached() ? HttpStatus.OK : HttpStatus.CREATED)); }