下面列出了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;
}
@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);
}
@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;
}
@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);
}
@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);
}
protected String contentTypeOf(HttpHeaders headers) {
final MediaType contentType = headers.getContentType();
return contentType == null ? null : contentType.toString();
}