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:com.ge.predix.test.utils.PolicyHelper.java
public CreatePolicyStatus createPolicySet(final String policyFile, final RestTemplate restTemplate, final HttpHeaders headers) { PolicySet policySet;/*from w ww . j a v a 2s. com*/ try { policySet = new ObjectMapper().readValue(new File(policyFile), PolicySet.class); String policyName = policySet.getName(); restTemplate.put(zoneHelper.getAcsBaseURL() + ACS_POLICY_SET_API_PATH + policyName, new HttpEntity<>(policySet, headers)); return CreatePolicyStatus.SUCCESS; } catch (IOException e) { return CreatePolicyStatus.JSON_ERROR; } catch (HttpClientErrorException httpException) { return httpException.getStatusCode() != null && httpException.getStatusCode().equals(HttpStatus.UNPROCESSABLE_ENTITY) ? CreatePolicyStatus.INVALID_POLICY_SET : CreatePolicyStatus.ACS_ERROR; } catch (RestClientException e) { return CreatePolicyStatus.ACS_ERROR; } }
From source file:org.venice.piazza.servicecontroller.messaging.handlers.RegisterServiceHandler.java
/** * Handler for the RegisterServiceJob that was submitted. Stores the metadata in MongoDB * // w ww .j a v a2 s . c o m * @see org.venice.piazza.servicecontroller.messaging.handlers.Handler#handle(model.job.PiazzaJobType) */ @Override public ResponseEntity<String> handle(PiazzaJobType jobRequest) { coreLogger.log("Registering a Service", Severity.INFORMATIONAL); RegisterServiceJob job = (RegisterServiceJob) jobRequest; if (job != null) { // Get the Service metadata Service serviceMetadata = job.data; coreLogger.log("serviceMetadata received is " + serviceMetadata, Severity.INFORMATIONAL); String result = handle(serviceMetadata); if (result.length() > 0) { String responseString = "{\"resourceId\":" + "\"" + result + "\"}"; coreLogger.log(String.format("Service registered %s", serviceMetadata.getServiceId()), Severity.INFORMATIONAL, new AuditElement("serviceController", "registeredExternalService", serviceMetadata.getServiceId())); return new ResponseEntity<String>(responseString, HttpStatus.OK); } else { coreLogger.log("No result response from the handler, something went wrong", Severity.ERROR); coreLogger.log( String.format("The service was NOT registered id %s", serviceMetadata.getServiceId()), Severity.ERROR, new AuditElement("serviceController", "registerServiceError", serviceMetadata.getServiceId())); return new ResponseEntity<String>("RegisterServiceHandler handle didn't work", HttpStatus.UNPROCESSABLE_ENTITY); } } else { coreLogger.log("No RegisterServiceJob", Severity.ERROR); return new ResponseEntity<String>("No RegisterServiceJob", HttpStatus.BAD_REQUEST); } }
From source file:org.cloudfoundry.identity.uaa.login.AccountsController.java
@RequestMapping(value = "/verify_user", method = GET) public String verifyUser(Model model, @RequestParam("code") String code, HttpServletResponse response) throws IOException { AccountCreationService.AccountCreationResponse accountCreation; try {// www . j av a 2 s .c o m accountCreation = accountCreationService.completeActivation(code); } catch (HttpClientErrorException e) { model.addAttribute("error_message_code", "code_expired"); response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value()); return "accounts/new_activation_email"; } UaaPrincipal uaaPrincipal = new UaaPrincipal(accountCreation.getUserId(), accountCreation.getUsername(), accountCreation.getEmail(), Origin.UAA, null); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(uaaPrincipal, null, UaaAuthority.USER_AUTHORITIES); SecurityContextHolder.getContext().setAuthentication(token); String redirectLocation = accountCreation.getRedirectLocation(); if (redirectLocation == null) { redirectLocation = "home"; } return "redirect:" + redirectLocation; }
From source file:org.smigo.user.UserController.java
@PreAuthorize("isAuthenticated()") @RequestMapping(value = "/rest/user", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseBody/* www . j a va 2 s . co m*/ public List<ObjectError> updateUser(@RequestBody @Valid User userBean, BindingResult result, @AuthenticationPrincipal AuthenticatedUser user, HttpServletResponse response) { if (result.hasErrors()) { log.warn("Update user failed. Username:" + user.getUsername() + " Errors:" + StringUtils.arrayToDelimitedString(result.getAllErrors().toArray(), ", ")); response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value()); return result.getAllErrors(); } log.info("Updating user: " + userBean.toString()); userHandler.updateUser(user.getId(), userBean); return Collections.emptyList(); }
From source file:fi.helsinki.opintoni.exception.GlobalExceptionHandlers.java
@Override protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { List<FieldError> fieldErrors = ex.getBindingResult().getFieldErrors(); List<ValidationError> errorResources = fieldErrors.stream() .map(fieldError -> new ValidationError(fieldError.getField(), fieldError.getCode())) .collect(Collectors.toList()); return new ResponseEntity<>(errorResources, headers, HttpStatus.UNPROCESSABLE_ENTITY); }
From source file:com.sentinel.web.controllers.OrientDbController.java
/** * /*from www . j ava 2s . co m*/ * @param user * @param role * @return */ @RequestMapping(value = "/users/{user}/revoke/role/{role}", method = RequestMethod.POST) @ResponseBody @PreAuthorize(value = "hasRole('ORIENT_ADMIN_PRIVILEGE')") public ResponseEntity<String> revokeRole(@PathVariable User user, @PathVariable Role role) { if (user == null) { return new ResponseEntity<String>("invalid user id", HttpStatus.UNPROCESSABLE_ENTITY); } userService.revokeRole(user, role); userRepository.saveAndFlush(user); return new ResponseEntity<String>("role revoked", HttpStatus.OK); }
From source file:com.ge.predix.acs.privilege.management.SubjectPrivilegeManagementController.java
@ApiOperation(value = "Creates a list of subjects. Existing subjects will be updated with the provided values.", tags = { "Attribute Management" }) @ApiResponses(value = { @ApiResponse(code = 204, message = "Subject objects added successfully."), }) @RequestMapping(method = POST, value = { V1 + SUBJECTS_URL }, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<?> appendsubjects(@RequestBody final List<BaseSubject> subjects) { try {//from w ww .j a va2s.c o m this.failIfParentsSpecified(subjects); this.service.appendSubjects(subjects); return noContent(); } catch (RestApiException e) { // NOTE: This block is necessary to avoid accidentally // converting the HTTP status code to an unintended one throw e; } catch (Exception e) { throw new RestApiException(HttpStatus.UNPROCESSABLE_ENTITY, e); } }
From source file:com.ge.predix.acs.privilege.management.ResourcePrivilegeManagementController.java
@ApiOperation(value = "Creates a list of resources for the given zone. " + "Existing resources will be updated with the provided values.", tags = { "Attribute Management" }) @ApiResponses(value = { @ApiResponse(code = 204, message = "Resource objects appended successfully."), }) @RequestMapping(method = POST, value = { V1 + MANAGED_RESOURCES_URL }, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<?> appendResources(@RequestBody final List<BaseResource> resources) { try {//from w w w . ja v a2 s.c o m this.failIfParentsSpecified(resources); this.service.appendResources(resources); return noContent(); } catch (RestApiException e) { // NOTE: This block is necessary to avoid accidentally // converting the HTTP status code to an unintended one throw e; } catch (Exception e) { throw new RestApiException(HttpStatus.UNPROCESSABLE_ENTITY, e); } }
From source file:org.venice.piazza.servicecontroller.messaging.handlers.RegisterServiceHandlerTest.java
/** * Test what happens when there is an invalid registration *///from w ww . j a va2s .co m @Test public void testUnsuccessfulRegistration() { RegisterServiceJob job = new RegisterServiceJob(); job.data = service; final RegisterServiceHandler rsMock = Mockito.spy(rsHandler); Mockito.doReturn("").when(rsMock).handle(service); ResponseEntity<String> result = rsMock.handle(job); assertEquals("The status code should be HttpStatus.UNPROCESSABLE_ENTITY.", result.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); }
From source file:org.venice.piazza.servicecontroller.messaging.handlers.UpdateServiceHandlerTest.java
/** * Test what happens when there is an invalid update *///from w w w . j av a2 s . co m @Test public void testUnsuccessfulUpdate() { UpdateServiceJob job = new UpdateServiceJob(); job.data = service; job.jobId = "a842aae2-bd74-4c4b-9a65-c45e8cd9060"; ArrayList<String> resultList = new ArrayList<String>(); resultList.add(job.jobId); resultList.add(service.getServiceId()); ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultList.toString(), HttpStatus.UNPROCESSABLE_ENTITY); final UpdateServiceHandler ushMock = Mockito.spy(usHandler); Mockito.doReturn("").when(ushMock).handle(service); ResponseEntity<String> result = ushMock.handle(job); assertEquals("The item was not updated successfully.", responseEntity.getStatusCode(), result.getStatusCode()); }