当前位置: 首页>>代码示例>>Java>>正文


Java RequestContext.put方法代码示例

本文整理汇总了Java中com.netflix.zuul.context.RequestContext.put方法的典型用法代码示例。如果您正苦于以下问题:Java RequestContext.put方法的具体用法?Java RequestContext.put怎么用?Java RequestContext.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.netflix.zuul.context.RequestContext的用法示例。


在下文中一共展示了RequestContext.put方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
  RequestContext ctx = RequestContext.getCurrentContext();
  String uri = ctx.get("requestURI").toString();
  String newUri = uri.replaceFirst("^/rest", "");
  logger.info("Rewritten request uri from {} to {}", uri, newUri);
  ctx.put("requestURI", newUri);

  return null;
}
 
开发者ID:WillemJiang,项目名称:acmeair,代码行数:11,代码来源:UriRewriteFilter.java

示例2: shouldFilter

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public boolean shouldFilter() {
	RequestContext ctx = RequestContext.getCurrentContext();
	boolean isRedirect = ctx.getResponseStatusCode() == 302;
	if (!isRedirect)
		return false;

	boolean hasCorrectLocation = false;

	List<Pair<String, String>> zuulResponseHeaders = ctx.getZuulResponseHeaders();
	for (Pair<String, String> zuulResponseHeader : zuulResponseHeaders) {
		if ("Location".equalsIgnoreCase(zuulResponseHeader.first())) {
			HttpServletRequest request = ctx.getRequest();
			String path = urlPathHelper.getPathWithinApplication(request);
			Route route = routeLocator.getMatchingRoute(path);
			UriComponents redirectTo = ServletUriComponentsBuilder
					.fromHttpUrl(zuulResponseHeader.second()).build();
			UriComponents routeLocation = ServletUriComponentsBuilder
					.fromHttpUrl(route.getLocation()).build();

			if (redirectTo.getHost().equalsIgnoreCase(routeLocation.getHost())
					&& redirectTo.getPort() == routeLocation.getPort()) {
				String toLocation = ServletUriComponentsBuilder
						.fromHttpUrl(zuulResponseHeader.second())
						.host(request.getServerName())
						.port(request.getServerPort())
						.replacePath(
								buildRoutePath(route, zuulResponseHeader.second()))
						.build().toUriString();

				ctx.put(REDIRECT_TO_URL, toLocation);
				hasCorrectLocation = true;
				break;
			}
		}
	}

	return hasCorrectLocation;
}
 
开发者ID:mthizo247,项目名称:spring-cloud-netflix-zuul-websocket,代码行数:40,代码来源:ProxyRedirectFilter.java

示例3: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
public Object run() {
	RequestContext ctx = getCurrentContext();
	HttpServletRequest request = ctx.getRequest();
	// put the serviceId in `RequestContext`
	ctx.put("serviceId", request.getParameter("service"));
	return null;
}
 
开发者ID:spring-cloud-samples,项目名称:sample-zuul-filters,代码行数:8,代码来源:QueryParamServiceIdPreFilter.java


注:本文中的com.netflix.zuul.context.RequestContext.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。