Java Code Examples for org.springframework.http.HttpStatus#CREATED

The following examples show how to use org.springframework.http.HttpStatus#CREATED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserController.java    From SpringCloud-Shop with Apache License 2.0 6 votes vote down vote up
@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public ResponseEntity<User> save(User user, UriComponentsBuilder ucb) {
    ServiceInstance instance = client.getLocalServiceInstance();
    logger.info("/user, host:" + instance.getHost() + ", serviceId:" + instance.getServiceId() + ",user id:" + user.getId() + ",user name:" + user.getName());

    User saved = userService.save(user);

    HttpHeaders headers = new HttpHeaders();
    URI locationUri = ucb.path("/login/")
            .path(String.valueOf(saved.getId()))
            .build()
            .toUri();
    headers.setLocation(locationUri);

    ResponseEntity<User> responseEntity = new ResponseEntity<>(saved, headers, HttpStatus.CREATED);

    return responseEntity;

}
 
Example 2
Source File: UserController.java    From QuizZz with MIT License 5 votes vote down vote up
@RequestMapping(value = "/registration", method = RequestMethod.POST)
@PreAuthorize("permitAll")
public ResponseEntity<User> signUp(@Valid User user, BindingResult result) {

	RestVerifier.verifyModelResult(result);
	User newUser = registrationService.startRegistration(user);

	if (registrationService.isRegistrationCompleted(newUser)) {
		return new ResponseEntity<User>(newUser, HttpStatus.CREATED);
	} else {
		return new ResponseEntity<User>(newUser, HttpStatus.OK);
	}
}
 
Example 3
Source File: SystemStoreController.java    From yshopmall with Apache License 2.0 5 votes vote down vote up
@PostMapping(value = "/getL")
@Log("获取经纬度")
@ApiOperation("获取经纬度")
@PreAuthorize("@el.check('yxSystemStore:getl')")
public ResponseEntity<Object> create(@Validated @RequestBody String jsonStr){
    String key = RedisUtil.get(ShopKeyUtils.getTengXunMapKey());
    if(StrUtil.isBlank(key)) throw  new BadRequestException("请先配置腾讯地图key");
    JSONObject jsonObject = JSON.parseObject(jsonStr);
    String addr = jsonObject.getString("addr");
    String url = StrUtil.format("?address={}&key={}",addr,key);
    String json = HttpUtil.get(ShopConstants.QQ_MAP_URL+url);
    return new ResponseEntity<>(json,HttpStatus.CREATED);
}
 
Example 4
Source File: LocationFacade.java    From spring-rest-server with GNU Lesser General Public License v3.0 5 votes vote down vote up
@RequestMapping(value = "/ticket/{ticketId}/scan/{locationId}", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public LocationVO addLocationScan(@PathVariable long ticketId, @PathVariable long locationId) {
    Ticket ticket = ticketService.get(ticketId);
    Location location = ticketService.addLocationScan(ticket, locationId);
    return mappingService.map(location, LocationVO.class);
}
 
Example 5
Source File: UserController.java    From bearchoke with Apache License 2.0 5 votes vote down vote up
/**
 * Register a user with the system
 *
 * @param user user
 * @return
 */
@RequestMapping(value = "/api/user/register", method = {RequestMethod.POST}, produces = ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON_VALUE, consumes = ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public void register(@RequestBody RegisterUserDto user) {
    // attach default role to user
    user.setRoles(new String[]{PlatformConstants.DEFAULT_USER_ROLE});

    if (log.isDebugEnabled()) {
        log.debug(user.toString());
    }

    commandBus.dispatch(new GenericCommandMessage<>(
                    new RegisterUserCommand(new UserIdentifier(), user))
    );
}
 
Example 6
Source File: InvtsController.java    From maintain with MIT License 5 votes vote down vote up
@RequestMapping("download")
public ResponseEntity<byte[]> download() throws IOException {
	HttpHeaders headers = new HttpHeaders();
	headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
	headers.setContentDispositionFormData("attachment", "README.md");
	File file = new File("README.md");
	System.out.println(file.getAbsolutePath());
	System.out.println(this.getClass().getResource(""));
	return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED);
}
 
Example 7
Source File: ResourcesController.java    From multi-tenant-rest-api with MIT License 5 votes vote down vote up
@PreAuthorize("@roleChecker.hasValidRole(#principal)")
@RequestMapping(value="/company", method=RequestMethod.POST, produces=MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<CompanyDTO> createCompany(
		Principal principal,
		@RequestBody CompanyDTO companyDTO) {
	
	// Check for SUPERADMIN role
	// RoleChecker.hasValidRole(principal);
	
	companyDTO = companyService.create(companyDTO);
	
	return new ResponseEntity<CompanyDTO>(companyDTO, HttpStatus.CREATED);
}
 
Example 8
Source File: TagsController.java    From restdocs-raml with MIT License 5 votes vote down vote up
@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(method = RequestMethod.POST)
HttpHeaders create(@RequestBody TagInput tagInput) {
	Tag tag = new Tag();
	tag.setName(tagInput.getName());

	this.repository.save(tag);

	HttpHeaders httpHeaders = new HttpHeaders();
	httpHeaders.setLocation(linkTo(TagsController.class).slash(tag.getId()).toUri());

	return httpHeaders;
}
 
Example 9
Source File: AnswerController.java    From QuizZz with MIT License 5 votes vote down vote up
@RequestMapping(value = "", method = RequestMethod.POST)
@PreAuthorize("isAuthenticated()")
@ResponseStatus(HttpStatus.CREATED)
public Answer save(@Valid Answer answer, BindingResult result, @RequestParam long question_id) {

	RestVerifier.verifyModelResult(result);

	Question question = questionService.find(question_id);
	return questionService.addAnswerToQuestion(answer, question);
}
 
Example 10
Source File: PostController.java    From Spring-Boot-Blog-REST-API with GNU Affero General Public License v3.0 5 votes vote down vote up
@PostMapping
@PreAuthorize("hasRole('USER')")
public ResponseEntity<PostResponse> addPost(@Valid @RequestBody PostRequest postRequest,
		@CurrentUser UserPrincipal currentUser) {
	PostResponse postResponse = postService.addPost(postRequest, currentUser);
	
	return new ResponseEntity<PostResponse>(postResponse, HttpStatus.CREATED);
}
 
Example 11
Source File: AuthenticationController.java    From cf-SpringBootTrader with Apache License 2.0 5 votes vote down vote up
/**
 * Logins in the user from the authentication request passed in body.
 * 
 * @param authenticationRequest The request with username and password.
 * @return HTTP status CREATED if successful.
 */
@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseStatus( HttpStatus.CREATED )
@ResponseBody
public Map<String, Object> login(@RequestBody AuthenticationRequest authenticationRequest) {
	logger.debug("AuthenticationController.login: login request for username: " + authenticationRequest.getUsername());
	Map<String, Object> authenticationResponse = this.service.login(authenticationRequest.getUsername(), authenticationRequest.getPassword());
	return authenticationResponse;// authToken and accountId;
}
 
Example 12
Source File: RegistrationController.java    From xxproject with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/user/registration", method = RequestMethod.POST)
@ResponseBody
public ApiError registerUserAccount(@Valid final UserDto accountDto, final HttpServletRequest request) {
    logger.info("Registering user account with information: {}", accountDto);

    final User registered = userService.registerNewUserAccount(accountDto);

    return new ApiError(HttpStatus.CREATED, "user successfully registered");
}
 
Example 13
Source File: ServletAnnotationControllerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/foo")
public ResponseEntity<String> foo(HttpEntity<byte[]> requestEntity) throws UnsupportedEncodingException {
	assertNotNull(requestEntity);
	assertEquals("MyValue", requestEntity.getHeaders().getFirst("MyRequestHeader"));
	String requestBody = new String(requestEntity.getBody(), "UTF-8");
	assertEquals("Hello World", requestBody);

	HttpHeaders responseHeaders = new HttpHeaders();
	responseHeaders.set("MyResponseHeader", "MyValue");
	return new ResponseEntity<String>(requestBody, responseHeaders, HttpStatus.CREATED);
}
 
Example 14
Source File: Controller.java    From journeyFromMonolithToMicroservices with MIT License 5 votes vote down vote up
@RequestMapping(value = "/reocurringPayment", method = RequestMethod.POST)
public ResponseEntity<String> createReocurringPayment(@RequestBody Map<String, Object> data){
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.add("content-type", MediaType.APPLICATION_JSON.toString());

    ResponseEntity<String> response;
    if (paymentGateway.createReocurringPayment((Integer)data.get("amount"))) {
        response = new ResponseEntity<>("{errors: []}", responseHeaders, HttpStatus.CREATED);
    } else {
        response = new ResponseEntity<>("{errors: [\"error1\", \"error2\"]}", responseHeaders, HttpStatus.BAD_REQUEST);
    }

    return response;
}
 
Example 15
Source File: KafkaController.java    From metron with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Creates a new Kafka topic")
@ApiResponses({
  @ApiResponse(message = "Returns saved Kafka topic", code = 200)
})
@RequestMapping(value = "/topic", method = RequestMethod.POST)
ResponseEntity<KafkaTopic> save(final @ApiParam(name = "topic", value = "Kafka topic", required = true) @RequestBody KafkaTopic topic) throws RestException {
  return new ResponseEntity<>(kafkaService.createTopic(topic), HttpStatus.CREATED);
}
 
Example 16
Source File: V1ArticleResource.java    From kaif with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "[article] Create an article with content",
    notes = "Create an article with content in specified zone")
@ResponseStatus(HttpStatus.CREATED)
@RequiredScope(ClientAppScope.ARTICLE)
@RequestMapping(value = "/speak", method = RequestMethod.PUT, consumes = {
    MediaType.APPLICATION_JSON_VALUE })
public V1ArticleDto speak(ClientAppUserAccessToken token, @Valid @RequestBody SpeakEntry entry) {
  return articleService.createSpeak(token, entry.zone, entry.title.trim(), entry.content.trim())
      .toV1Dto();
}
 
Example 17
Source File: DesignTacoController.java    From spring-in-action-5-samples with Apache License 2.0 4 votes vote down vote up
@PostMapping(consumes="application/json")
@ResponseStatus(HttpStatus.CREATED)
public Taco postTaco(@RequestBody Taco taco) {
  return tacoRepo.save(taco);
}
 
Example 18
Source File: AlbumController.java    From PhotoAlbum-api with MIT License 4 votes vote down vote up
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<?> createAlbum(@Valid @RequestBody AlbumRequest albumRequest) {
  return new ResponseEntity<>(this.albumService.createAlbum(albumRequest), HttpStatus.CREATED);
}
 
Example 19
Source File: UserResource.java    From Spring-5.0-By-Example with MIT License 4 votes vote down vote up
@PostMapping
public ResponseEntity<User> newUser(NewsRequest news){
  return new ResponseEntity<>(new User(), HttpStatus.CREATED);
}
 
Example 20
Source File: StreamDefinitionController.java    From spring-cloud-dataflow with Apache License 2.0 3 votes vote down vote up
/**
 * Create a new stream.
 *
 * @param name stream name
 * @param dsl DSL definition for stream
 * @param deploy if {@code true}, the stream is deployed upon creation (default is
 * {@code false})
 * @param description description of the stream definition
 * @return the created stream definition
 * @throws DuplicateStreamDefinitionException if a stream definition with the same name
 * already exists
 * @throws InvalidStreamDefinitionException if there errors in parsing the stream DSL,
 * resolving the name, or type of applications in the stream
 */
@RequestMapping(value = "", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public StreamDefinitionResource save(@RequestParam("name") String name, @RequestParam("definition") String dsl,
										@RequestParam(value = "description", defaultValue = "") String description,
										@RequestParam(value = "deploy", defaultValue = "false") boolean deploy) {
	StreamDefinition streamDefinition = this.streamService.createStream(name, dsl, description, deploy);
	return new Assembler(new PageImpl<>(Collections.singletonList(streamDefinition))).toModel(streamDefinition);
}