org.springframework.http.MediaType#toString ( )源码实例Demo

下面列出了org.springframework.http.MediaType#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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);
}
 
@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);
}
 
@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);
}
 
/**
 * Add a header to the request. Values are always added.
 * @param name the header name
 * @param values one or more header values
 */
public MockHttpServletRequestBuilder header(String name, Object... values) {
	if ("Content-Type".equalsIgnoreCase(name)) {
		List<MediaType> mediaTypes = MediaType.parseMediaTypes(StringUtils.arrayToCommaDelimitedString(values));
		this.contentType = MediaType.toString(mediaTypes);
	}
	addToMultiValueMap(this.headers, name, values);
	return this;
}
 
/**
 * Add all headers to the request. Values are always added.
 * @param httpHeaders the headers and values to add
 */
public MockHttpServletRequestBuilder headers(HttpHeaders httpHeaders) {
	MediaType mediaType = httpHeaders.getContentType();
	if (mediaType != null) {
		this.contentType = mediaType.toString();
	}
	for (String name : httpHeaders.keySet()) {
		Object[] values = ObjectUtils.toObjectArray(httpHeaders.get(name).toArray());
		addToMultiValueMap(this.headers, name, values);
	}
	return this;
}
 
@Override
public ContentTypeHeader contentTypeHeader() {
	MediaType contentType = this.result.getRequestHeaders().getContentType();
	if (contentType == null) {
		return null;
	}
	return new ContentTypeHeader(contentType.toString());
}
 
@Override
@Nullable
public Header getContentType() {
	MediaType contentType = this.headers.getContentType();
	return (contentType != null ? new BasicHeader("Content-Type", contentType.toString()) : null);
}
 
private String getContentType() {
	MediaType contentType = getHeaders().getContentType();
	return contentType != null ? contentType.toString() : MediaType.APPLICATION_OCTET_STREAM_VALUE;
}
 
源代码9 项目: spring-analysis-note   文件: MockPart.java
@Override
@Nullable
public String getContentType() {
	MediaType contentType = this.headers.getContentType();
	return (contentType != null ? contentType.toString() : null);
}
 
@Override
public String getContentType() {
	MediaType type = this.outputMessage.getHeaders().getContentType();
	return (type != null ? type.toString() : null);
}
 
源代码11 项目: spring-analysis-note   文件: MockPart.java
@Override
@Nullable
public String getContentType() {
	MediaType contentType = this.headers.getContentType();
	return (contentType != null ? contentType.toString() : null);
}
 
@Override
@Nullable
public Header getContentType() {
	MediaType contentType = this.headers.getContentType();
	return (contentType != null ? new BasicHeader("Content-Type", contentType.toString()) : null);
}
 
private String getContentType() {
	MediaType contentType = getHeaders().getContentType();
	return contentType != null ? contentType.toString() : MediaType.APPLICATION_OCTET_STREAM_VALUE;
}
 
源代码14 项目: java-technology-stack   文件: MockPart.java
@Override
@Nullable
public String getContentType() {
	MediaType contentType = this.headers.getContentType();
	return (contentType != null ? contentType.toString() : null);
}
 
@Override
public String getContentType() {
	MediaType type = this.outputMessage.getHeaders().getContentType();
	return (type != null ? type.toString() : null);
}
 
源代码16 项目: java-technology-stack   文件: MockPart.java
@Override
@Nullable
public String getContentType() {
	MediaType contentType = this.headers.getContentType();
	return (contentType != null ? contentType.toString() : null);
}
 
@Override
public Header getContentType() {
	MediaType contentType = this.headers.getContentType();
	return (contentType != null ? new BasicHeader("Content-Type", contentType.toString()) : null);
}
 
@Override
public Header getContentType() {
	MediaType contentType = this.headers.getContentType();
	return (contentType != null ? new BasicHeader("Content-Type", contentType.toString()) : null);
}
 
@Override
public String getContentType() {
	MediaType type = this.outputMessage.getHeaders().getContentType();
	return (type != null ? type.toString() : null);
}
 
源代码20 项目: raml-tester   文件: SpringHttpRamlMessage.java
protected String contentTypeOf(HttpHeaders headers) {
    final MediaType contentType = headers.getContentType();
    return contentType == null ? null : contentType.toString();
}