当前位置: 首页>>代码示例>>Java>>正文


Java HttpMediaTypeNotSupportedException.getSupportedMediaTypes方法代码示例

本文整理汇总了Java中org.springframework.web.HttpMediaTypeNotSupportedException.getSupportedMediaTypes方法的典型用法代码示例。如果您正苦于以下问题:Java HttpMediaTypeNotSupportedException.getSupportedMediaTypes方法的具体用法?Java HttpMediaTypeNotSupportedException.getSupportedMediaTypes怎么用?Java HttpMediaTypeNotSupportedException.getSupportedMediaTypes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.HttpMediaTypeNotSupportedException的用法示例。


在下文中一共展示了HttpMediaTypeNotSupportedException.getSupportedMediaTypes方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleHttpMediaTypeNotSupported

import org.springframework.web.HttpMediaTypeNotSupportedException; //导入方法依赖的package包/类
@Override
protected ResponseEntity<Object> handleHttpMediaTypeNotSupported(final HttpMediaTypeNotSupportedException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
	logger.info(ex.getClass().getName());ex.printStackTrace();
	//
	final StringBuilder builder = new StringBuilder();
	builder.append(ex.getContentType());
	builder.append(" media type is not supported. Supported media types are ");

	for (final MediaType type : ex.getSupportedMediaTypes()) {
		builder.append(type + " ");
	}

	final AitException AitException = new AitException(HttpStatus.UNSUPPORTED_MEDIA_TYPE, ex.getLocalizedMessage(), builder.substring(0, builder.length() - 2));
	return handleExceptionInternal(ex, AitException, headers, AitException.getStatus(), request);
}
 
开发者ID:allianzit,项目名称:ait-platform,代码行数:16,代码来源:AitRestExceptionHandler.java

示例2: handleHttpMediaTypeNotSupported

import org.springframework.web.HttpMediaTypeNotSupportedException; //导入方法依赖的package包/类
/**
 * Customize the response for HttpMediaTypeNotSupportedException.
 * <p>This method sets the "Accept" header and delegates to
 * {@link #handleExceptionInternal}.
 * @param ex the exception
 * @param headers the headers to be written to the response
 * @param status the selected response status
 * @param request the current request
 * @return a {@code ResponseEntity} instance
 */
protected ResponseEntity<Object> handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex,
		HttpHeaders headers, HttpStatus status, WebRequest request) {

	List<MediaType> mediaTypes = ex.getSupportedMediaTypes();
	if (!CollectionUtils.isEmpty(mediaTypes)) {
		headers.setAccept(mediaTypes);
	}

	return handleExceptionInternal(ex, null, headers, status, request);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:ResponseEntityExceptionHandler.java

示例3: handleHttpMediaTypeNotSupported

import org.springframework.web.HttpMediaTypeNotSupportedException; //导入方法依赖的package包/类
protected ResponseEntity<Object> handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex, HttpHeaders headers, HttpStatus status, HttpServletRequest request) {
    List mediaTypes = ex.getSupportedMediaTypes();
    if(!CollectionUtils.isEmpty(mediaTypes)) {
        headers.setAccept(mediaTypes);
    }

    return handleExceptionInternal(ex, (Object) null, headers, status, request);
}
 
开发者ID:xmomen,项目名称:easy-mybatis,代码行数:9,代码来源:RestExceptionHandler.java

示例4: handleHttpMediaTypeNotSupported

import org.springframework.web.HttpMediaTypeNotSupportedException; //导入方法依赖的package包/类
/**
 * Customize the response for HttpMediaTypeNotSupportedException.
 * This method sets the "Accept" header and delegates to
 * {@link #handleExceptionInternal(Exception, Object, HttpHeaders, HttpStatus, WebRequest)}.
 * @param ex the exception
 * @param headers the headers to be written to the response
 * @param status the selected response status
 * @param request the current request
 * @return a {@code ResponseEntity} instance
 */
protected ResponseEntity<Object> handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex,
		HttpHeaders headers, HttpStatus status, WebRequest request) {

	List<MediaType> mediaTypes = ex.getSupportedMediaTypes();
	if (!CollectionUtils.isEmpty(mediaTypes)) {
		headers.setAccept(mediaTypes);
	}

	return handleExceptionInternal(ex, null, headers, status, request);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:21,代码来源:ResponseEntityExceptionHandler.java

示例5: createHeaders

import org.springframework.web.HttpMediaTypeNotSupportedException; //导入方法依赖的package包/类
@Override
protected HttpHeaders createHeaders(HttpMediaTypeNotSupportedException ex, HttpServletRequest req) {

    HttpHeaders headers = super.createHeaders(ex, req);
    List<MediaType> mediaTypes = ex.getSupportedMediaTypes();

    if (!isEmpty(mediaTypes)) {
        headers.setAccept(mediaTypes);
    }
    return headers;
}
 
开发者ID:jirutka,项目名称:spring-rest-exception-handler,代码行数:12,代码来源:HttpMediaTypeNotSupportedExceptionHandler.java

示例6: handleHttpMediaTypeNotSupported

import org.springframework.web.HttpMediaTypeNotSupportedException; //导入方法依赖的package包/类
/**
 * 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
 * @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, 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();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:DefaultHandlerExceptionResolver.java

示例7: handleHttpMediaTypeNotSupported

import org.springframework.web.HttpMediaTypeNotSupportedException; //导入方法依赖的package包/类
/**
 * 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
 * @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, 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();
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:23,代码来源:DefaultHandlerExceptionResolver.java


注:本文中的org.springframework.web.HttpMediaTypeNotSupportedException.getSupportedMediaTypes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。