Example usage for org.springframework.http HttpStatus NOT_ACCEPTABLE

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

Introduction

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

Prototype

HttpStatus NOT_ACCEPTABLE

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

Click Source Link

Document

406 Not Acceptable .

Usage

From source file:com.hp.autonomy.frontend.find.idol.configuration.IdolConfigurationController.java

@SuppressWarnings("ProhibitedExceptionDeclared")
@RequestMapping(value = "/config", method = { RequestMethod.POST, RequestMethod.PUT })
public ResponseEntity<?> saveConfig(@RequestBody final IdolFindConfigWrapper configResponse) throws Exception {
    log.info(Markers.AUDIT, "REQUESTED UPDATE CONFIGURATION");

    try {/*  ww w. j av a 2 s.  co m*/
        configService.updateConfig(configResponse.getConfig());
        final Object response = configService.getConfigResponse();
        log.info(Markers.AUDIT, "UPDATED CONFIGURATION");
        return new ResponseEntity<>(response, HttpStatus.OK);
    } catch (final ConfigException ce) {
        return new ResponseEntity<>(Collections.singletonMap("exception", ce.getMessage()),
                HttpStatus.NOT_ACCEPTABLE);
    } catch (final ConfigValidationException cve) {
        return new ResponseEntity<>(Collections.singletonMap("validation", cve.getValidationErrors()),
                HttpStatus.NOT_ACCEPTABLE);
    }
}

From source file:com.greglturnquist.springagram.fileservice.mongodb.ApplicationController.java

@RequestMapping(method = RequestMethod.POST, value = "/files")
public ResponseEntity<?> newFile(@RequestParam("name") String filename,
        @RequestParam("file") MultipartFile file) {

    if (!file.isEmpty()) {
        try {/*from  www . ja va 2 s  .  com*/
            this.fileService.saveFile(file.getInputStream(), filename);

            Link link = linkTo(methodOn(ApplicationController.class).getFile(filename)).withRel(filename);
            return ResponseEntity.created(new URI(link.getHref())).build();

        } catch (IOException | URISyntaxException e) {
            return ResponseEntity.badRequest().body("Couldn't process the request");
        }
    } else {
        return ResponseEntity.status(HttpStatus.NOT_ACCEPTABLE).body("File is empty");
    }
}

From source file:su90.mybatisdemo.web.endpoints.EmployeesEndpoints.java

@RequestMapping(value = "/set/", method = RequestMethod.POST, consumes = {
        MediaType.APPLICATION_JSON_UTF8_VALUE }, produces = { MediaType.TEXT_PLAIN_VALUE })
@ApiOperation(value = "create one employee if possible")
public ResponseEntity<Void> createEmployee(@RequestBody EmployeeIn employeeIn) {
    if (employeeIn.email == null) {
        return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
    }/* ww w  . ja  va 2 s  . co m*/
    if (employeesService.hasEntityWithEmail(employeeIn.email)) {
        return new ResponseEntity<>(HttpStatus.CONFLICT);
    }

    if (employeeIn.job_id != null && jobsService.getEntryById(employeeIn.job_id) == null) {
        return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
    }

    if (employeeIn.manager_id != null && employeesService.getEntryById(employeeIn.manager_id) == null) {
        return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
    }

    if (employeeIn.department_id != null && departmentsService.getEntryById(employeeIn.department_id) == null) {
        return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
    }

    Long thekey = employeesService.saveEntry(employeeIn.getDomain());

    if (thekey != null) {
        HttpHeaders headers = new HttpHeaders();
        headers.setLocation(
                UriUtils.generateUri(MvcUriComponentsBuilder.on(EmployeesEndpoints.class).getOne(thekey)));
        return new ResponseEntity<>(headers, HttpStatus.CREATED);
    } else {
        return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
    }

}

From source file:com.ge.predix.acs.commons.web.RestErrorHandlerTest.java

@Test
public void testRestApiException() {
    RestErrorHandler errorHandler = new RestErrorHandler();

    HttpServletRequest request = new MockHttpServletRequest();
    HttpServletResponse response = new MockHttpServletResponse();
    Exception e = new RestApiException(HttpStatus.NOT_ACCEPTABLE, "NOT_ACCEPTABLE",
            "Not acceptable Error Message");

    ModelAndView errorResponse = errorHandler.createApiErrorResponse(e, request, response);

    // Custom error status code 406
    Assert.assertEquals(response.getStatus(), HttpStatus.NOT_ACCEPTABLE.value());

    Assert.assertNotNull(errorResponse);
    Assert.assertNotNull(errorResponse.getModel().get("ErrorDetails"));

    // Response payload with customer error code and message
    assertRestApiErrorResponse(errorResponse, "NOT_ACCEPTABLE", "Not acceptable Error Message");

}

From source file:com.sms.server.controller.MediaController.java

@RequestMapping(value = "/{id}/contents", method = RequestMethod.GET)
public ResponseEntity<List<MediaElement>> getMediaElementsByParentID(@PathVariable("id") Long id) {
    MediaElement parentDirectory = mediaDao.getMediaElementByID(id);

    if (parentDirectory == null) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }/*  w w w.ja  v a  2 s. c o m*/

    if (parentDirectory.getType() != MediaElementType.DIRECTORY) {
        return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
    }

    List<MediaElement> mediaElements = mediaDao.getMediaElementsByParentPath(parentDirectory.getPath());

    if (mediaElements == null) {
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

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

From source file:com.sms.server.controller.AdminController.java

@RequestMapping(value = "/user/role", method = RequestMethod.POST, headers = {
        "Content-type=application/json" })
@ResponseBody//from w  w  w . jav  a 2 s .c  om
public ResponseEntity<String> createUserRole(@RequestBody UserRole userRole) {
    // Check mandatory fields.
    if (userRole.getUsername() == null || userRole.getRole() == null) {
        return new ResponseEntity<>("Missing required parameter.", HttpStatus.BAD_REQUEST);
    }

    // Check unique fields
    if (userDao.getUserByUsername(userRole.getUsername()) == null) {
        return new ResponseEntity<>("Username is not registered.", HttpStatus.NOT_ACCEPTABLE);
    }

    // Add user role to the database.
    if (!userDao.createUserRole(userRole)) {
        LogService.getInstance().addLogEntry(Level.ERROR, CLASS_NAME,
                "Error adding role'" + userRole.getRole() + "' to user '" + userRole.getUsername() + "'.",
                null);
        return new ResponseEntity<>("Error adding user role to database.", HttpStatus.INTERNAL_SERVER_ERROR);
    }

    LogService.getInstance().addLogEntry(Level.INFO, CLASS_NAME,
            "Added role'" + userRole.getRole() + "' to user '" + userRole.getUsername() + "'.", null);
    return new ResponseEntity<>("User role added successfully.", HttpStatus.CREATED);
}

From source file:just.aRest.project.DAO.ApplDAOImpl.java

@Override
public ResponseEntity<String> createApplication(Application app) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    String query = "SELECT email FROM Client WHERE username = ? LIMIT 1";
    try {//w w w .  j  a  v a  2  s  .  c  om
        //before creating the application check if the user exists
        String checker0 = jdbcTemplate.queryForObject(query, new Object[] { app.getUsername() }, String.class);
        int checker = 0;
        if (checker0.equals("") || checker0 == null)
            checker = 0;
        else
            checker = 1;
        if (checker == 1) {
            //Create the application
            query = "INSERT INTO Application VALUES(?,?,?,?,?,?,?,0,0,?,10)";
            checker = jdbcTemplate.update(query, app.getApp_code(), app.getAmount(), app.getRepay_Time(),
                    app.getBuy_type(), app.getDrivers_license(), app.getTaxes(), app.getTekmiriwsi(),
                    app.getUsername());
            //enter empty field for Directors Commentary
            if (checker == 1) {
                query = "INSERT INTO Director VALUES(\"\",?)";
                checker = jdbcTemplate.update(query, app.getApp_code());
                if (checker == 1) {
                    //Return user for successful completion
                    return new ResponseEntity<String>("Opperation completed successfully", HttpStatus.OK);
                } else {
                    //inform him that something went wrong
                    return new ResponseEntity<String>("Very rare issue,contact technical support",
                            HttpStatus.NOT_ACCEPTABLE);
                }
            } else {
                return new ResponseEntity<String>("Fill the form correctly", HttpStatus.NOT_ACCEPTABLE);
            }
        } else {
            return new ResponseEntity<String>("User doesn\'t exist", HttpStatus.NOT_ACCEPTABLE);
        }

    } catch (EmptyResultDataAccessException e) {
        return new ResponseEntity<String>("User doesn\'t exist", HttpStatus.NOT_ACCEPTABLE);
    } catch (NumberFormatException e) {
        return new ResponseEntity<String>("Form filled incorrectly", HttpStatus.NOT_ACCEPTABLE);
    }

}

From source file:com.novation.eligibility.rest.spring.web.servlet.handler.DefaultRestErrorResolver.java

protected final Map<String, String> createDefaultExceptionMappingDefinitions() {

    Map<String, String> m = new LinkedHashMap<String, String>();

    // 400/*from   ww w.  j av  a 2  s  . co  m*/
    applyDef(m, HttpMessageNotReadableException.class, HttpStatus.BAD_REQUEST);
    applyDef(m, MissingServletRequestParameterException.class, HttpStatus.BAD_REQUEST);
    applyDef(m, TypeMismatchException.class, HttpStatus.BAD_REQUEST);
    applyDef(m, "javax.validation.ValidationException", HttpStatus.BAD_REQUEST);

    // 404
    applyDef(m, NoSuchRequestHandlingMethodException.class, HttpStatus.NOT_FOUND);
    applyDef(m, "org.hibernate.ObjectNotFoundException", HttpStatus.NOT_FOUND);

    // 405
    applyDef(m, HttpRequestMethodNotSupportedException.class, HttpStatus.METHOD_NOT_ALLOWED);

    // 406
    applyDef(m, HttpMediaTypeNotAcceptableException.class, HttpStatus.NOT_ACCEPTABLE);

    // 409
    //can't use the class directly here as it may not be an available dependency:
    applyDef(m, "org.springframework.dao.DataIntegrityViolationException", HttpStatus.CONFLICT);

    // 415
    applyDef(m, HttpMediaTypeNotSupportedException.class, HttpStatus.UNSUPPORTED_MEDIA_TYPE);

    return m;
}