本文整理汇总了Java中org.springframework.web.context.request.NativeWebRequest.getHeader方法的典型用法代码示例。如果您正苦于以下问题:Java NativeWebRequest.getHeader方法的具体用法?Java NativeWebRequest.getHeader怎么用?Java NativeWebRequest.getHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.context.request.NativeWebRequest
的用法示例。
在下文中一共展示了NativeWebRequest.getHeader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveMediaTypes
import org.springframework.web.context.request.NativeWebRequest; //导入方法依赖的package包/类
@Override
public List<MediaType> resolveMediaTypes(NativeWebRequest request)
throws HttpMediaTypeNotAcceptableException {
String path = urlPathHelper.getPathWithinApplication(
request.getNativeRequest(HttpServletRequest.class));
if (!StringUtils.hasText(path) || !path.equals("/")) { // Only care about "/"
return Collections.emptyList();
}
String userAgent = request.getHeader(HttpHeaders.USER_AGENT);
if (userAgent != null) {
Agent agent = Agent.fromUserAgent(userAgent);
if (agent != null) {
if (AgentId.CURL.equals(agent.getId())
|| AgentId.HTTPIE.equals(agent.getId())) {
return Collections.singletonList(MediaType.TEXT_PLAIN);
}
}
}
return Collections.singletonList(MediaType.APPLICATION_JSON);
}
示例2: resolveMediaTypes
import org.springframework.web.context.request.NativeWebRequest; //导入方法依赖的package包/类
/**
* {@inheritDoc}
* @throws HttpMediaTypeNotAcceptableException if the 'Accept' header cannot be parsed.
*/
@Override
public List<MediaType> resolveMediaTypes(NativeWebRequest webRequest) throws HttpMediaTypeNotAcceptableException {
String acceptHeader = webRequest.getHeader(ACCEPT_HEADER);
try {
if (StringUtils.hasText(acceptHeader)) {
List<MediaType> mediaTypes = MediaType.parseMediaTypes(acceptHeader);
MediaType.sortBySpecificityAndQuality(mediaTypes);
return mediaTypes;
}
}
catch (InvalidMediaTypeException ex) {
throw new HttpMediaTypeNotAcceptableException(
"Could not parse accept header [" + acceptHeader + "]: " + ex.getMessage());
}
return Collections.emptyList();
}
示例3: resolveArgument
import org.springframework.web.context.request.NativeWebRequest; //导入方法依赖的package包/类
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
final String token = webRequest.getHeader("X-Auth-Token");
final Authentication authentication = SecurityContextHolder.getContext()
.getAuthentication();
return new AuthContext(token, authentication);
}