List of usage examples for org.springframework.http HttpStatus CONFLICT
HttpStatus CONFLICT
To view the source code for org.springframework.http HttpStatus CONFLICT.
Click Source Link
From source file:eu.freme.broker.eservices.FremeNER.java
private ResponseEntity<String> callBackend(String uri, HttpMethod method, String body) { RestTemplate restTemplate = new RestTemplate(); try {/*from w w w . j a v a 2s . c om*/ if (body == null) { return restTemplate.exchange(new URI(uri), method, null, String.class); } else { ResponseEntity<String> response = restTemplate.exchange(new URI(uri), method, new HttpEntity<String>(body), String.class); if (response.getStatusCode() == HttpStatus.CONFLICT) { throw new eu.freme.broker.exception.BadRequestException( "Dataset with this name already existis and it cannot be created."); } else { return response; } // return restTemplate.exchange(new URI(uri), method, new HttpEntity<String>(body), String.class); } } catch (HttpClientErrorException rce) { if (rce.getStatusCode() == HttpStatus.CONFLICT) { throw new eu.freme.broker.exception.BadRequestException( "Dataset with this name already existis and it cannot be created."); } else { throw new eu.freme.broker.exception.ExternalServiceFailedException(rce.getMessage()); } } catch (RestClientException rce) { logger.error("failed", rce); throw new eu.freme.broker.exception.ExternalServiceFailedException(rce.getMessage()); } catch (Exception e) { logger.error("failed", e); return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:org.cloudfoundry.identity.uaa.oauth.ClientAdminEndpointsTests.java
@Test public void testHandleClientAlreadyExists() throws Exception { ResponseEntity<InvalidClientDetailsException> result = endpoints .handleClientAlreadyExists(new ClientAlreadyExistsException("No such client: foo")); assertEquals(HttpStatus.CONFLICT, result.getStatusCode()); }
From source file:ca.intelliware.ihtsdo.mlds.web.rest.ApplicationResource.java
@RequestMapping(value = Routes.APPLICATION, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @RolesAllowed({ AuthoritiesConstants.USER, AuthoritiesConstants.STAFF, AuthoritiesConstants.ADMIN }) @Transactional//from w w w. j a v a 2 s. co m @Timed public ResponseEntity<?> updateApplication(@PathVariable long applicationId, @RequestBody ObjectNode requestBody) throws IOException { Application original = applicationRepository.findOne(applicationId); Application updatedApplication = constructUpdatedApplication(requestBody, original); try { applicationService.doUpdate(original, updatedApplication); applicationAuditEvents.logApprovalStateChange(updatedApplication); } catch (IllegalArgumentException e) { return new ResponseEntity<String>("Forbidden change to application:" + e.getMessage(), HttpStatus.CONFLICT); } return new ResponseEntity<Application>(original, HttpStatus.OK); }
From source file:com.orange.ngsi2.server.Ngsi2BaseController.java
@ExceptionHandler({ ConflictingEntitiesException.class }) public ResponseEntity<Object> conflictingEntities(ConflictingEntitiesException exception, HttpServletRequest request) {//from ww w .j av a2 s. c om logger.error("ConflictingEntities: {}", exception.getMessage()); HttpStatus httpStatus = HttpStatus.CONFLICT; if (request.getHeader("Accept").contains(MediaType.TEXT_PLAIN_VALUE)) { return new ResponseEntity<>(exception.getError().toString(), httpStatus); } return new ResponseEntity<>(exception.getError(), httpStatus); }
From source file:com.mocktpo.api.LicenseApiController.java
@RequestMapping(value = "/api/licenses/require", method = RequestMethod.POST) public ResponseEntity<Void> require(@RequestBody RequireActivationVo vo) { logger.debug("{}.{}() accessed.", this.getClass().getSimpleName(), Thread.currentThread().getStackTrace()[1].getMethodName()); String email = vo.getEmail(); String hardware = vo.getHardware(); List<License> lz = service.findByEmail(email); if (null != lz && lz.size() > 0) { // email exists, filled in by agents previously. License lic = lz.get(0);// w w w . j a v a 2 s .c om String licensedHardware = lic.getHardware(); if (StringUtils.isEmpty(licensedHardware)) { // hardware remains blank lic.setHardware(hardware); Date date = new Date(); lic.setDateUpdated(date); service.update(lic); EmailUtils.sendActivationCode(lic); return ResponseEntity.ok().build(); } else { if (licensedHardware.equals(hardware)) { // same hardware registered EmailUtils.sendActivationCode(lic); return ResponseEntity.ok().build(); } else { return ResponseEntity.status(HttpStatus.CONFLICT).build(); // different hardware registered } } } else { return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); // email never exists } }
From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTest.java
private void testForConflicts(final String id, final List<String> commandArgs, final List<ClusterCriteria> clusterCriteriaList, final Set<String> commandCriteria) throws Exception { final JobRequest jobConflictRequest = new JobRequest.Builder(JOB_NAME, JOB_USER, JOB_VERSION, clusterCriteriaList, commandCriteria).withId(id).withCommandArgs(commandArgs) .withDisableLogArchival(true).build(); RestAssured.given(this.getRequestSpecification()).contentType(MediaType.APPLICATION_JSON_VALUE) .body(GenieObjectMapper.getMapper().writeValueAsBytes(jobConflictRequest)).when().port(this.port) .post(JOBS_API).then().statusCode(Matchers.is(HttpStatus.CONFLICT.value())); }
From source file:com.vmware.appfactory.common.base.AbstractController.java
/** * Convert all thrown AfConflictException exceptions * into a 409 error code./*from ww w . ja v a 2s.c om*/ * @param ex * @return */ @ResponseBody @ResponseStatus(HttpStatus.CONFLICT) @ExceptionHandler(AfConflictException.class) public String handleConflictException(Exception ex) { _log.error("Resource conflict!", ex); return ex.getMessage(); }
From source file:com.vmware.appfactory.workpool.WorkpoolClientService.java
/** * Used to create a workpool. This call can create workpools of Full, * linked, Custom types./*from w ww .j ava 2s . co m*/ * * NOTE: The created workpool or the Id is not returned as its not needed * at this point in time. If needed @see VmImage.createVmImage() * * @param workpool * @return * @throws WpException, AfConflictException */ public Long createWorkpool(Workpool workpool) throws WpException, AfConflictException { try { // This method does not return the URI uri = _rest.postForLocation(baseUrl() + "/workpools", workpool); return Long.valueOf(AfUtil.extractLastURIToken(uri)); } catch (HttpStatusCodeException ex) { if (ex.getStatusCode() == HttpStatus.CONFLICT) { throw new AfConflictException("CONFLICT_NAME: " + ex.getMessage()); } throw new WpException("Workpool cannot be created: " + ex.getMessage()); } catch (RestClientException e) { throw new WpException("Workpool cannot be created: " + e.getMessage()); } }
From source file:com.vmware.appfactory.workpool.WorkpoolClientService.java
/** * Used to update a VM Image. Name field can be updated. * * @param workpool//from w w w . j av a 2s . c om * @throws WpException */ public void updateWorkpool(Workpool workpool) throws WpException, AfNotFoundException, AfConflictException { Long id = workpool.getId(); try { _rest.put(baseUrl() + "/workpools/{id}", workpool, id); } catch (HttpStatusCodeException ex) { if (ex.getStatusCode() == HttpStatus.NOT_FOUND) { throw new AfNotFoundException("NOT_FOUND: " + ex.getMessage()); } else if (ex.getStatusCode() == HttpStatus.CONFLICT) { throw new AfConflictException("CONFLICT_NAME: " + ex.getMessage()); } throw new WpException("Workpool cannot be updated: " + ex.getMessage()); } catch (RestClientException e) { throw new WpException("Workpool cannot be updated: " + e.getMessage()); } }
From source file:edu.isi.misd.scanner.network.registry.web.controller.BaseController.java
@ExceptionHandler({ ConflictException.class, DataIntegrityViolationException.class }) @ResponseBody//w w w . ja v a2 s .com @ResponseStatus(value = HttpStatus.CONFLICT) public ErrorMessage handleConflictException(Exception e) { return new ErrorMessage(HttpStatus.CONFLICT.value(), HttpStatus.CONFLICT.getReasonPhrase(), e.getLocalizedMessage()); }