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


Java RequestContext.setResponseBody方法代码示例

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


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

示例1: run

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

    log.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString()));

    Object accessToken = request.getParameter("accessToken");
    if(accessToken == null) {
        log.warn("access token is empty");
        ctx.setSendZuulResponse(false);
        ctx.setResponseBody("401");
        ctx.setResponseStatusCode(401);
        return null;
    }
    log.info("access token ok");
    return null;
}
 
开发者ID:DemoHubs,项目名称:hlxy-docker,代码行数:19,代码来源:AccessFilter.java

示例2: 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

示例3: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
    RequestContext ctx= RequestContext.getCurrentContext();
    HttpServletRequest req=ctx.getRequest();
    String ipAddr=this.getIpAddr(req);
    logger.info("请求IP地址为:[{}]",ipAddr);
   //配置本地IP白名单,生产环境可放入数据库或者redis中
    List<String> ips=new ArrayList<String>();
    ips.add("0:0:0:0:0:0:0:1");
    ips.add("172.0.0.1");
    ips.add("10.17.30.1");


    if(!ips.contains(ipAddr)){
        logger.info("IP地址校验不通过!!!");
        ctx.setResponseStatusCode(401);
        ctx.setSendZuulResponse(false);
        ctx.setResponseBody("IpAddr is forbidden!");
    }else{
        logger.info("IP地址校验通过.");
    }
    return null;
}
 
开发者ID:gengkangkang,项目名称:springcloud,代码行数:24,代码来源:IPFilter.java

示例4: run

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

       Long remainingLimit = null;
	for (RateLimitCheck rl : filterConfig.getRateLimitChecks()) {
		ConsumptionProbe probe = rl.rateLimit(request);
		if (probe != null) {
			if (probe.isConsumed()) {
				remainingLimit = getRemainingLimit(remainingLimit, probe);
			} else {
				context.setResponseStatusCode(HttpStatus.TOO_MANY_REQUESTS.value());
				context.setResponseBody(filterConfig.getHttpResponseBody());
				context.setSendZuulResponse(false);
			}
			if(filterConfig.getStrategy().equals(RateLimitConditionMatchingStrategy.FIRST)) {
				break;
			}
		}
	};

	return null;
}
 
开发者ID:MarcGiffing,项目名称:bucket4j-spring-boot-starter,代码行数:25,代码来源:ServletRateLimitFilter.java

示例5: run

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

       Long remainingLimit = null;
	for (RateLimitCheck rl : filterConfig.getRateLimitChecks()) {
		ConsumptionProbe probe = rl.rateLimit(request);
		if (probe != null) {
			if (probe.isConsumed()) {
				remainingLimit = getRemainingLimit(remainingLimit, probe);
			} else {
				context.setResponseStatusCode(HttpStatus.TOO_MANY_REQUESTS.value());
				context.setResponseBody(filterConfig.getHttpResponseBody());
				context.setSendZuulResponse(false);
				break;
			}
			if(filterConfig.getStrategy().equals(RateLimitConditionMatchingStrategy.FIRST)) {
				break;
			}
		}
	};

	return null;
}
 
开发者ID:MarcGiffing,项目名称:bucket4j-spring-boot-starter,代码行数:26,代码来源:ZuulRateLimitFilter.java

示例6: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    HttpServletRequest request = ctx.getRequest();
    String auth = request.getHeader("Authorization");
    String accessToken = auth.split(" ")[1];
    ctx.set("LimitAccess", Boolean.TRUE);
    try {
        Triple<Long, String, Long> clientTriple = databaseUserDetailService.loadClientByToken(accessToken);
        String user = clientTriple.getMiddle();
        Long intervalInMills = clientTriple.getLeft();
        Long limits = clientTriple.getRight();
        if (intervalInMills != null && intervalInMills != 0l && limits != null && limits != 0l) {
            if (!access(user, intervalInMills, limits)) {
                ctx.set("LimitAccess", Boolean.FALSE);
                ctx.setSendZuulResponse(false);
                ctx.setResponseStatusCode(HttpServletResponse.SC_BAD_REQUEST);
                ctx.setResponseBody("The times of usage is limited");
            }
        }
    } catch (Throwable e) {
    }
    return null;
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:25,代码来源:LimitAccessFilter.java

示例7: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
	log.info("This is a post filter, system throw a RuntimeException");
	RequestContext ctx = RequestContext.getCurrentContext();
	try {
		doSomething();
	} catch (Exception e) {
		/*
		 * ctx.set("error.status_code",
		 * HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
		 * ctx.set("error.exception", e); ctx.set("error.message",
		 * "有一些错误发生");
		 */
		ctx.setResponseStatusCode(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
		ctx.setResponseBody("{\"result\":\"server error\"}");// 返回错误内容
	}
	return null;
}
 
开发者ID:rongwei84n,项目名称:Auts_Assert_manager,代码行数:19,代码来源:ThrowExceptionFilter.java

示例8: apiLimitExceeded

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
/**
 * Create a Zuul response error when the API limit is exceeded.
 */
private void apiLimitExceeded() {
    RequestContext ctx = RequestContext.getCurrentContext();
    ctx.setResponseStatusCode(HttpStatus.TOO_MANY_REQUESTS.value());
    if (ctx.getResponseBody() == null) {
        ctx.setResponseBody("API rate limit exceeded");
        ctx.setSendZuulResponse(false);
    }
}
 
开发者ID:oktadeveloper,项目名称:jhipster-microservices-example,代码行数:12,代码来源:RateLimitingFilter.java

示例9: run

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

    if (!context.getResponseGZipped()) {
        context.getResponse().setCharacterEncoding("UTF-8");
    }

    String rewrittenResponse = rewriteBasePath(context);
    context.setResponseBody(rewrittenResponse);
    return null;
}
 
开发者ID:oktadeveloper,项目名称:jhipster-microservices-example,代码行数:13,代码来源:SwaggerBasePathRewritingFilter.java

示例10: apiLimitExceeded

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
private void apiLimitExceeded() {
    RequestContext ctx = RequestContext.getCurrentContext();
    ctx.setResponseStatusCode(HttpStatus.TOO_MANY_REQUESTS.value());
    if (ctx.getResponseBody() == null) {
        ctx.setResponseBody("API rate limit exceeded");
        ctx.setSendZuulResponse(false);
    }
}
 
开发者ID:ElectronicArmory,项目名称:Armory,代码行数:9,代码来源:RateLimitingFilter.java

示例11: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
public Object run() {
	try {
		RequestContext context = getCurrentContext();
		InputStream stream = context.getResponseDataStream();
		String body = StreamUtils.copyToString(stream, Charset.forName("UTF-8"));
		context.setResponseBody("Modified via setResponseBody(): "+body);
	}
	catch (IOException e) {
		rethrowRuntimeException(e);
	}
	return null;
}
 
开发者ID:spring-cloud-samples,项目名称:sample-zuul-filters,代码行数:13,代码来源:ModifyResponseBodyFilter.java

示例12: apiLimitExceeded

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
/**
 * Create a Zuul response error when the API limit is exceeded.
 */
private static void apiLimitExceeded() {
    RequestContext ctx = RequestContext.getCurrentContext();
    ctx.setResponseStatusCode(HttpStatus.TOO_MANY_REQUESTS.value());
    if (ctx.getResponseBody() == null) {
        ctx.setResponseBody("API rate limit exceeded");
        ctx.setSendZuulResponse(false);
    }
}
 
开发者ID:xm-online,项目名称:xm-gate,代码行数:12,代码来源:RateLimitingFilter.java

示例13: responseBody

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
private String responseBody(RequestContext context) throws IOException {
  try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(STREAM_BUFFER_SIZE.get())) {
    IOUtils.copy(context.getResponseDataStream(), outputStream);
    context.setResponseBody(outputStream.toString());
    return outputStream.toString();
  }
}
 
开发者ID:ServiceComb,项目名称:ServiceComb-Company-WorkShop,代码行数:8,代码来源:CacheUpdateFilter.java


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