List of usage examples for org.springframework.http HttpStatus UNPROCESSABLE_ENTITY
HttpStatus UNPROCESSABLE_ENTITY
To view the source code for org.springframework.http HttpStatus UNPROCESSABLE_ENTITY.
Click Source Link
From source file:org.openbaton.nfvo.api.exceptions.GlobalExceptionHandler.java
@ExceptionHandler({ BadRequestException.class, BadFormatException.class, NetworkServiceIntegrityException.class, WrongStatusException.class, UnrecognizedPropertyException.class, VimException.class, CyclicDependenciesException.class, WrongAction.class, PasswordWeakException.class }) @ResponseStatus(value = HttpStatus.BAD_REQUEST) protected ResponseEntity<Object> handleInvalidRequest(Exception e, WebRequest request) { if (log.isDebugEnabled()) { log.error("Exception was thrown -> Return message: " + e.getMessage(), e); } else {// w w w . j a va 2s . c o m log.error("Exception was thrown -> Return message: " + e.getMessage()); } ExceptionResource exc = new ExceptionResource("Bad Request", e.getMessage()); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); return handleExceptionInternal(e, exc, headers, HttpStatus.UNPROCESSABLE_ENTITY, request); }
From source file:org.smigo.user.UserController.java
@RequestMapping(value = "/rest/user", method = RequestMethod.POST) @ResponseBody//from w w w. j a v a 2 s. c o m public List<ObjectError> addUser(@RequestBody @Valid UserAdd user, BindingResult result, HttpServletResponse response, Locale locale) { log.info("Create user: " + user); if (result.hasErrors()) { log.warn("Create user failed. Username:" + user.getUsername() + " Errors:" + StringUtils.arrayToDelimitedString(result.getAllErrors().toArray(), ", ")); response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value()); return result.getAllErrors(); } userHandler.createUser(user, locale); return Collections.emptyList(); }
From source file:com.ge.predix.acs.commons.web.ResponseEntityBuilder.java
/** * Response entity usually to reflect semantically invalid input data. Creates a typed ResponseEntity with HTTP * status code 422 with no response payload. * * @return The corresponding ResponseEntity *//*from w w w . j a va2 s . c o m*/ public static ResponseEntity<Void> unprocessable() { return new ResponseEntity<Void>(HttpStatus.UNPROCESSABLE_ENTITY); }
From source file:org.venice.piazza.servicecontroller.messaging.handlers.UpdateServiceHandler.java
/** * Handler for the RegisterServiceJob that was submitted. Stores the metadata in MongoDB * @see org.venice.piazza.servicecontroller.messaging.handlers.Handler#handle(model.job.PiazzaJobType) *//*from www .j av a 2s.com*/ public ResponseEntity<String> handle(PiazzaJobType jobRequest) { LOGGER.debug("Updating a service"); UpdateServiceJob job = (UpdateServiceJob) jobRequest; if (job != null) { // Get the ResourceMetadata Service sMetadata = job.data; LOGGER.info("serviceMetadata received is " + sMetadata); coreLogger.log("serviceMetadata received is " + sMetadata, Severity.INFORMATIONAL); String result = handle(sMetadata); if (result.length() > 0) { String jobId = job.getJobId(); // TODO Use the result, send a message with the resource Id and jobId ArrayList<String> resultList = new ArrayList<>(); resultList.add(jobId); resultList.add(sMetadata.getServiceId()); return new ResponseEntity<String>(resultList.toString(), HttpStatus.OK); } else { coreLogger.log("No result response from the handler, something went wrong", Severity.ERROR); return new ResponseEntity<String>("UpdateServiceHandler handle didn't work", HttpStatus.UNPROCESSABLE_ENTITY); } } else { coreLogger.log("A null PiazzaJobRequest was passed in. Returning null", Severity.ERROR); return new ResponseEntity<String>("A Null PiazzaJobRequest was received", HttpStatus.BAD_REQUEST); } }
From source file:app.api.swagger.SwaggerConfig.java
private List<ResponseMessage> defaultHttpResponses() { final List<ResponseMessage> results = new ArrayList<ResponseMessage>(); results.add(response(HttpStatus.FORBIDDEN, null)); results.add(response(HttpStatus.UNAUTHORIZED, null)); results.add(response(HttpStatus.BAD_REQUEST, null)); results.add(response(HttpStatus.UNPROCESSABLE_ENTITY, ERROR_MODEL)); return results; }
From source file:com.ge.predix.acs.service.policy.admin.PolicyManagementController.java
@ApiOperation(value = "Creates/Updates a policy set for the given zone.", tags = { "Policy Set Management" }) @ApiResponses(value = {//from w w w . j av a 2 s .co m @ApiResponse(code = 201, message = "Policy set creation successful. Policy set URI is returned in 'Location' header."), }) @RequestMapping(method = PUT, value = POLICY_SET_URL, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<?> createPolicySet(@RequestBody final PolicySet policySet, @PathVariable("policySetId") final String policySetId) { validatePolicyIdOrFail(policySet, policySetId); try { this.service.upsertPolicySet(policySet); URI policySetUri = UriTemplateUtils.expand(POLICY_SET_URL, "policySetId:" + policySet.getName()); return created(policySetUri.getPath()); } catch (PolicyManagementException e) { throw new RestApiException(HttpStatus.UNPROCESSABLE_ENTITY, e.getMessage(), e); } }
From source file:org.smigo.species.SpeciesController.java
@PreAuthorize("isAuthenticated()") @RequestMapping(value = "/rest/species/{id:\\d+}", method = RequestMethod.PUT) @ResponseBody// w w w. j a va2s. c om public Object updateSpecies(@Valid @RequestBody Species species, BindingResult result, @PathVariable int id, @AuthenticationPrincipal AuthenticatedUser user, HttpServletResponse response, Locale locale) { log.info("Updating species. Species:" + species); if (result.hasErrors()) { response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value()); return result.getAllErrors(); } Review review = speciesHandler.updateSpecies(id, species, user); if (review == Review.MODERATOR) { response.setStatus(HttpStatus.ACCEPTED.value()); } return speciesHandler.getSpecies(id); }
From source file:org.smigo.species.vernacular.VernacularController.java
@PreAuthorize("isAuthenticated()") @RequestMapping(value = "/rest/vernacular/{id:\\d+}", method = RequestMethod.PUT) @ResponseBody//from w ww . j a v a 2 s. c om public Object updateVernacular(@Valid @RequestBody Vernacular vernacular, BindingResult result, @PathVariable int id, @AuthenticationPrincipal AuthenticatedUser user, Locale locale, HttpServletResponse response) { log.info("Updating vernacular:" + vernacular); if (result.hasErrors()) { response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value()); return result.getAllErrors(); } Review review = vernacularHandler.updateVernacular(id, vernacular, user, locale); if (review == Review.MODERATOR) { response.setStatus(HttpStatus.ACCEPTED.value()); } return null; }
From source file:io.github.microcks.web.DynamicMockRestController.java
@RequestMapping(value = "/{service}/{version}/{resource}", method = RequestMethod.POST) public ResponseEntity<String> createResource(@PathVariable("service") String serviceName, @PathVariable("version") String version, @PathVariable("resource") String resource, @RequestParam(value = "delay", required = false) Long delay, @RequestBody(required = true) String body, HttpServletRequest request) {//from w w w. j a v a2 s . com log.debug("Creating a new resource '{}' for service '{}-{}'", resource, serviceName, version); long startTime = System.currentTimeMillis(); MockContext mockContext = getMockContext(serviceName, version, "POST /" + resource); if (mockContext != null) { Document document = null; GenericResource genericResource = null; try { // Try parsing body payload that should be json. document = Document.parse(body); // Now create a generic resource. genericResource = new GenericResource(); genericResource.setServiceId(mockContext.service.getId()); genericResource.setPayload(document); genericResource = genericResourceRepository.save(genericResource); } catch (JsonParseException jpe) { // Return a 422 code : unprocessable entity. return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY); } // Append id and wait if specified before returning. document.append(ID_FIELD, genericResource.getId()); waitForDelay(startTime, delay, mockContext); return new ResponseEntity<>(document.toJson(), HttpStatus.CREATED); } // Return a 400 code : bad request. return new ResponseEntity<>(HttpStatus.BAD_REQUEST); }
From source file:de.fhg.fokus.nubomedia.paas.VNFRServiceImpl.java
/** * Registers a new App to the VNFR with a specific VNFR ID * /*ww w . ja va 2s.c o m*/ * @param externalAppId - application identifier * @param points - capacity */ public ApplicationRecord registerApplication(String externalAppId, int points) throws NotEnoughResourcesException { try { if (serviceProfile == null) { logger.info("Service Profile not set. make sure the VNFR_ID, VNFM_IP and VNFM_PORT are available "); return null; } String URL = serviceProfile.getServiceApiUrl(); ApplicationRecordBody bodyObj = new ApplicationRecordBody(externalAppId, points); Gson mapper = new GsonBuilder().create(); String body = mapper.toJson(bodyObj, ApplicationRecordBody.class); logger.info("registering new application: \nURL: " + URL + "\n + " + body); HttpHeaders creationHeader = new HttpHeaders(); creationHeader.add("Accept", "application/json"); creationHeader.add("Content-type", "application/json"); HttpEntity<String> registerEntity = new HttpEntity<String>(body, creationHeader); ResponseEntity response = restTemplate.exchange(URL, HttpMethod.POST, registerEntity, String.class); logger.info("response from VNFM " + response); HttpStatus status = response.getStatusCode(); if (status.equals(HttpStatus.CREATED) || status.equals(HttpStatus.OK)) { logger.info("Deployment status: " + status + " response: " + response); ApplicationRecord responseBody = mapper.fromJson((String) response.getBody(), ApplicationRecord.class); logger.info("returned object " + responseBody.toString()); return responseBody; } else if (status.equals(HttpStatus.UNPROCESSABLE_ENTITY)) { throw new NotEnoughResourcesException("Not enough resource " + response.getBody()); } } catch (NotEnoughResourcesException e) { logger.error(e.getMessage()); } catch (RestClientException e) { logger.error("Error registering application to VNFR - " + e.getMessage()); } return null; }