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.bennavetta.appsite.webapi.SettingsController.java
@RequestMapping(method = POST, value = "/{name}") public ResponseEntity<String> putSetting(@PathVariable String name, @RequestBody String value) { settings.set(name, value);/*from ww w.ja v a 2s . com*/ log.trace("Setting {} = {}", name, value); HttpHeaders headers = new HttpHeaders(); URI location = ServletUriComponentsBuilder.fromCurrentServletMapping().path("/settings/{name}").build() .expand(name).toUri(); headers.setLocation(location); return new ResponseEntity<String>(headers, HttpStatus.CREATED); }
From source file:cn.aozhi.songify.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. ja v a2 s. c o m taskService.saveTask(task); // Restful?url, ?id. Long 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:de.codecentric.boot.admin.services.ApplicationRegistrator.java
/** * Registers the client application at spring-boot-admin-server. * * @return true if successful registration on at least one admin server */// ww w .ja va 2 s . c om public boolean register() { boolean isRegistrationSuccessful = false; Application self = createApplication(); for (String adminUrl : admin.getAdminUrl()) { try { @SuppressWarnings("rawtypes") ResponseEntity<Map> response = template.postForEntity(adminUrl, new HttpEntity<>(self, HTTP_HEADERS), Map.class); if (response.getStatusCode().equals(HttpStatus.CREATED)) { if (registeredId.compareAndSet(null, response.getBody().get("id").toString())) { LOGGER.info("Application registered itself as {}", response.getBody()); } else { LOGGER.debug("Application refreshed itself as {}", response.getBody()); } isRegistrationSuccessful = true; if (admin.isRegisterOnce()) { break; } } else { LOGGER.warn("Application failed to registered itself as {}. Response: {}", self, response.toString()); } } catch (Exception ex) { LOGGER.warn("Failed to register application as {} at spring-boot-admin ({}): {}", self, admin.getAdminUrl(), ex.getMessage()); } } return isRegistrationSuccessful; }
From source file:am.ik.categolj2.api.file.FileRestController.java
@RequestMapping(method = RequestMethod.POST/*, headers = Categolj2Headers.X_ADMIN*/) public ResponseEntity<List<FileResource>> uploadFiles(FilesForm filesForm) { List<UploadFile> uploadFiles = filesForm.getFiles().stream().map(fileHelper::multipartFileToUploadFile) .collect(Collectors.toList()); List<FileResource> created = uploadFileService.create(uploadFiles).stream() .map(resource -> beanMapper.map(resource, FileResource.class)).collect(Collectors.toList()); return new ResponseEntity<>(created, HttpStatus.CREATED); }
From source file:com.salmon.security.xacml.demo.springmvc.rest.controller.MarketPlacePopulatorController.java
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json", value = "vehicleadd") @ResponseStatus(HttpStatus.CREATED) @ResponseBody/*from w w w . j ava 2 s. com*/ public ResponseEntity<Vehicle> createVehicle(@RequestBody Vehicle vehicle, UriComponentsBuilder builder) { LOG.info("REST CREATE Vechicle - " + vehicle.toString()); marketPlaceController.registerVehicle(vehicle); HttpHeaders headers = new HttpHeaders(); URI newVehicleLocation = builder.path("/aggregators/dvla/vehicles/{plate}") .buildAndExpand(vehicle.getPlate()).toUri(); LOG.info("REST CREATE VEHICLE - new vehicle @ " + newVehicleLocation.toString()); headers.setLocation(newVehicleLocation); return new ResponseEntity<Vehicle>(vehicle, headers, HttpStatus.CREATED); }
From source file:com.nicusa.controller.DrugControllerTest.java
@Test public void testCreateDrugAsALoggedInUser() { Drug drug = new Drug(); drug.setId(1L);// w w w . j a v a 2s . co m DrugResource drugResource = new DrugResource(); when(securityController.getAuthenticatedUserProfileId()).thenReturn(1L); when(drugResourceToDomainConverter.convert(drugResource)).thenReturn(drug); ResponseEntity<?> responseEntity = drugController.create(drugResource); assertThat(responseEntity.getStatusCode(), is(HttpStatus.CREATED)); }
From source file:bg.vitkinov.edu.services.JokeCategoryService.java
@RequestMapping(method = { RequestMethod.POST, RequestMethod.PUT }) public ResponseEntity<?> insert(@RequestParam String name, @RequestParam String keywords) { Optional<Category> category = repository.findByName(name); if (category.isPresent()) { return new ResponseEntity<>(category.get(), HttpStatus.CONFLICT); }/*ww w. j av a2 s . c o m*/ Category newCateogry = new Category(); newCateogry.setName(name); newCateogry.setKeyWords(getKewWors(keywords)); return new ResponseEntity<>(repository.save(newCateogry), HttpStatus.CREATED); }
From source file:de.hska.ld.content.controller.FolderControllerIntegrationTest.java
@Test public void testCreateSubFolderUsesHttpCreatedOnPersist() 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); Long folderId = folder.getId(); Assert.assertNotNull(folderId);/*from w w w .j av a 2 s .co m*/ Folder subFolder = new Folder("Sub Test"); HttpResponse response2 = UserSession.user().post(RESOURCE_FOLDER + "/" + folderId + "/folders", subFolder); Assert.assertEquals(HttpStatus.CREATED, ResponseHelper.getStatusCode(response2)); Assert.assertEquals(ResponseHelper.getBody(response2, FolderDto.class).getJsonParentId(), folderId); }
From source file:com.btmatthews.leabharlann.controller.LibraryController.java
/** * The endpoint that creates a new sub-folder in a workspace. * * @param workspaceName The workspace name. * @param node The node identifier of the parent folder. * @param folder The {@link Folder} descriptor for the new folder. * @return The {@link Folder} for the newly created node. */// w ww .j av a 2s . co m @RequestMapping(value = "workspaces/{workspace}/folders/{node}/folder", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) @ResponseBody public Folder createFolder(@PathVariable("workspace") final String workspaceName, @PathVariable("node") final String node, @RequestBody final Folder folder) { final Workspace workspace = libraryService.getWorkspace(workspaceName); return libraryService.createFolder(workspace, node, folder.getName()); }
From source file:org.openbaton.autoscaling.api.RestEventInterface.java
/** * Deactivates autoscaling for the passed NSR * * @param msg : NSR in payload to add for autoscaling *//* www .j a v a 2s .c o m*/ @RequestMapping(value = "RELEASE_RESOURCES_FINISH", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public void deactivate(@RequestBody String msg) throws NotFoundException { log.debug("========================"); log.debug("msg=" + msg); JsonParser jsonParser = new JsonParser(); JsonObject json = jsonParser.parse(msg).getAsJsonObject(); Gson mapper = new GsonBuilder().create(); Action action = mapper.fromJson(json.get("action"), Action.class); log.debug("ACTION=" + action); NetworkServiceRecord nsr = mapper.fromJson(json.get("payload"), NetworkServiceRecord.class); log.debug("NSR=" + nsr); elasticityManagement.deactivate(nsr.getId()); }