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.oolong.platform.web.error.DefaultRestErrorResolver.java

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

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

    // 400//  w  w  w. j a v a  2 s  . c om
    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;
}

From source file:br.com.modoagil.asr.rest.support.RESTErrorHandler.java

/**
 * Manipula exceo para status HTTP {@code 404}
 *
 * @param ex/*from w w  w.  ja  va  2s  .  c om*/
 *            {@link NoSuchRequestHandlingMethodException}
 * @return resposta ao cliente
 */
@ResponseBody
@ExceptionHandler({ NoSuchRequestHandlingMethodException.class })
public Response<E> processNoSuchRequestHandlingMethodException(final NoSuchRequestHandlingMethodException ex) {
    this.logger.info("handleNoSuchRequestHandlingMethodException - Catching: " + ex.getClass().getSimpleName(),
            ex);
    return new ResponseBuilder<E>().success(false)
            .message("No h 'handle' para o mtodo chamado: " + ex.getMethodName())
            .status(HttpStatus.NOT_ACCEPTABLE).build();
}

From source file:com.yang.oa.commons.exception.DefaultRestErrorResolver.java

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

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

    // 400//from  ww  w .  j  a v a 2 s . c  o 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);
    applyDef(m, JlException.class, HttpStatus.BAD_REQUEST);
    //401
    applyDef(m, org.apache.shiro.authz.UnauthorizedException.class, HttpStatus.UNAUTHORIZED);
    applyDef(m, org.apache.shiro.authz.UnauthenticatedException.class, HttpStatus.UNAUTHORIZED);
    // 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;
}

From source file:org.openwms.core.uaa.api.RolesController.java

/**
 * FIXME [scherrer] Comment this//from   w w  w. jav a 2 s. c o m
 *
 * @param role
 * @return
 */
@PutMapping
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public RoleVO save(@RequestBody @Valid RoleVO role) {
    if (role.getId() == null) {
        String msg = translate(ExceptionCodes.ROLE_IS_TRANSIENT, role.getName());
        throw new HttpBusinessException(msg, HttpStatus.NOT_ACCEPTABLE);
    }
    Role toSave = m.map(role, Role.class);
    return m.map(service.save(toSave), RoleVO.class);
}

From source file:org.entitypedia.games.common.api.handlers.DefaultExceptionDetailsResolver.java

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

    // 400//from ww  w  .  ja va 2  s  .c o  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;
}

From source file:edu.mayo.trilliumbridge.webapp.TransformerController.java

protected void doTransform(HttpServletRequest request, HttpServletResponse response, String acceptHeader,
        String formatOverride, Transformer transformer) throws IOException {

    // default to XML if no Accept Header (it should at least be */*, but just in case).
    if (StringUtils.isBlank(acceptHeader)) {
        acceptHeader = MediaType.APPLICATION_ATOM_XML_VALUE;
    }//w  w w.j  a  v  a 2  s.c o  m

    TrilliumBridgeTransformer.Format responseFormat = null;

    if (StringUtils.isNotBlank(formatOverride)) {
        responseFormat = TrilliumBridgeTransformer.Format.valueOf(formatOverride);
    } else {
        String[] accepts = StringUtils.split(acceptHeader, ',');

        for (String accept : accepts) {
            MediaType askedForType = MediaType.parseMediaType(accept);
            if (askedForType.isCompatibleWith(MediaType.TEXT_XML)
                    || askedForType.isCompatibleWith(MediaType.APPLICATION_XML)) {
                responseFormat = TrilliumBridgeTransformer.Format.XML;
            } else if (askedForType.isCompatibleWith(MediaType.TEXT_HTML)
                    || askedForType.isCompatibleWith(MediaType.APPLICATION_XHTML_XML)) {
                responseFormat = TrilliumBridgeTransformer.Format.HTML;
            } else if (askedForType.getType().equals("application")
                    && askedForType.getSubtype().equals("pdf")) {
                responseFormat = TrilliumBridgeTransformer.Format.PDF;
            }

            if (responseFormat != null) {
                break;
            }
        }
    }

    if (responseFormat == null) {
        throw new UserInputException("Cannot return type: " + acceptHeader, HttpStatus.NOT_ACCEPTABLE);
    }

    String contentType;
    switch (responseFormat) {
    case XML:
        contentType = MediaType.APPLICATION_XML_VALUE;
        break;
    case HTML:
        contentType = MediaType.TEXT_HTML_VALUE.toString();
        break;
    case PDF:
        contentType = "application/pdf";
        break;
    default:
        throw new IllegalStateException("Illegal Response Format");
    }

    InputStream inputStream;
    if (request instanceof MultipartHttpServletRequest) {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        MultipartFile multipartFile = multipartRequest.getFile(INPUT_FILE_NAME);
        inputStream = multipartFile.getInputStream();
    } else {
        inputStream = request.getInputStream();
    }

    inputStream = this.checkForUtf8BOMAndDiscardIfAny(this.checkStreamIsNotEmpty(inputStream));

    // create a buffer so we don't use the servlet's output stream unless
    // we get a successful transform, because if we do use it,
    // we can't use the error view anymore.
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    transformer.transform(inputStream, baos, responseFormat);

    try {
        response.setContentType(contentType);
        response.getOutputStream().write(baos.toByteArray());
    } finally {
        IOUtils.closeQuietly(baos);
    }

}

From source file:net.jkratz.igdb.controller.advice.ErrorController.java

@RequestMapping(produces = "application/json")
@ExceptionHandler(HttpMediaTypeNotAcceptableException.class)
@ResponseStatus(HttpStatus.NOT_ACCEPTABLE)
public @ResponseBody Map<String, Object> handleMediaTypeNotAcceptableException(
        HttpMediaTypeNotAcceptableException ex) {
    logger.warn(ex.getMessage());/* ww w. jav  a 2  s .  com*/
    Map<String, Object> map = Maps.newHashMap();
    map.put("error", "Unsupported Media Type");
    map.put("message", ex.getMessage());
    return map;
}

From source file:br.com.modoagil.asr.rest.support.RESTErrorHandler.java

/**
 * Manipula exceo para status HTTP {@code 406}
 *
 * @param ex/*from  w w  w .j  av  a  2 s.  c o  m*/
 *            {@link HttpMediaTypeNotAcceptableException}
 * @return resposta ao cliente
 */
@ResponseBody
@ExceptionHandler(HttpMediaTypeNotAcceptableException.class)
public Response<E> processHttpMediaTypeNotAcceptableException(final HttpMediaTypeNotAcceptableException ex) {
    this.logger.info("handleHttpMediaTypeNotAcceptableException - Catching: " + ex.getClass().getSimpleName(),
            ex);
    return new ResponseBuilder<E>().success(false).message(ex.getMessage()).status(HttpStatus.NOT_ACCEPTABLE)
            .build();
}

From source file:com.projectx.mvc.servicehandler.quickregister.QuickRegisterHandler.java

@Override
public QuickRegisterSavedEntityDTO addNewCustomer(QuickRegisterEntity customerQuickRegisterEntity)
        throws QuickRegisterDetailsAlreadyPresentException {

    HttpEntity<QuickRegisterEntity> entity = new HttpEntity<QuickRegisterEntity>(customerQuickRegisterEntity);

    ResponseEntity<QuickRegisterSavedEntityDTO> result = restTemplate.exchange(
            env.getProperty("rest.host") + "/customer/quickregister", HttpMethod.POST, entity,
            QuickRegisterSavedEntityDTO.class);

    if (result.getStatusCode() == HttpStatus.CREATED)
        return result.getBody();
    else if (result.getStatusCode() == HttpStatus.NOT_ACCEPTABLE)
        throw new ValidationFailedException();
    else if (result.getStatusCode() == HttpStatus.ALREADY_REPORTED)
        throw new QuickRegisterDetailsAlreadyPresentException();

    throw new ResourceNotFoundException();
}