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


Java RequestContext.set方法代码示例

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


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

示例1: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
public Object run() {
	try {
		RequestContext context = getCurrentContext();
		InputStream in = (InputStream) context.get("requestEntity");
		if (in == null) {
			in = context.getRequest().getInputStream();
		}
		String body = StreamUtils.copyToString(in, Charset.forName("UTF-8"));
		// body = "request body modified via set('requestEntity'): "+ body;
		body = body.toUpperCase();
		context.set("requestEntity", new ByteArrayInputStream(body.getBytes("UTF-8")));
	}
	catch (IOException e) {
		rethrowRuntimeException(e);
	}
	return null;
}
 
开发者ID:spring-cloud-samples,项目名称:sample-zuul-filters,代码行数:18,代码来源:UppercaseRequestEntityFilter.java

示例2: run

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

  // span is a child of one created in servlet-filter
  Span span = tracer.buildSpan(ctx.getRequest().getMethod())
      .withTag(Tags.COMPONENT.getKey(), COMPONENT_NAME)
      .startManual();

  tracer.inject(span.context(), Format.Builtin.HTTP_HEADERS,
      new TextMapInjectAdapter(ctx.getZuulRequestHeaders()));

  ctx.set(CONTEXT_SPAN_KEY, span);

  return null;
}
 
开发者ID:opentracing-contrib,项目名称:java-spring-cloud,代码行数:17,代码来源:TracePreZuulFilter.java

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

示例4: run

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

    logger.info("Send {} request to {}", request.getMethod(), request.getRequestURL().toString());

    String accessToken = request.getParameter("access_token");
    if (accessToken == null) {
        logger.warn("Access token is empty");
        /*
        context.setSendZuulResponse(false);
        context.setResponseStatusCode(401);
        */
        RuntimeException e = new RuntimeException("An exception.");
        context.set("error.status_code", HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        context.set("error.exception", e);
        throw e;
    }

    logger.info("Access ok");

    return null;
}
 
开发者ID:tduni,项目名称:learn-spring-cloud,代码行数:25,代码来源:AccessFilter.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

示例6: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
	RequestContext ctx = RequestContext.getCurrentContext();
	Throwable throwable = RequestContext.getCurrentContext().getThrowable();
	log.error("this is a ErrorFilter : {}", throwable.getCause().getMessage());
	ctx.set("error.status_code", HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
	ctx.set("error.exception", throwable.getCause());
	return null;
}
 
开发者ID:rongwei84n,项目名称:Auts_Assert_manager,代码行数:10,代码来源:ErrorFilter.java

示例7: run

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

    context.set("error.status_code", HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    context.set("exception", throwable.getCause());

    return null;
}
 
开发者ID:tduni,项目名称:learn-spring-cloud,代码行数:11,代码来源:ErrorFilter.java


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