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


Java RequestContext.getResponse方法代码示例

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


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

示例1: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {

    try {
        RequestContext ctx = RequestContext.getCurrentContext();
        HttpServletResponse response = ctx.getResponse();

        if (!rateLimiter.tryAcquire()) {
            HttpStatus httpStatus = HttpStatus.TOO_MANY_REQUESTS;

            response.setContentType(MediaType.TEXT_PLAIN_VALUE);
            response.setStatus(httpStatus.value());
            ctx.setResponseStatusCode(httpStatus.value());
            ctx.setSendZuulResponse(false);
        }
    } catch (Exception e) {
        ReflectionUtils.rethrowRuntimeException(e);
    }
    return null;
}
 
开发者ID:kenly333,项目名称:service-hive,代码行数:21,代码来源:RateLimitZuulFilter.java

示例2: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
  try {
    RequestContext currentContext = RequestContext.getCurrentContext();
    HttpServletResponse response = currentContext.getResponse();

    if (!rateLimiter.tryAcquire()) {

      response.setContentType(MediaType.TEXT_PLAIN_VALUE);
      response.setStatus(this.tooManyRequests.value());
      response.getWriter().append(this.tooManyRequests.getReasonPhrase());

      currentContext.setSendZuulResponse(false);

      throw new ZuulException(this.tooManyRequests.getReasonPhrase(),
          this.tooManyRequests.value(),
          this.tooManyRequests.getReasonPhrase());
    }
  } catch (Exception e) {
    ReflectionUtils.rethrowRuntimeException(e);
  }
  return null;
}
 
开发者ID:drm317,项目名称:cloud-native-reference,代码行数:24,代码来源:ThrottlingPreFilter.java

示例3: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
  logger.info("Moving cookies from byte stream to header");
  RequestContext ctx = RequestContext.getCurrentContext();

  String rawCookies = responseBodyOf(ctx);
  Map<String, String> cookies = jsonOf(ctx, rawCookies);

  HttpServletResponse response = ctx.getResponse();
  for (Map.Entry<String, String> entry : cookies.entrySet()) {
    Cookie cookie = new Cookie(entry.getKey(), entry.getValue());
    cookie.setPath("/");
    response.addCookie(cookie);
  }
  ctx.setResponse(response);
  ctx.setResponseBody("logged in");

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

示例4: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
public Object run() {
	RequestContext context = RequestContext.getCurrentContext();
	HttpServletResponse servletResponse = context.getResponse();
	servletResponse.addHeader("X-Foo",
			UUID.randomUUID().toString());
	return null;
}
 
开发者ID:spring-cloud-samples,项目名称:sample-zuul-filters,代码行数:8,代码来源:AddResponseHeaderFilter.java

示例5: doFieldMappingRun

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
private void doFieldMappingRun() {
  ZuulRouteDto route = this.loadRoute();
  Map<String, String> fieldMap = route.getMappingField();
  RequestContext ctx = RequestContext.getCurrentContext();
  HttpServletRequest request = ctx.getRequest();
  HttpServletResponse response = ctx.getResponse();
  Map<String, String> valueMap = Maps.newHashMap();
  for (Map.Entry<String, String> entry : fieldMap.entrySet()) {
    String sourceFieldName = entry.getKey();
    String targetFieldName = entry.getValue();
    String fieldValue = request.getParameter(sourceFieldName);
    valueMap.put(targetFieldName, fieldValue);
  }
  if (valueMap.isEmpty()) {
    ctx.set("error.status_code", 400);
    ctx.set("error.message", "param can not be empty");
  } else {
    try {
      String result = remoteComponent.callRemoteService(route.getServiceName(), route.getGroup(),
          route.getVersion(), route.getMethod(), valueMap);
      response.setStatus(HttpServletResponse.SC_OK);
      response.setContentType("application/json; charset=UTF-8");
      response.getWriter().print(result);
    } catch (Throwable e) {
      ctx.set("error.status_code", 500);
      ctx.set("error.message", e.getMessage());
      ctx.set("error.exception", e);
    }
  }
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:31,代码来源:GrpcRemoteRouteFilter.java


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