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.acs.privilege.management.ResourcePrivilegeManagementController.java
private ResponseEntity<BaseResource> doPutResource(final BaseResource resource, final String resourceIdentifier) { try {//from w ww . j a v a 2 s . c o m boolean createdResource = this.service.upsertResource(resource); URI resourceUri = UriTemplateUtils.expand(MANAGED_RESOURCE_URL, "resourceIdentifier:" + resourceIdentifier); if (createdResource) { return created(resourceUri.getPath(), false); } // CHECK if path returns the right info return created(resourceUri.getPath(), true); } catch (Exception e) { throw new RestApiException(HttpStatus.UNPROCESSABLE_ENTITY, e); } }
From source file:ch.heigvd.gamification.api.BadgesEndpoint.java
@Override @RequestMapping(method = RequestMethod.POST) public ResponseEntity<Void> badgesPost( @ApiParam(value = "Badge to add", required = true) @RequestBody BadgeDTO body, @ApiParam(value = "token that identifies the app sending the request", required = true) @RequestHeader(value = "X-Gamification-Token", required = true) String xGamificationToken) { AuthenKey apiKey = authenKeyRepository.findByAppKey(xGamificationToken); if (apiKey == null) { return new ResponseEntity(HttpStatus.UNAUTHORIZED); }/* w w w . j a v a 2 s . com*/ Application app = apiKey.getApp(); if (body != null && app != null) { if (badgeRepository.findByNameAndApp(body.getName(), app) != null) { return new ResponseEntity("name already use", HttpStatus.UNPROCESSABLE_ENTITY); } Badge badge = new Badge(); badge.setDescription(body.getDescription()); badge.setName(body.getName()); badge.setImage(body.getImageURI()); badge.setApp(app); badgeRepository.save(badge); HttpHeaders responseHeaders = new HttpHeaders(); UriComponents uriComponents = MvcUriComponentsBuilder .fromMethodName(BadgesEndpoint.class, "badgesBadgeIdGet", 1, badge.getId()).build(); URI locationUri = uriComponents.toUri(); responseHeaders.add("Location", uriComponents.toString()); return new ResponseEntity<>(responseHeaders, HttpStatus.CREATED); } else { return new ResponseEntity("no content is available", HttpStatus.BAD_REQUEST); } }
From source file:com.ge.predix.acs.privilege.management.ResourcePrivilegeManagementController.java
private void validResourceIdentifierOrFail(final BaseResource resource, final String resourceIdentifier) { if (!resourceIdentifier.equals(resource.getResourceIdentifier())) { throw new RestApiException(HttpStatus.UNPROCESSABLE_ENTITY, String.format("Resource identifier = %s, does not match the one provided in URI = %s", resource.getResourceIdentifier(), resourceIdentifier)); }/*from ww w.java 2 s . c o m*/ }
From source file:io.github.microcks.web.DynamicMockRestController.java
@RequestMapping(value = "/{service}/{version}/{resource}/{resourceId}", method = RequestMethod.PUT) public ResponseEntity<String> updateResource(@PathVariable("service") String serviceName, @PathVariable("version") String version, @PathVariable("resource") String resource, @PathVariable("resourceId") String resourceId, @RequestParam(value = "delay", required = false) Long delay, @RequestBody(required = true) String body, HttpServletRequest request) {// w w w . j a v a2 s . co m log.debug("Update resource '{}:{}' for service '{}-{}'", resource, resourceId, serviceName, version); long startTime = System.currentTimeMillis(); MockContext mockContext = getMockContext(serviceName, version, "PUT /" + resource + "/:id"); if (mockContext != null) { // Get the requested generic resource. GenericResource genericResource = genericResourceRepository.findOne(resourceId); if (genericResource != null) { Document document = null; try { // Try parsing body payload that should be json. document = Document.parse(body); document.remove(ID_FIELD); // Now update the generic resource payload. genericResource.setPayload(document); genericResourceRepository.save(genericResource); } catch (JsonParseException jpe) { // Return a 422 code : unprocessable entity. return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY); } // Wait if specified before returning. waitForDelay(startTime, delay, mockContext); // Return the updated resource as well as a 200 code. return new ResponseEntity<>(transformToResourceJSON(genericResource), HttpStatus.OK); } else { // Wait if specified before returning. waitForDelay(startTime, delay, mockContext); // Return a 404 code : not found. return new ResponseEntity<>(HttpStatus.NOT_FOUND); } } // Return a 400 code : bad request. return new ResponseEntity<>(HttpStatus.BAD_REQUEST); }
From source file:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java
public void testBatchCreateResourcesEmptyList() { List<BaseResource> resources = new ArrayList<BaseResource>(); try {/*from w ww. jav a2s. c om*/ this.acsAdminRestTemplate.postForEntity(this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH, new HttpEntity<>(resources, this.zone1Headers), BaseResource[].class); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); return; } Assert.fail("Expected unprocessable entity http client error."); }
From source file:com.ge.predix.integration.test.AccessControlServiceIT.java
@Test(dataProvider = "endpointProvider") public void testPolicyCreationInValidPolicy(final String endpoint) throws Exception { String testPolicyName = ""; try {/*from w ww . j a v a 2 s.c o m*/ String policyFile = "src/test/resources/missing-policy-set-name-policy.json"; testPolicyName = this.policyHelper.setTestPolicy(this.acsAdminRestTemplate, this.zone1Headers, endpoint, policyFile); } catch (HttpClientErrorException e) { this.acsTestUtil.assertExceptionResponseBody(e, "policy set name is missing"); Assert.assertEquals(e.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); return; } this.policyHelper.deletePolicySet(this.acsAdminRestTemplate, this.acsUrl, testPolicyName, this.zone1Headers); Assert.fail("testPolicyCreationInValidPolicy should have failed"); }
From source file:com.ge.predix.integration.test.AccessControlServiceIT.java
@Test(dataProvider = "endpointProvider") public void testPolicyCreationInValidWithBadPolicySetNamePolicy(final String endpoint) throws Exception { String testPolicyName = ""; try {/* w ww . j av a 2 s . c o m*/ String policyFile = "src/test/resources/policy-set-with-only-name-effect.json"; testPolicyName = this.policyHelper.setTestPolicy(this.acsAdminRestTemplate, this.zone1Headers, endpoint, policyFile); } catch (HttpClientErrorException e) { this.acsTestUtil.assertExceptionResponseBody(e, "is not URI friendly"); Assert.assertEquals(e.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); return; } this.policyHelper.deletePolicySet(this.acsAdminRestTemplate, this.acsUrl, testPolicyName, this.zone1Headers); Assert.fail("testPolicyCreationInValidPolicy should have failed"); }
From source file:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java
@Test public void testBatchResourcesDataConstraintViolationResourceIdentifier() { List<BaseResource> resources = new ArrayList<BaseResource>(); resources.add(this.privilegeHelper.createResource("dupResourceIdentifier")); resources.add(this.privilegeHelper.createResource("dupResourceIdentifier")); try {//w w w. ja va 2 s . c om // This POST causes a data constraint violation on the service bcos // of duplicate // resource_identifiers which returns a HTTP 422 error. this.acsAdminRestTemplate.postForEntity(this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH, new HttpEntity<>(resources, this.zone1Headers), ResponseEntity.class); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); return; } this.acsAdminRestTemplate.exchange(this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH + "/marissa", HttpMethod.DELETE, new HttpEntity<>(this.zone1Headers), ResponseEntity.class); Assert.fail( "Expected unprocessable entity http client error on post for 2 resources with duplicate resource" + "identifiers."); }
From source file:com.ge.predix.integration.test.AccessControlServiceIT.java
@Test(dataProvider = "endpointProvider") public void testPolicyCreationJsonSchemaInvalidPolicySet(final String endpoint) throws Exception { String testPolicyName = ""; try {//from w w w. j a va 2s .c om String policyFile = "src/test/resources/invalid-json-schema-policy-set.json"; testPolicyName = this.policyHelper.setTestPolicy(this.acsAdminRestTemplate, this.zone1Headers, endpoint, policyFile); } catch (HttpClientErrorException e) { this.acsTestUtil.assertExceptionResponseBody(e, "JSON Schema validation"); Assert.assertEquals(e.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); return; } this.policyHelper.deletePolicySet(this.acsAdminRestTemplate, this.acsUrl, testPolicyName, this.zone1Headers); Assert.fail("testPolicyCreationInValidPolicy should have failed"); }
From source file:de.codecentric.batch.web.JobOperationsController.java
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY) @ExceptionHandler(JobParametersInvalidException.class) public String handleParametersInvalid(Exception ex) { LOG.warn("Job parameters are invalid.", ex); return ex.getMessage(); }