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:de.hska.ld.content.controller.TagControllerIntegrationTest.java
@Test public void testGetTagsPage() 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 a v a 2 s . com*/ Assert.assertNotNull(tag.getId()); HttpResponse responseGetTagList = UserSession.user().get(RESOURCE_TAG); Assert.assertEquals(HttpStatus.OK, ResponseHelper.getStatusCode(responseGetTagList)); List<Tag> tagList = ResponseHelper.getPageList(responseGetTagList, Tag.class); Assert.assertTrue(tagList.size() > 0); Assert.assertTrue(tagList.contains(tag)); }
From source file:org.openlmis.fulfillment.web.TransferPropertiesController.java
/** * Allows creating new transfer properties. * If the id is specified, it will be ignored. * * @param properties A transfer properties bound to the request body * @return ResponseEntity containing the created transfer properties *//*from w ww .jav a2s . com*/ @RequestMapping(value = "/transferProperties", method = RequestMethod.POST) @ResponseBody public ResponseEntity create(@RequestBody TransferPropertiesDto properties) { LOGGER.debug("Checking right to create transfer properties"); permissionService.canManageSystemSettings(); LOGGER.debug("Creating new Transfer Properties"); TransferProperties entity = TransferPropertiesFactory.newInstance(properties); List<Message.LocalizedMessage> errors = validate(entity); if (isNotTrue(errors.isEmpty())) { return ResponseEntity.badRequest().body(errors); } properties.setId(null); TransferProperties saved = transferPropertiesService.save(entity); LOGGER.debug("Created new Transfer Properties with id: {}", saved.getId()); return ResponseEntity.status(HttpStatus.CREATED) .body(TransferPropertiesFactory.newInstance(saved, exporter)); }
From source file:com.boyuanitsm.fort.web.rest.AccountResource.java
/** * POST /register : register the user./*from w ww .jav a2s. c o m*/ * * @param managedUserDTO the managed user DTO * @param request the HTTP request * @return the ResponseEntity with status 201 (Created) if the user is registred or 400 (Bad Request) if the login or e-mail is already in use */ @RequestMapping(value = "/register", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_PLAIN_VALUE }) @Timed public ResponseEntity<?> registerAccount(@Valid @RequestBody ManagedUserDTO managedUserDTO, HttpServletRequest request) { HttpHeaders textPlainHeaders = new HttpHeaders(); textPlainHeaders.setContentType(MediaType.TEXT_PLAIN); return userRepository.findOneByLogin(managedUserDTO.getLogin().toLowerCase()) .map(user -> new ResponseEntity<>("login already in use", textPlainHeaders, HttpStatus.BAD_REQUEST)) .orElseGet(() -> userRepository.findOneByEmail(managedUserDTO.getEmail()) .map(user -> new ResponseEntity<>("e-mail address already in use", textPlainHeaders, HttpStatus.BAD_REQUEST)) .orElseGet(() -> { User user = userService.createUserInformation(managedUserDTO.getLogin(), managedUserDTO.getPassword(), managedUserDTO.getFirstName(), managedUserDTO.getLastName(), managedUserDTO.getEmail().toLowerCase(), managedUserDTO.getLangKey()); String baseUrl = request.getScheme() + // "http" "://" + // "://" request.getServerName() + // "myhost" ":" + // ":" request.getServerPort() + // "80" request.getContextPath(); // "/myContextPath" or "" if deployed in root context mailService.sendActivationEmail(user, baseUrl); return new ResponseEntity<>(HttpStatus.CREATED); })); }
From source file:io.github.microcks.web.TestController.java
@RequestMapping(value = "/tests", method = RequestMethod.POST) public ResponseEntity<TestResult> createTest(@RequestBody TestRequestDTO test) { log.debug("Creating new test for {} on endpoint {}", test.getServiceId(), test.getTestEndpoint()); Service service = null;/*from w ww. jav a2s . co m*/ // serviceId may have the form of <service_name>:<service_version> if (test.getServiceId().contains(":")) { String name = test.getServiceId().substring(0, test.getServiceId().indexOf(':')); String version = test.getServiceId().substring(test.getServiceId().indexOf(':') + 1); service = serviceRepository.findByNameAndVersion(name, version); } else { service = serviceRepository.findOne(test.getServiceId()); } TestRunnerType testRunner = TestRunnerType.valueOf(test.getRunnerType()); TestResult testResult = testService.launchTests(service, test.getTestEndpoint(), testRunner); return new ResponseEntity<TestResult>(testResult, HttpStatus.CREATED); }
From source file:com.netflix.genie.web.controllers.ApplicationRestController.java
/** * Create an Application.//from w ww.j av a2 s . c om * * @param app The application to create * @return The created application configuration * @throws GenieException For any error */ @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public ResponseEntity<Void> createApplication(@RequestBody final Application app) throws GenieException { log.debug("Called to create new application"); final String id = this.applicationService.createApplication(app); final HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation( ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(id).toUri()); return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED); }
From source file:gateway.controller.ServiceController.java
/** * Registers an external service with the Piazza Service Controller. * /*from w ww.ja v a 2 s . c o m*/ * @see http://pz-swagger.stage.geointservices.io/#!/Service/post_service * * @param service * The service to register. * @param user * The user submitting the request * @return The Service Id, or appropriate error. */ @RequestMapping(value = "/service", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) @ApiOperation(value = "Register new Service definition", notes = "Creates a new Service with the Piazza Service Controller; that can be invoked through Piazza jobs with Piazza data.", tags = "Service") @ApiResponses(value = { @ApiResponse(code = 201, message = "The Id of the newly created Service", response = ServiceIdResponse.class), @ApiResponse(code = 400, message = "Bad Request", response = ErrorResponse.class), @ApiResponse(code = 401, message = "Unauthorized", response = ErrorResponse.class), @ApiResponse(code = 500, message = "Internal Error", response = ErrorResponse.class) }) public ResponseEntity<PiazzaResponse> registerService( @ApiParam(value = "The metadata for the service. This includes the URL, parameters, inputs and outputs. It also includes other release metadata such as classification and availability.", required = true) @Valid @RequestBody Service service, Principal user) { try { // Log the request logger.log(String.format("User %s requested Service registration.", gatewayUtil.getPrincipalName(user)), PiazzaLogger.INFO); // Populate the authoring field in the Service Metadata if (service.getResourceMetadata() == null) { service.setResourceMetadata(new ResourceMetadata()); } service.getResourceMetadata().createdBy = gatewayUtil.getPrincipalName(user); service.getResourceMetadata().createdOn = (new DateTime()).toString(); // Create the Service Job to forward PiazzaJobRequest jobRequest = new PiazzaJobRequest(); jobRequest.createdBy = gatewayUtil.getPrincipalName(user); jobRequest.jobType = new RegisterServiceJob(service); // Proxy the request to the Service Controller try { return new ResponseEntity<PiazzaResponse>( restTemplate.postForEntity(String.format("%s/%s", SERVICECONTROLLER_URL, "registerService"), jobRequest, ServiceIdResponse.class).getBody(), HttpStatus.CREATED); } catch (HttpClientErrorException | HttpServerErrorException hee) { LOGGER.error("Error Registering Service", hee); return new ResponseEntity<PiazzaResponse>( gatewayUtil.getErrorResponse(hee.getResponseBodyAsString()), hee.getStatusCode()); } } catch (Exception exception) { String error = String.format("Error Registering Service by user %s: %s", gatewayUtil.getPrincipalName(user), exception.getMessage()); LOGGER.error(error, exception); logger.log(error, PiazzaLogger.ERROR); return new ResponseEntity<PiazzaResponse>(new ErrorResponse(error, "Gateway"), HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:tv.arte.resteventapi.web.controllers.EventsController.java
/** * Create an event and returns it (additional infos included) * /* www . j av a2s .c o m*/ * @param baseEventRequestParam A set of params * @return The created evet * @throws RestEventApiValidationException */ @RequestMapping(produces = { RestEventApiMediaType.APPLICATION_VND_API_JSON_VALUE }, consumes = { RestEventApiMediaType.APPLICATION_VND_API_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }, method = { RequestMethod.POST }) @ResponseStatus(HttpStatus.CREATED) @HrefedLocationHeader public EventResourceResponse createEvent( @RequestBody @Valid RestEventPostRequestParam restEventPostRequestParam, HttpServletResponse response) throws RestEventApiValidationException { RestEvent restEvent = eventService.createRestEvent(restEventPostRequestParam); return new EventResourceResponse(restEvent); }
From source file:com.netflix.genie.web.controllers.ClusterRestController.java
/** * Create cluster configuration.//from w ww. j av a2 s . c o m * * @param cluster contains the cluster information to create * @return The created cluster * @throws GenieException For any error */ @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public ResponseEntity<Void> createCluster(@RequestBody final Cluster cluster) throws GenieException { log.debug("Called to create new cluster {}", cluster); final String id = this.clusterService.createCluster(cluster); final HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation( ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(id).toUri()); return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED); }
From source file:com.msyla.usergreeter.user.web.UserPreferenceResource.java
@RequestMapping(value = "/{id}", method = RequestMethod.PUT) public ResponseEntity<UserPreferenceDto> update(@PathVariable Long id, @RequestBody @Valid UserPreferenceDto dto, UriComponentsBuilder builder) { UserPreferenceDto updatedDto = service.update(id, dto); Link link = ControllerLinkBuilder.linkTo(UserPreferenceResource.class).slash(updatedDto.getKey()) .withSelfRel();//from ww w. j a va2 s. c o m updatedDto.add(link); HttpHeaders headers = new HttpHeaders(); headers.setLocation(builder.path("/api/user/preferences/{id}").buildAndExpand(updatedDto.getKey()).toUri()); return new ResponseEntity<>(updatedDto, headers, HttpStatus.CREATED); }