當前位置: 首頁>>代碼示例>>Java>>正文


Java NativeWebRequest.getHeader方法代碼示例

本文整理匯總了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);
}
 
開發者ID:rvillars,項目名稱:edoras-one-initializr,代碼行數:21,代碼來源:WebConfig.java

示例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();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:HeaderContentNegotiationStrategy.java

示例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);
}
 
開發者ID:redlink-gmbh,項目名稱:smarti,代碼行數:9,代碼來源:RestServiceConfiguration.java


注:本文中的org.springframework.web.context.request.NativeWebRequest.getHeader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。