Java Code Examples for org.springframework.http.HttpStatus#UNSUPPORTED_MEDIA_TYPE

The following examples show how to use org.springframework.http.HttpStatus#UNSUPPORTED_MEDIA_TYPE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlobalHandlerExceptionResolver.java    From fast-family-master with Apache License 2.0 5 votes vote down vote up
@ResponseStatus(value = HttpStatus.UNSUPPORTED_MEDIA_TYPE)
@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
public Response handleHttpMediaTypeNotSupportedException(
        HttpMediaTypeNotSupportedException e) {
    logError("httpMediaTypeNotSupportedException", e.getMessage(), e);
    return Response
            .fail(415,
                    String.format("媒体类型%s错误", e.getContentType()));
}
 
Example 2
Source File: UnsupportedMediaTypeStatusException.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Constructor for when trying to encode from or decode to a specific Java type.
 * @since 5.1
 */
public UnsupportedMediaTypeStatusException(@Nullable MediaType contentType, List<MediaType> supportedTypes,
		@Nullable ResolvableType bodyType) {

	super(HttpStatus.UNSUPPORTED_MEDIA_TYPE, initReason(contentType, bodyType));
	this.contentType = contentType;
	this.supportedMediaTypes = Collections.unmodifiableList(supportedTypes);
	this.bodyType = bodyType;
}
 
Example 3
Source File: RestControllerExceptionTranslator.java    From hsweb-framework with Apache License 2.0 5 votes vote down vote up
/**
 * ContentType不支持异常
 * 比如:@RequestBody注解,需要Content-Type: application/json, 但是请求未指定使用的默认的 Content-Type: application/x-www-form-urlencoded
 */
@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
@ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
ResponseMessage handleException(HttpMediaTypeNotSupportedException exception) {
    return ResponseMessage.error(HttpStatus.UNSUPPORTED_MEDIA_TYPE.value(),
            "不支持的请求类型:" + exception.getContentType().toString())
            .result(exception.getSupportedMediaTypes()
                    .stream()
                    .map(MediaType::toString)
                    .collect(Collectors.toList()));
}
 
Example 4
Source File: DefaultExceptionAdvice.java    From Taroco with Apache License 2.0 5 votes vote down vote up
@ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
@ExceptionHandler({HttpMediaTypeNotSupportedException.class})
public ResponseEntity handleHttpMediaTypeNotSupportedException(HttpMediaTypeNotSupportedException e) {
    LOGGER.error("不支持当前媒体类型", e);
    Response response = Response.failure(DefaultError.CONTENT_TYPE_NOT_SUPPORT);
    response.setExtMessage(e.getMessage());
    return new ResponseEntity<>(response, HttpStatus.UNSUPPORTED_MEDIA_TYPE);
}
 
Example 5
Source File: GlobalControllerAdvice.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
@ResponseStatus(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE)
public ResponseEntity<ErrorMessage> handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex
) {
	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, HttpStatus.UNSUPPORTED_MEDIA_TYPE);
}
 
Example 6
Source File: GlobalControllerAdvice.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
@ResponseStatus(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE)
public ResponseEntity<ErrorMessage> handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex
) {
	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, HttpStatus.UNSUPPORTED_MEDIA_TYPE);
}
 
Example 7
Source File: GlobalControllerAdvice.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
@ResponseStatus(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE)
public ResponseEntity<ErrorMessage> handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex
) {
	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, HttpStatus.UNSUPPORTED_MEDIA_TYPE);
}
 
Example 8
Source File: UnsupportedMediaTypeStatusException.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Constructor for when trying to encode from or decode to a specific Java type.
 * @since 5.1
 */
public UnsupportedMediaTypeStatusException(@Nullable MediaType contentType, List<MediaType> supportedTypes,
		@Nullable ResolvableType bodyType) {

	super(HttpStatus.UNSUPPORTED_MEDIA_TYPE, initReason(contentType, bodyType));
	this.contentType = contentType;
	this.supportedMediaTypes = Collections.unmodifiableList(supportedTypes);
	this.bodyType = bodyType;
}
 
Example 9
Source File: UnsupportedMediaTypeStatusException.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Constructor for when the specified Content-Type is invalid.
 */
public UnsupportedMediaTypeStatusException(@Nullable String reason) {
	super(HttpStatus.UNSUPPORTED_MEDIA_TYPE, reason);
	this.contentType = null;
	this.supportedMediaTypes = Collections.emptyList();
	this.bodyType = null;
}
 
Example 10
Source File: GlobalExceptionHandler.java    From SENS with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 415 - Unsupported Media Type
 */
@ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
public String handleHttpMediaTypeNotSupportedException(HttpMediaTypeNotSupportedException e, Model model) {
    log.error("不支持当前媒体类型", e);
    String message = "【不支持当前媒体类型】" + e.getMessage();
    model.addAttribute("message", message);
    model.addAttribute("code", 415);
    return viewName;
}
 
Example 11
Source File: GlobalExceptionHand.java    From spring-boot-shiro with Apache License 2.0 5 votes vote down vote up
/**
 * 415 - Unsupported Media Type
 */
@ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
public Response handleHttpMediaTypeNotSupportedException(Exception e) {
    String msg = "不支持当前媒体类型!";
    log.error(msg, e);
    return new Response().failure(msg);
}
 
Example 12
Source File: ErrorController.java    From kakaopay-coupon with MIT License 5 votes vote down vote up
@ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
@ResponseBody
public ErrorInfo handleNotJsonRequest(HttpServletRequest req, Exception ex) {
    log.info("handleNotJsonRequest - Only support Content type 'application/json'");
    return new ErrorInfo(req.getRequestURL().toString(), "Only support Content type 'application/json'", NOT_JSON_MEDIA_TYPE);
}
 
Example 13
Source File: GlobalExceptionHandler.java    From Spring-Boot-Book with Apache License 2.0 5 votes vote down vote up
/**
 * 415 - Unsupported Media Type
 */
@ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
public Map<String, Object> handleHttpMediaTypeNotSupportedException(HttpMediaTypeNotSupportedException e) {
    logger.error("不支持当前媒体类型", e);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("rspCode", 415);
    map.put("rspMsg", e.getMessage());
    //发生异常进行日志记录,写入数据库或者其他处理,此处省略
    return map;
}
 
Example 14
Source File: MediaTypeNotSupportedStatusException.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Constructor for when the Content-Type is not supported.
 */
public MediaTypeNotSupportedStatusException(List<MediaType> supportedMediaTypes) {
	super(HttpStatus.UNSUPPORTED_MEDIA_TYPE, "Unsupported media type", null);
	this.supportedMediaTypes = Collections.unmodifiableList(supportedMediaTypes);
}
 
Example 15
Source File: ExceptionAdvice.java    From open-capacity-platform with Apache License 2.0 4 votes vote down vote up
/**
 * 返回状态码:415
 */
@ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
@ExceptionHandler({HttpMediaTypeNotSupportedException.class})
public Result handleHttpMediaTypeNotSupportedException(HttpMediaTypeNotSupportedException e) {
    return defHandler("不支持当前媒体类型", e);
}
 
Example 16
Source File: DefaultExceptionAdvice.java    From microservices-platform with Apache License 2.0 4 votes vote down vote up
/**
 * 返回状态码:415
 */
@ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
@ExceptionHandler({HttpMediaTypeNotSupportedException.class})
public Result handleHttpMediaTypeNotSupportedException(HttpMediaTypeNotSupportedException e) {
    return defHandler("不支持当前媒体类型", e);
}
 
Example 17
Source File: MediaTypeNotSupportedStatusException.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Constructor for when the Content-Type is invalid.
 */
public MediaTypeNotSupportedStatusException(String reason) {
	super(HttpStatus.UNSUPPORTED_MEDIA_TYPE, reason);
	this.supportedMediaTypes = Collections.emptyList();
}
 
Example 18
Source File: BaseExceptionHandlerAdvice.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE) // 415
@ExceptionHandler(FlowableContentNotSupportedException.class)
@ResponseBody
public ErrorInfo handleNotSupported(FlowableContentNotSupportedException e) {
    return new ErrorInfo("Content is not supported", e);
}
 
Example 19
Source File: UnsupportedFormatException.java    From webanno with Apache License 2.0 4 votes vote down vote up
public UnsupportedFormatException(String aFormat, Object... aArgs)
{
    super(String.format(aFormat, aArgs), HttpStatus.UNSUPPORTED_MEDIA_TYPE);
}
 
Example 20
Source File: ExceptionHandlerAdvice.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE) // 415
@ExceptionHandler(ActivitiDmnContentNotSupportedException.class)
@ResponseBody
public ErrorInfo handleNotSupported(ActivitiDmnContentNotSupportedException e) {
  return new ErrorInfo("Content is not supported", e);
}