本文整理匯總了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);
}