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:org.jbr.taskmgr.web.controller.TaskController.java
@RequestMapping(method = RequestMethod.POST) @RestEndpoint/*from w w w .jav a 2s. c o m*/ public ResponseEntity<TaskResource> createTask(@Valid @RequestBody final TaskResource task) throws TaskManagerException { final Task createdTask = taskService.createTask(taskAssembler.toEntity(task)); if (LOG.isDebugEnabled()) { LOG.debug("createdTask = {}", createdTask); } final TaskResource resource = taskAssembler.toResource(createdTask); resource.add(linkTo(TaskController.class).slash(task.getUuid()).withSelfRel()); return new ResponseEntity<>(resource, HttpStatus.CREATED); }
From source file:de.codecentric.boot.admin.AdminApplicationHazelcastTest.java
@Test public void test() { Application app = Application.create("Hazelcast Test").withHealthUrl("http://127.0.0.1/health").build(); Application app2 = Application.create("Hazelcast Test").withHealthUrl("http://127.0.0.1:2/health").build(); Application app3 = Application.create("Do not find").withHealthUrl("http://127.0.0.1:3/health").build(); // publish app on instance1 ResponseEntity<Application> postResponse = registerApp(app, instance1); app = postResponse.getBody();// w w w . j av a 2 s. co m assertEquals(HttpStatus.CREATED, postResponse.getStatusCode()); assertNotNull(app.getId()); // publish app2 on instance2 ResponseEntity<Application> postResponse2 = registerApp(app2, instance2); app2 = postResponse2.getBody(); assertEquals(HttpStatus.CREATED, postResponse.getStatusCode()); assertNotNull(app2.getId()); // retrieve app from instance2 ResponseEntity<Application> getResponse = getApp(app.getId(), instance2); assertEquals(HttpStatus.OK, getResponse.getStatusCode()); assertEquals(app, getResponse.getBody()); // retrieve app and app2 from instance1 (but not app3) app3 = registerApp(app3, instance1).getBody(); Collection<Application> apps = getAppByName("Hazelcast Test", instance1).getBody(); assertEquals(2, apps.size()); assertTrue(apps.contains(app)); assertTrue(apps.contains(app2)); assertFalse(apps.contains(app3)); }
From source file:com.mycompany.springrest.controllers.RoleController.java
@RequestMapping(value = "/role/", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Void> createRole(@RequestBody Role role, UriComponentsBuilder ucBuilder) { logger.info("Creating Role " + role.getName()); if (roleService.isRoleExist(role)) { logger.info("A Role with name " + role.getName() + " already exist"); return new ResponseEntity<Void>(HttpStatus.CONFLICT); }/*from w w w . j av a 2 s .c om*/ roleService.addRole(role); HttpHeaders headers = new HttpHeaders(); headers.setLocation(ucBuilder.path("/role/{id}").buildAndExpand(role.getId()).toUri()); return new ResponseEntity<Void>(headers, HttpStatus.CREATED); }
From source file:org.mifos.module.sms.controller.MifosSmsController.java
@RequestMapping(value = "/sms/configuration", method = RequestMethod.POST, consumes = { "application/json" }, produces = { "application/json" }) public ResponseEntity<String> createSMSBridgeConfig(@RequestBody final SMSBridgeConfig smsBridgeConfig) { if (this.smsBridgeService.findSmsBridgeConfigByTenantId(smsBridgeConfig.getTenantId()) != null) { return new ResponseEntity<>("Tenant " + smsBridgeConfig.getTenantId() + " already exists!", HttpStatus.BAD_REQUEST); }/*from w w w . j a va2 s . c om*/ final String newApiKey = this.securityService.generateApiKey(smsBridgeConfig.getTenantId(), smsBridgeConfig.getMifosToken(), smsBridgeConfig.getSmsProviderAccountId(), smsBridgeConfig.getSmsProviderToken()); smsBridgeConfig.setApiKey(newApiKey); this.smsBridgeService.createSmsBridgeConfig(smsBridgeConfig); return new ResponseEntity<>(newApiKey, HttpStatus.CREATED); }
From source file:org.oncoblocks.centromere.web.controller.CrudApiController.java
/** * {@code POST /}//www . j a v a 2 s .co m * Attempts to create a new record using the submitted entity. Throws an exception if the * entity already exists. * * @param entity entity representation to be persisted * @return updated representation of the submitted entity */ @RequestMapping(value = "", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE, ApiMediaTypes.APPLICATION_HAL_JSON_VALUE, ApiMediaTypes.APPLICATION_HAL_XML_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_PLAIN_VALUE }) public HttpEntity<?> create(@RequestBody T entity, HttpServletRequest request) { T created = getRepository().insert(entity); if (created == null) throw new RequestFailureException(40003, "There was a problem creating the record.", "", ""); if (ApiMediaTypes.isHalMediaType(request.getHeader("Accept"))) { FilterableResource resource = getAssembler().toResource(created); return new ResponseEntity<>(resource, HttpStatus.CREATED); } else { return new ResponseEntity<>(created, HttpStatus.CREATED); } }
From source file:de.escalon.hypermedia.sample.event.ReviewController.java
@Action("ReviewAction") @RequestMapping(value = "/events/{eventId}", method = RequestMethod.POST) public @ResponseBody ResponseEntity<Void> addReview(@PathVariable int eventId, @RequestBody Review review) { Assert.notNull(review);/*from ww w . j a v a2 s .c o m*/ Assert.notNull(review.getReviewRating()); Assert.notNull(review.getReviewRating().getRatingValue()); ResponseEntity<Void> responseEntity; try { eventBackend.addReview(eventId, review.getReviewBody(), review.getReviewRating()); final HttpHeaders headers = new HttpHeaders(); headers.setLocation(AffordanceBuilder .linkTo(AffordanceBuilder.methodOn(this.getClass()).getReviews(eventId)).toUri()); responseEntity = new ResponseEntity<Void>(headers, HttpStatus.CREATED); } catch (NoSuchElementException ex) { responseEntity = new ResponseEntity<Void>(HttpStatus.NOT_FOUND); } return responseEntity; }
From source file:org.bonitasoft.web.designer.controller.ImportController.java
@RequestMapping(value = "/import/{artifactType}", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE) @ResponseStatus(HttpStatus.CREATED) @ResponseBody/*from ww w.jav a 2s . c o m*/ public ImportReport importArtifact(@RequestParam("file") MultipartFile file, @RequestParam(value = "force", defaultValue = "false", required = false) boolean force, @PathVariable(value = "artifactType") String artifactType) { checkFilePartIsPresent(file); checkFileIsZip(file); Path extractDir = unzip(file); ArtifactImporter importer = getArtifactImporter(artifactType, extractDir); if (force) { return pathImporter.forceImportFromPath(extractDir, importer); } return pathImporter.importFromPath(extractDir, importer); }
From source file:eu.supersede.dm.rest.CriteriaRest.java
/** * Create a new criterion.//from www .j a v a2s .c o m * @param vc */ @RequestMapping(value = "", method = RequestMethod.POST) public ResponseEntity<?> createCriteria(@RequestBody ValutationCriteria vc) { vc.setCriteriaId(null); DMGame.get().getJpa().criteria.save(vc); // valutationCriterias.save(vc); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation(ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}") .buildAndExpand(vc.getCriteriaId()).toUri()); return new ResponseEntity<>(null, httpHeaders, HttpStatus.CREATED); }
From source file:io.github.howiefh.jeews.modules.sys.controller.OrganizationController.java
@RequiresPermissions("organization:create") @RequestMapping(value = "", method = RequestMethod.POST) public ResponseEntity<OrganizationResource> create(HttpEntity<Organization> entity, HttpServletRequest request) throws URISyntaxException { Organization organization = entity.getBody(); organizationService.save(organization); HttpHeaders headers = new HttpHeaders(); OrganizationResource organizationResource = new OrganizationResourceAssembler().toResource(organization); headers.setLocation(entityLinks.linkForSingleResource(Organization.class, organization.getId()).toUri()); ResponseEntity<OrganizationResource> responseEntity = new ResponseEntity<OrganizationResource>( organizationResource, headers, HttpStatus.CREATED); return responseEntity; }
From source file:de.hska.ld.content.controller.TagControllerIntegrationTest.java
@Test public void testCreateTagUsesHttpCreatedOnPersist() throws Exception { HttpResponse response = UserSession.user().post(RESOURCE_TAG, tag); Assert.assertEquals(HttpStatus.CREATED, ResponseHelper.getStatusCode(response)); Tag tag = ResponseHelper.getBody(response, Tag.class); Assert.assertNotNull(tag);/* w w w .j av a 2 s . c o m*/ Assert.assertNotNull(tag.getId()); }