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:org.osiam.resources.exceptions.OsiamExceptionHandler.java
private HttpStatus setStatus(Exception ex) { if (ex instanceof ResourceNotFoundException) { return HttpStatus.NOT_FOUND; }/*from w ww. ja v a2 s . com*/ if (ex instanceof SchemaUnknownException) { return HttpStatus.I_AM_A_TEAPOT; } if (ex instanceof UnsupportedOperationException) { return HttpStatus.NOT_IMPLEMENTED; } return HttpStatus.CONFLICT; }
From source file:com.example.todo.api.common.error.RestGlobalExceptionHandler.java
@ExceptionHandler(BusinessException.class) public ResponseEntity<Object> handleBusinessException(BusinessException ex, WebRequest request) { return handleResultMessagesNotificationException(ex, new HttpHeaders(), HttpStatus.CONFLICT, request); }
From source file:de.codecentric.boot.admin.services.SpringBootAdminRegistratorTest.java
@Test public void register_failed_conflict() { AdminProperties adminProps = new AdminProperties(); adminProps.setUrl("http://sba:8080"); AdminClientProperties clientProps = new AdminClientProperties(); clientProps.setUrl("http://localhost:8080"); clientProps.setName("AppName"); RestTemplate restTemplate = mock(RestTemplate.class); when(restTemplate.postForEntity(isA(String.class), isA(Application.class), eq(Application.class))) .thenReturn(new ResponseEntity<Application>(HttpStatus.CONFLICT)); SpringBootAdminRegistrator registrator = new SpringBootAdminRegistrator(restTemplate, adminProps, clientProps);//from ww w . ja v a 2 s . co m boolean result = registrator.register(); assertFalse(result); }
From source file:ch.wisv.areafiftylan.extras.consumption.controller.ConsumptionController.java
@ExceptionHandler(value = AlreadyConsumedException.class) public ResponseEntity<?> handleAlreadyConsumed(AlreadyConsumedException e) { return createResponseEntity(HttpStatus.CONFLICT, e.getMessage()); }
From source file:org.jrb.lots.web.GlobalExceptionHandler.java
/** * Converts one of several client-based conflict exceptions into an HTTP 409 * response with an error body. The mapped exceptions are as follows: * <ul>/* ww w. j av a 2s . c o m*/ * <li>{@link DuplicateTagException}</li> * <li>{@link DuplicateThingException}</li> * </ul> * * @param e * the client exception * @return the error body */ @ExceptionHandler({ DuplicateTagException.class, DuplicateThingException.class }) public ResponseEntity<MessageResponse> handleConflictError(final Exception e) { if (LOG.isDebugEnabled()) { LOG.debug(e.getMessage(), e); } return utils.createMessageResponse(e.getMessage(), HttpStatus.CONFLICT); }
From source file:nc.noumea.mairie.organigramme.core.ws.BaseWsConsumer.java
public String readResponseAsString(ClientResponse response, String url) { if (response.getStatus() == HttpStatus.NO_CONTENT.value()) { return null; }/* ww w . j a v a 2s . c om*/ if (response.getStatus() != HttpStatus.OK.value() && response.getStatus() != HttpStatus.CONFLICT.value()) { throw new WSConsumerException( String.format("An error occured when querying '%s'. Return code is : %s, content is %s", url, response.getStatus(), response.getEntity(String.class))); } return response.getEntity(String.class); }
From source file:no.ndla.taxonomy.service.SwaggerConfiguration.java
@Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2).select() .apis(RequestHandlerSelectors.basePackage("no.ndla.taxonomy.service.rest.v1")) .paths(PathSelectors.regex("/v1/.*")).build().pathMapping("/").apiInfo(apiInfo()) .securitySchemes(newArrayList(oauth())).securityContexts(newArrayList(securityContext())) .directModelSubstitute(URI.class, String.class).useDefaultResponseMessages(false) .produces(newHashSet(APPLICATION_JSON_UTF8.toString())) .consumes(newHashSet(APPLICATION_JSON_UTF8.toString())) .globalResponseMessage(RequestMethod.GET, newArrayList(new ResponseMessageBuilder().code(HttpStatus.OK.value()) .message(HttpStatus.OK.getReasonPhrase()).build())) .globalResponseMessage(RequestMethod.PUT, newArrayList(//from w w w. j a v a 2 s . co m new ResponseMessageBuilder().code(NO_CONTENT.value()) .message(NO_CONTENT.getReasonPhrase()).build(), new ResponseMessageBuilder().code(NOT_FOUND.value()) .message(NOT_FOUND.getReasonPhrase()).build())) .globalResponseMessage(DELETE, newArrayList( new ResponseMessageBuilder().code(NO_CONTENT.value()) .message(NO_CONTENT.getReasonPhrase()).build(), new ResponseMessageBuilder().code(NOT_FOUND.value()) .message(NOT_FOUND.getReasonPhrase()).build())) .globalResponseMessage(RequestMethod.POST, newArrayList( new ResponseMessageBuilder().code(HttpStatus.CREATED.value()) .message(CREATED.getReasonPhrase()) .headersWithDescription(singletonMap(LOCATION.toString(), new Header("Location", "Path to created resource", new ModelRef("URI")))) .build(), new ResponseMessageBuilder().code(HttpStatus.CONFLICT.value()) .message(CONFLICT.getReasonPhrase()).build())); }
From source file:net.maritimecloud.identityregistry.controllers.EntityController.java
/** * Creates a new Entity//from w w w . j a v a 2 s .c om * * @return a reply... * @throws McBasicRestException */ protected ResponseEntity<T> createEntity(HttpServletRequest request, String orgMrn, T input) throws McBasicRestException { Organization org = this.organizationService.getOrganizationByMrn(orgMrn); if (org != null) { // Check that the entity being created belongs to the organization if (!MrnUtil.getOrgShortNameFromOrgMrn(orgMrn) .equals(MrnUtil.getOrgShortNameFromEntityMrn(input.getMrn()))) { throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.MISSING_RIGHTS, request.getServletPath()); } input.setIdOrganization(org.getId()); try { T newEntity = this.entityService.save(input); return new ResponseEntity<>(newEntity, HttpStatus.OK); } catch (DataIntegrityViolationException e) { throw new McBasicRestException(HttpStatus.CONFLICT, e.getRootCause().getMessage(), request.getServletPath()); } } else { throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND, request.getServletPath()); } }
From source file:com.appglu.impl.UserTemplateTest.java
@Test public void signupUsernameExists() { mockServer.expect(requestTo("http://localhost/appglu/v1/users")).andExpect(method(HttpMethod.POST)) .andExpect(header("Content-Type", jsonMediaType.toString())) .andExpect(content().string(compactedJson("data/user_signup"))) .andRespond(withStatus(HttpStatus.CONFLICT).body(compactedJson("data/user_signup_username_exists")) .headers(responseHeaders)); Assert.assertFalse(appGluTemplate.isUserAuthenticated()); Assert.assertNull(appGluTemplate.getAuthenticatedUser()); User user = new User(); user.setUsername("username"); user.setPassword("password"); AuthenticationResult result = userOperations.signup(user); Assert.assertFalse(result.succeed()); Assert.assertFalse(appGluTemplate.isUserAuthenticated()); Assert.assertNull(appGluTemplate.getAuthenticatedUser()); Assert.assertEquals(ErrorCode.APP_USER_USERNAME_ALREADY_USED, result.getError().getCode()); Assert.assertEquals("There is already an user with this username.", result.getError().getMessage()); mockServer.verify();/*w ww. ja v a 2s .co m*/ }
From source file:org.trustedanalytics.user.invite.RestErrorHandler.java
@ResponseBody @ResponseStatus(HttpStatus.CONFLICT) @ExceptionHandler(WrongUserRolesException.class) public String incorrectRoles(Exception e) throws IOException { return e.getMessage(); }