Example usage for org.springframework.http HttpStatus CONFLICT

List of usage examples for org.springframework.http HttpStatus CONFLICT

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus CONFLICT.

Prototype

HttpStatus CONFLICT

To view the source code for org.springframework.http HttpStatus CONFLICT.

Click Source Link

Document

409 Conflict .

Usage

From source file:org.dataone.proto.trove.mn.rest.base.AbstractWebController.java

@ResponseStatus(value = HttpStatus.CONFLICT)
@ExceptionHandler(IdentifierNotUnique.class)
public void handleException(IdentifierNotUnique exception, HttpServletRequest request,
        HttpServletResponse response) {/* ww  w.j a  v a  2s.c o m*/
    handleBaseException((BaseException) exception, request, response);
}

From source file:ca.intelliware.ihtsdo.mlds.web.rest.ReleasePackagesResource.java

@RequestMapping(value = Routes.RELEASE_PACKAGE, method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
@RolesAllowed({ AuthoritiesConstants.STAFF, AuthoritiesConstants.ADMIN })
@Timed/* ww  w  .  j a va  2  s  .c om*/
public @ResponseBody ResponseEntity<?> deactivateReleasePackage(@PathVariable long releasePackageId) {

    ReleasePackage releasePackage = releasePackageRepository.findOne(releasePackageId);
    if (releasePackage == null) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }

    authorizationChecker.checkCanEditReleasePackage(releasePackage);

    for (ReleaseVersion releaseVersion : releasePackage.getReleaseVersions()) {
        if (releaseVersion.isOnline()) {
            return new ResponseEntity<>(HttpStatus.CONFLICT);
        }
    }

    releasePackageAuditEvents.logDeletionOf(releasePackage);

    // Actually mark releasePackage as being inactive and then hide from subsequent calls rather than sql delete from the db
    releasePackageRepository.delete(releasePackage);

    return new ResponseEntity<>(HttpStatus.OK);
}

From source file:org.kew.rmf.reconciliation.ws.ReconciliationServiceController.java

/**
 * Single reconciliation query.// www.j  av a2 s. c  o m
 */
@RequestMapping(value = "/reconcile/{configName}", method = { RequestMethod.GET,
        RequestMethod.POST }, params = { "query", "callback" }, produces = "application/json; charset=UTF-8")
public ResponseEntity<String> doSingleQuery(@PathVariable String configName,
        @RequestParam("query") String query,
        @RequestParam(value = "callback", required = false) String callback) {
    logger.info("{}: Single query request {}", configName, query);

    String jsonres = null;
    try {
        Query q = jsonMapper.readValue(query, Query.class);
        QueryResult[] qres = doQuery(q, configName);
        QueryResponse<QueryResult> response = new QueryResponse<>();
        response.setResult(qres);
        jsonres = jsonMapper.writeValueAsString(response);
    } catch (JsonMappingException | JsonGenerationException e) {
        logger.warn(configName + ": Error parsing JSON query", e);
        return new ResponseEntity<String>(e.toString(), HttpStatus.INTERNAL_SERVER_ERROR);
    } catch (IOException e) {
        return new ResponseEntity<String>(e.toString(), HttpStatus.INTERNAL_SERVER_ERROR);
    } catch (MatchExecutionException e) {
        return new ResponseEntity<String>(e.toString(), HttpStatus.NOT_FOUND);
    } catch (TooManyMatchesException e) {
        return new ResponseEntity<String>(e.toString(), HttpStatus.CONFLICT);
    }

    return new ResponseEntity<String>(wrapResponse(callback, jsonres), HttpStatus.OK);
}

From source file:org.spring.data.gemfire.rest.GemFireRestInterfaceTest.java

@SuppressWarnings("deprecation")
private RestTemplate setErrorHandler(final RestTemplate restTemplate) {
    restTemplate.setErrorHandler(new ResponseErrorHandler() {
        private final Set<HttpStatus> errorStatuses = new HashSet<>();

        /* non-static */ {
            errorStatuses.add(HttpStatus.BAD_REQUEST);
            errorStatuses.add(HttpStatus.UNAUTHORIZED);
            errorStatuses.add(HttpStatus.FORBIDDEN);
            errorStatuses.add(HttpStatus.NOT_FOUND);
            errorStatuses.add(HttpStatus.METHOD_NOT_ALLOWED);
            errorStatuses.add(HttpStatus.NOT_ACCEPTABLE);
            errorStatuses.add(HttpStatus.REQUEST_TIMEOUT);
            errorStatuses.add(HttpStatus.CONFLICT);
            errorStatuses.add(HttpStatus.REQUEST_ENTITY_TOO_LARGE);
            errorStatuses.add(HttpStatus.REQUEST_URI_TOO_LONG);
            errorStatuses.add(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
            errorStatuses.add(HttpStatus.TOO_MANY_REQUESTS);
            errorStatuses.add(HttpStatus.INTERNAL_SERVER_ERROR);
            errorStatuses.add(HttpStatus.NOT_IMPLEMENTED);
            errorStatuses.add(HttpStatus.BAD_GATEWAY);
            errorStatuses.add(HttpStatus.SERVICE_UNAVAILABLE);
        }/*from   w  ww.j  a v  a2s.co m*/

        @Override
        public boolean hasError(final ClientHttpResponse response) throws IOException {
            return errorStatuses.contains(response.getStatusCode());
        }

        @Override
        public void handleError(final ClientHttpResponse response) throws IOException {
            System.err.printf("%1$d - %2$s%n", response.getRawStatusCode(), response.getStatusText());
            System.err.println(readBody(response));
        }

        private String readBody(final ClientHttpResponse response) throws IOException {
            BufferedReader responseBodyReader = null;

            try {
                responseBodyReader = new BufferedReader(new InputStreamReader(response.getBody()));

                StringBuilder buffer = new StringBuilder();
                String line;

                while ((line = responseBodyReader.readLine()) != null) {
                    buffer.append(line).append(System.getProperty("line.separator"));
                }

                return buffer.toString().trim();
            } finally {
                FileSystemUtils.close(responseBodyReader);
            }
        }
    });

    return restTemplate;
}

From source file:ch.wisv.areafiftylan.products.controller.OrderRestController.java

@ExceptionHandler(ImmutableOrderException.class)
public ResponseEntity<?> handleWrongOrderStatusException(ImmutableOrderException e) {
    return createResponseEntity(HttpStatus.CONFLICT, e.getMessage());
}

From source file:org.cloudfoundry.identity.uaa.integration.ClientAdminEndpointsIntegrationTests.java

@Test
// CFID-372/*from w w w .  j  a v a 2  s .c o  m*/
public void testCreateExistingClientFails() throws Exception {
    BaseClientDetails client = createClient("client_credentials");

    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> attempt = serverRunning.getRestTemplate().exchange(
            serverRunning.getUrl("/oauth/clients"), HttpMethod.POST,
            new HttpEntity<BaseClientDetails>(client, headers), Map.class);
    assertEquals(HttpStatus.CONFLICT, attempt.getStatusCode());
    @SuppressWarnings("unchecked")
    Map<String, String> map = attempt.getBody();
    assertEquals("invalid_client", map.get("error"));
}

From source file:net.maritimecloud.identityregistry.controllers.ServiceController.java

/**
 * Updates a Service/*from ww w.j a  va  2  s  . c o  m*/
 * 
 * @return a reply...
 * @throws McBasicRestException 
 */
@RequestMapping(value = "/api/org/{orgMrn}/service/{serviceMrn}", method = RequestMethod.PUT)
@ResponseBody
@PreAuthorize("hasRole('SERVICE_ADMIN') and @accessControlUtil.hasAccessToOrg(#orgMrn)")
public ResponseEntity<?> updateService(HttpServletRequest request, @PathVariable String orgMrn,
        @PathVariable String serviceMrn, @Valid @RequestBody Service input, BindingResult bindingResult)
        throws McBasicRestException {
    ValidateUtil.hasErrors(bindingResult, request);
    if (!serviceMrn.equals(input.getMrn())) {
        throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.URL_DATA_MISMATCH,
                request.getServletPath());
    }
    Organization org = this.organizationService.getOrganizationByMrn(orgMrn);
    if (org != null) {
        // Check that the entity being updated belongs to the organization
        if (!MrnUtil.getOrgShortNameFromOrgMrn(orgMrn)
                .equals(MrnUtil.getOrgShortNameFromEntityMrn(input.getMrn()))) {
            throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.MISSING_RIGHTS,
                    request.getServletPath());
        }
        Service service = this.entityService.getByMrn(serviceMrn);
        if (service == null) {
            throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ENTITY_NOT_FOUND,
                    request.getServletPath());
        }
        if (service.getIdOrganization().compareTo(org.getId()) == 0) {
            // Update the keycloak client for the service if needed
            if (input.getOidcAccessType() != null && !input.getOidcAccessType().trim().isEmpty()) {
                // Check if the redirect uri is set if access type is "bearer-only"
                if (!"bearer-only".equals(input.getOidcAccessType()) && (input.getOidcRedirectUri() == null
                        || input.getOidcRedirectUri().trim().isEmpty())) {
                    throw new McBasicRestException(HttpStatus.BAD_REQUEST,
                            MCIdRegConstants.OIDC_MISSING_REDIRECT_URL, request.getServletPath());
                }
                keycloakAU.init(KeycloakAdminUtil.BROKER_INSTANCE);
                String clientSecret;
                try {
                    if (service.getOidcClientId() != null && !service.getOidcClientId().isEmpty()) {
                        clientSecret = keycloakAU.updateClient(service.getMrn(), service.getOidcAccessType(),
                                service.getOidcRedirectUri());
                    } else {
                        service.setOidcClientId(service.getMrn());
                        clientSecret = keycloakAU.createClient(service.getMrn(), service.getOidcAccessType(),
                                service.getOidcRedirectUri());
                    }
                } catch (IOException e) {
                    log.error("Error while updating/creation client in keycloak.", e);
                    throw new McBasicRestException(HttpStatus.INTERNAL_SERVER_ERROR,
                            MCIdRegConstants.ERROR_CREATING_KC_CLIENT, request.getServletPath());
                } catch (DuplicatedKeycloakEntry dke) {
                    throw new McBasicRestException(HttpStatus.CONFLICT, dke.getErrorMessage(),
                            request.getServletPath());
                }
                if ("confidential".equals(service.getOidcAccessType())) {
                    service.setOidcClientSecret(clientSecret);
                } else {
                    service.setOidcClientSecret(null);
                }
            }
            input.selectiveCopyTo(service);
            try {
                this.entityService.save(service);
                return new ResponseEntity<>(HttpStatus.OK);
            } catch (DataIntegrityViolationException e) {
                throw new McBasicRestException(HttpStatus.CONFLICT, e.getRootCause().getMessage(),
                        request.getServletPath());
            }
        }
        throw new McBasicRestException(HttpStatus.FORBIDDEN, MCIdRegConstants.MISSING_RIGHTS,
                request.getServletPath());
    } else {
        throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND,
                request.getServletPath());
    }
}

From source file:ch.wisv.areafiftylan.teams.controller.TeamRestController.java

@ExceptionHandler(IllegalArgumentException.class)
public ResponseEntity<?> handleIllegalArgumentException(IllegalArgumentException e) {
    return createResponseEntity(HttpStatus.CONFLICT, e.getMessage());
}

From source file:org.terasoluna.gfw.functionaltest.app.exceptionhandling.ExceptionHandlingController.java

@ExceptionHandler(OptimisticLockingFailureException.class)
@ResponseStatus(HttpStatus.CONFLICT)
public ModelAndView handleException(OptimisticLockingFailureException e) {
    ExtendedModelMap modelMap = new ExtendedModelMap();

    modelMap.addAttribute("exceptionMessage", e.getMessage());
    return new ModelAndView("exceptionhandling/exceptionHandler", modelMap);
}

From source file:org.terasoluna.gfw.functionaltest.app.exceptionhandling.ExceptionHandlingController.java

@ExceptionHandler(PessimisticLockingFailureException.class)
@ResponseStatus(HttpStatus.CONFLICT)
public ModelAndView handleException(PessimisticLockingFailureException e) {
    ExtendedModelMap modelMap = new ExtendedModelMap();

    modelMap.addAttribute("exceptionMessage", e.getMessage());
    return new ModelAndView("exceptionhandling/exceptionHandler", modelMap);
}