List of usage examples for org.springframework.http MediaType toString
public static String toString(Collection<MediaType> mediaTypes)
From source file:business.CustomResponseEntityExceptionHandler.java
@Override protected ResponseEntity<Object> handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { String unsupported = "Unsupported content type: " + ex.getContentType(); String supported = "Supported content types: " + MediaType.toString(ex.getSupportedMediaTypes()); ErrorMessage errorMessage = new ErrorMessage(unsupported, supported); return new ResponseEntity<Object>(errorMessage, headers, status); }
From source file:com.ns.retailmgr.controller.exception.RestControllerExceptionHandler.java
@Override protected ResponseEntity<Object> handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { String unsupported = "Unsupported content type: " + ex.getContentType(); String supported = "Supported content types: " + MediaType.toString(ex.getSupportedMediaTypes()); RestErrorMessage RestErrorMessage = new RestErrorMessage(unsupported, supported); return new ResponseEntity(RestErrorMessage, headers, status); }
From source file:com.garyclayburg.persistence.repository.CustomResponseEntityExceptionHandler.java
@Override protected ResponseEntity<Object> handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { String unsupported = "Unsupported content type: " + ex.getContentType(); String supported = "Supported content types: " + MediaType.toString(ex.getSupportedMediaTypes()); ErrorMessage errorMessage = new ErrorMessage(unsupported, supported); return new ResponseEntity(errorMessage, headers, status); }
From source file:org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver.java
/** * Handle the case where no {@linkplain org.springframework.http.converter.HttpMessageConverter message converters} * were found for the PUT or POSTed content. * <p>The default implementation sends an HTTP 415 error, sets the "Accept" header, * and returns an empty {@code ModelAndView}. Alternatively, a fallback view could * be chosen, or the HttpMediaTypeNotSupportedException could be rethrown as-is. * @param ex the HttpMediaTypeNotSupportedException to be handled * @param request current HTTP request//from w ww . j a va2 s . c o m * @param response current HTTP response * @param handler the executed handler * @return an empty ModelAndView indicating the exception was handled * @throws IOException potentially thrown from response.sendError() */ protected ModelAndView handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); List<MediaType> mediaTypes = ex.getSupportedMediaTypes(); if (!CollectionUtils.isEmpty(mediaTypes)) { response.setHeader("Accept", MediaType.toString(mediaTypes)); } return new ModelAndView(); }