当前位置: 首页>>代码示例>>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;未经允许,请勿转载。