本文整理汇总了Java中org.springframework.http.MediaType.getSubtype方法的典型用法代码示例。如果您正苦于以下问题:Java MediaType.getSubtype方法的具体用法?Java MediaType.getSubtype怎么用?Java MediaType.getSubtype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.http.MediaType
的用法示例。
在下文中一共展示了MediaType.getSubtype方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkContentType
import org.springframework.http.MediaType; //导入方法依赖的package包/类
public void checkContentType(String contentType) {
try {
MediaType media = MediaType.parseMediaType(contentType);
// TODO improve the logic here
if (media.getSubtype() != null && !media.getSubtype().contains("xml") && !media.getSubtype().contains("fhir") && !media.getSubtype().contains("json") && !media.getSubtype().contains("plain")) {
log.info("Unsupported media type: " + contentType);
throw new InvalidRequestException("Unsupported media type: sub " + contentType);
} else {
if (!contentType.contains("xml") && !contentType.contains("json")) {
log.info("Unsupported media type: " + contentType);
throw new InvalidRequestException("Unsupported media type: content " + contentType);
}
}
} catch (InvalidMediaTypeException e) {
log.info("Unsupported media type: " + contentType);
throw new InvalidRequestException("Unsupported media type: mime " + contentType);
}
}
示例2: getContentInfo
import org.springframework.http.MediaType; //导入方法依赖的package包/类
/**
* Returns the basic content info from the request.
* @param req WebScriptRequest
* @return BasicContentInfo
*/
private BasicContentInfo getContentInfo(WebScriptRequest req) {
String encoding = "UTF-8";
String contentType = MimetypeMap.MIMETYPE_BINARY;
if (StringUtils.isNotEmpty(req.getContentType()))
{
MediaType media = MediaType.parseMediaType(req.getContentType());
contentType = media.getType()+'/'+media.getSubtype();
if (media.getCharSet() != null)
{
encoding = media.getCharSet().toString();
}
}
return new ContentInfoImpl(contentType, encoding, -1, Locale.getDefault());
}
示例3: getHeaders
import org.springframework.http.MediaType; //导入方法依赖的package包/类
@Override
public HttpHeaders getHeaders() {
if (this.headers == null) {
this.headers = new HttpHeaders();
for (Enumeration<?> headerNames = this.servletRequest.getHeaderNames(); headerNames.hasMoreElements();) {
String headerName = (String) headerNames.nextElement();
for (Enumeration<?> headerValues = this.servletRequest.getHeaders(headerName);
headerValues.hasMoreElements();) {
String headerValue = (String) headerValues.nextElement();
this.headers.add(headerName, headerValue);
}
}
// HttpServletRequest exposes some headers as properties: we should include those if not already present
if (this.headers.getContentType() == null && this.servletRequest.getContentType() != null) {
MediaType contentType = MediaType.parseMediaType(this.servletRequest.getContentType());
this.headers.setContentType(contentType);
}
if (this.headers.getContentType() != null && this.headers.getContentType().getCharSet() == null &&
this.servletRequest.getCharacterEncoding() != null) {
MediaType oldContentType = this.headers.getContentType();
Charset charSet = Charset.forName(this.servletRequest.getCharacterEncoding());
Map<String, String> params = new HashMap<String, String>(oldContentType.getParameters());
params.put("charset", charSet.toString());
MediaType newContentType = new MediaType(oldContentType.getType(), oldContentType.getSubtype(), params);
this.headers.setContentType(newContentType);
}
if (this.headers.getContentLength() == -1 && this.servletRequest.getContentLength() != -1) {
this.headers.setContentLength(this.servletRequest.getContentLength());
}
}
return this.headers;
}