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:ch.wisv.areafiftylan.exception.GlobalControllerExceptionHandler.java

@ExceptionHandler(DataIntegrityViolationException.class)
public ResponseEntity<?> handleDataIntegrityViolation(DataIntegrityViolationException ex) {
    return createResponseEntity(HttpStatus.CONFLICT, ex.getMessage());
}

From source file:com.agroservices.restcontrollers.ProductosRest.java

@RequestMapping(value = "/", method = RequestMethod.POST)
public ResponseEntity<?> persist(@RequestBody Producto p) {
    try {/*  w ww .  j  a v a 2 s .c om*/
        pf.saveProducto(p);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        return new ResponseEntity<>(HttpStatus.CONFLICT);
    }
    return new ResponseEntity<>(HttpStatus.CREATED);
}

From source file:org.trustedanalytics.kafka.adminapi.api.ExceptionHandlerAdvice.java

@ExceptionHandler
@ResponseStatus(HttpStatus.CONFLICT)
@ResponseBody//  w w w.  j av a 2  s  .  c  om
public String handleConflict(TopicExistsException ex) {
    LOG.error("Handling TopicExistsException", ex);
    return ex.getMessage();
}

From source file:org.osiam.resources.exception.OsiamExceptionHandler.java

@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.CONFLICT)
@ResponseBody/*w  ww .j  av a2s.  c om*/
public ErrorResponse defaultExceptionHandler(Exception ex) {
    LOGGER.warn("An unexpected exception occurred", ex);
    return produceErrorResponse("An unexpected error occurred", HttpStatus.CONFLICT);
}

From source file:com.agroservices.restcontrollers.DespachoRest.java

@RequestMapping(value = "/{id}/seEntrego", method = RequestMethod.POST)
public ResponseEntity<?> modificarEstadoEntrega(@PathVariable int id, @RequestBody Despacho des) {
    boolean ans = df.setEstadoEntrega(id, des.isSeEntrego());
    if (ans) {/*from  w  w w .  ja v a2 s  .com*/
        return new ResponseEntity<>(HttpStatus.CREATED);
    }
    return new ResponseEntity<>(HttpStatus.CONFLICT);
}

From source file:gt.dakaik.exceptions.ManejadorExcepciones.java

@ResponseBody
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.CONFLICT)
ResponseEntity<String> exceptionHandler(Exception ex) {
    StringWriter errors = new StringWriter();
    ex.printStackTrace(new PrintWriter(errors));
    String err = errors.toString();
    eLog.error(err);/*from www.ja  v  a2 s  .  co  m*/
    String resp = "<div><h1>" + ex.getMessage() + "</h1><br/><p>" + err + "</p></div>";
    return new ResponseEntity(resp, HttpStatus.CONFLICT);
}

From source file:de.codecentric.boot.admin.services.SpringBootAdminRegistrator.java

/**
 * Registers the client application at spring-boot-admin-server.
 * @return true if successful//from   ww w .j  a  v a 2s .  co  m
 */
public boolean register() {
    Application app = createApplication();
    String adminUrl = adminProps.getUrl() + '/' + adminProps.getContextPath();

    try {
        ResponseEntity<Application> response = template.postForEntity(adminUrl, app, Application.class);

        if (response.getStatusCode().equals(HttpStatus.CREATED)) {
            LOGGER.debug("Application registered itself as {}", response.getBody());
            return true;
        } else if (response.getStatusCode().equals(HttpStatus.CONFLICT)) {
            LOGGER.warn("Application failed to registered itself as {} because of conflict in registry.", app);
        } else {
            LOGGER.warn("Application failed to registered itself as {}. Response: {}", app,
                    response.toString());
        }
    } catch (Exception ex) {
        LOGGER.warn("Failed to register application as {} at spring-boot-admin ({}): {}", app, adminUrl,
                ex.getMessage());
    }

    return false;
}

From source file:ca.qhrtech.controllers.CategoryController.java

@ApiMethod(description = "Creates a new Category")
@RequestMapping(value = "/category", method = RequestMethod.POST)
public ResponseEntity<Category> createCategory(@RequestBody Category category) {
    if (!categoryService.doesCategoryExist(category)) {
        Category newCategory = categoryService.saveCategory(category);
        return new ResponseEntity<>(newCategory, HttpStatus.CREATED);
    }/*from  w  w  w . ja va  2s.c o  m*/
    return new ResponseEntity<>(HttpStatus.CONFLICT);
}

From source file:org.ameba.exception.ResourceChangedException.java

/**
 * {@link HttpStatus#CONFLICT}.
 *
 * @return {@link HttpStatus#CONFLICT}
 */
@Override
public HttpStatus getStatus() {
    return HttpStatus.CONFLICT;
}

From source file:com.todo.backend.web.rest.exception.ExceptionResolver.java

@ResponseStatus(value = HttpStatus.CONFLICT)
@ExceptionHandler(DataIntegrityViolationException.class)
public @ResponseBody ErrorResponse dataIntegrityException(HttpServletRequest request,
        DataIntegrityViolationException exception) {
    if (log.isErrorEnabled()) {
        log.error(exception.getMessage(), exception);
    }//  w w w.  j ava 2  s .  c  o m
    // example: Duplicate entry 'field1-field2' for key 'UNQ_MODE_F1_F2_251F9D'
    final String message = exception.getRootCause().getMessage();
    if (message.contains("'UNQ")) {
        final String constraint = message.substring(message.indexOf("'UNQ") + 1, message.lastIndexOf("'"));
        return new ErrorResponse(ConstraintMapping.getErrorCodeForConstraint(constraint), message);
    }
    return new ErrorResponse(message, Collections.emptyList());
}