本文整理汇总了Java中org.springframework.http.HttpStatus.CONFLICT属性的典型用法代码示例。如果您正苦于以下问题:Java HttpStatus.CONFLICT属性的具体用法?Java HttpStatus.CONFLICT怎么用?Java HttpStatus.CONFLICT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.springframework.http.HttpStatus
的用法示例。
在下文中一共展示了HttpStatus.CONFLICT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
public Topic create(String name) {
if (repository.findByName(name).isPresent()) {
throw new HttpClientErrorException(HttpStatus.CONFLICT, name + " 이미 등록된 태그 입니다.");
}
return repository.save(new Topic(name));
}
示例2: deleteImageResource
@GetMapping(path="/deleteImage")
@ResponseBody
public ResponseEntity<Object> deleteImageResource (@RequestParam String email,
@RequestParam String fileName) {
ResponseEntity response = null;
User user;
if(email.equals("") || email == null){
response = new ResponseEntity<>("Email must not be empty", HttpStatus.NOT_ACCEPTABLE);
}
if(fileName.equals("") || fileName == null){
response = new ResponseEntity<>("File name must not be empty", HttpStatus.NOT_ACCEPTABLE);
}
user = userRepository.findByEmail(email);
if(user == null){
response = new ResponseEntity<>("User not found with provided email", HttpStatus.CONFLICT);
}
try{
imageRepository.deleteByFileName(fileName);
}catch(Exception e){
response = new ResponseEntity<>("Image not found", HttpStatus.BAD_REQUEST);
}
return response;
}
示例3: createCustomer
@SuppressWarnings({ "unchecked", "rawtypes" })
@RequestMapping(value = "/customer/", method = RequestMethod.POST)
public ResponseEntity<?> createCustomer(@RequestBody Customer customer, UriComponentsBuilder ucBuilder) {
logger.info("Creating Customer : {}", customer);
System.out.println(customerService.customerExist(customer));
if (customerService.customerExist(customer)) {
logger.error("Unable to create a customer with username {}", customer.getUsername());
return new ResponseEntity(new CustomErrorType("A customer with username " +
customer.getUsername() + " already exists."),HttpStatus.CONFLICT);
}
Customer currentCustomer = customerService.createCustomer(customer);
Long currentCustomerId = currentCustomer.getCustomerId();
JSONObject customerInfo = new JSONObject();
customerInfo.put("customerId", currentCustomerId);
HttpHeaders headers = new HttpHeaders();
headers.setLocation(ucBuilder.path("/api/customer/{customerId").buildAndExpand(customer.getCustomerId()).toUri());;
return new ResponseEntity<JSONObject>(customerInfo, HttpStatus.CREATED);
}
示例4: handlePackageDeleteException
@ExceptionHandler(PackageDeleteException.class)
public ResponseEntity<Map<String, String>> handlePackageDeleteException(PackageDeleteException error) {
// TODO investigate why SkipperErrorAttributes is not being invoked.
Map<String, String> map = new HashMap<>();
map.put("exception", error.getClass().getName());
map.put("message", error.getMessage());
return new ResponseEntity<Map<String, String>>(map, HttpStatus.CONFLICT);
}
示例5: handleDataIntegrityViolationException
@Loggable
@ResponseStatus(code = HttpStatus.CONFLICT)
@ExceptionHandler(DataIntegrityViolationException.class)
public ErrorDto handleDataIntegrityViolationException(DataIntegrityViolationException ex) {
if (uniqueConstraintList != null && ex.getCause() != null && ex.getCause() instanceof ConstraintViolationException) {
Optional<DataUniqueConstraint> matchCons = uniqueConstraintList.stream().filter((cons) ->
((ConstraintViolationException) ex.getCause()).getConstraintName().contains(cons.getConstraintName())).findFirst();
if (matchCons.isPresent()) {
return ErrorDto.builder()
.errorCode(ErrorCodes.DATA_VALIDATION)
.error(ValidationErrorDto.builder()
.errorCode("UNIQUE")
.fieldName(Arrays.stream(matchCons.get().getFieldNames())
.map(Object::toString)
.collect(Collectors.joining(", ")))
.build())
.message(ex.getLocalizedMessage())
.build();
}
}
return ErrorDto.builder()
.errorCode(ErrorCodes.UNKNOWN)
.message(ex.getLocalizedMessage())
.build();
}
示例6: register
/**
* Authenticates an user with an given user and password. Returns Unauthorized,
* when username or password is not correct.
*
* @param username
* Unique Username that is supposed to be set
* @param password
* Password that is supposed to be set
* @return User and Password or Unauthorized
*/
@RequestMapping(value = "/register", method = RequestMethod.POST)
public Object register(@RequestBody AuthenticationRequestBody body) {
String username = body.username;
char[] password = body.password.toCharArray();
log("New User registration ( username:'" + username + "' , password: '" + String.valueOf(password) + "' )");
ServiceBundle service = new ServiceBundle();
Optional<User> userOpt = service.registerUser(username, password);
if (userOpt.isPresent()) {
return userOpt.get();
} else {
return new ResponseEntity<String>(
"The registration failed. Does there maybe exist an user with the same Name?", HttpStatus.CONFLICT);
}
}
示例7: handleDataAccessExceptions
@ExceptionHandler(DataAccessException.class)
@ResponseStatus(value=HttpStatus.CONFLICT)
public ModelAndView handleDataAccessExceptions(HttpServletRequest request, DataAccessException ex) {
logger.warn("DataAccessException: " + request.getRequestURL(), ex);
ModelAndView mav = new ModelAndView();
mav.setViewName("error");
return mav;
}
示例8: createBot
/**
* Creates a new Bot configuration.
*
* @param user the authenticated user.
* @param botConfig the new Bot config.
* @return 201 'Created' HTTP status code if create successful, some other HTTP status code otherwise.
*/
@PreAuthorize("hasRole('ADMIN')")
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<?> createBot(@AuthenticationPrincipal User user, @RequestBody BotConfig botConfig) {
LOG.info("POST " + CONFIG_ENDPOINT_BASE_URI + " - createBot()"); // - caller: " + user.getUsername());
LOG.info("Request: " + botConfig);
final BotConfig createdConfig = botConfigService.createBotConfig(botConfig);
return createdConfig == null
? new ResponseEntity<>(HttpStatus.CONFLICT)
: buildResponseEntity(createdConfig, HttpStatus.CREATED);
}
示例9: handleInvalidMetadataDocumentState
@ResponseStatus(HttpStatus.CONFLICT)
@ExceptionHandler(InvalidMetadataDocumentStateException.class)
public @ResponseBody
ExceptionInfo handleInvalidMetadataDocumentState(HttpServletRequest request, Exception e) {
getLog().warn(String.format("Attempt a failed metadata document state transition at '%s'; " +
"this will generate a CONFLICT RESPONSE",
request.getRequestURL().toString()));
getLog().debug("Handling InvalidMetadataDocumentStateException and returning CONFLICT response", e);
return new ExceptionInfo(request.getRequestURL().toString(), e.getLocalizedMessage());
}
示例10: createUser
@RequestMapping(value = "/users", method = RequestMethod.POST)
public ResponseEntity<?> createUser(@RequestBody User user, UriComponentsBuilder ucBuilder) {
logger.info("Creating User : {}", user);
if (userService.isUserExist(user)) {
logger.error("Unable to create. A User with name {} already exist", user.getUsername());
return new ResponseEntity(new CustomErrorType("Unable to create. A User with name " +
user.getUsername() + " already exist."),HttpStatus.CONFLICT);
}
userService.addUser(user);
HttpHeaders headers = new HttpHeaders();
headers.setLocation(ucBuilder.path("/api/user/{id}").buildAndExpand(user.getId()).toUri());
return new ResponseEntity<String>(headers, HttpStatus.CREATED);
}
示例11: processConcurrencyError
@ExceptionHandler(ConcurrencyFailureException.class)
@ResponseStatus(HttpStatus.CONFLICT)
@ResponseBody
public ErrorVM processConcurrencyError(ConcurrencyFailureException ex) {
return new ErrorVM(ErrorConstants.ERR_CONCURRENCY_FAILURE);
}
示例12: handleDuplicateEntityException
@ExceptionHandler(value = {DuplicateEntityException.class})
@ResponseStatus(HttpStatus.CONFLICT)
public Resource handleDuplicateEntityException(DuplicateEntityException ex) {
return new Resource(ex.getMessage());
}
示例13: exception
@CrossOrigin
@ResponseStatus(HttpStatus.CONFLICT)
@ExceptionHandler(UserProjectException.class)
public MessageDTO exception(UserProjectException e) {
return new MessageDTO(e.getMessage());
}
示例14: userExists
@ExceptionHandler(UserAlreadyExistsException.class)
@ResponseStatus(HttpStatus.CONFLICT)
@ResponseBody
public ErrorInfo userExists(HttpServletRequest req, Exception ex) {
return new ErrorInfo(req.getRequestURL().toString(), ex, HttpStatus.CONFLICT.value());
}
示例15: processConcurencyError
@ExceptionHandler(ConcurrencyFailureException.class)
@ResponseStatus(HttpStatus.CONFLICT)
@ResponseBody
public ErrorDTO processConcurencyError(ConcurrencyFailureException ex) {
return new ErrorDTO(ErrorConstants.ERR_CONCURRENCY_FAILURE);
}