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


Java RequestContext.getCurrentContext方法代码示例

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


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

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Test
public void run_on_valid_response() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/service1" + DEFAULT_URL);
    RequestContext context = RequestContext.getCurrentContext();
    context.setRequest(request);

    MockHttpServletResponse response = new MockHttpServletResponse();
    context.setResponseGZipped(false);
    context.setResponse(response);

    InputStream in = IOUtils.toInputStream("{\"basePath\":\"/\"}", StandardCharsets.UTF_8);
    context.setResponseDataStream(in);

    filter.run();

    assertEquals("UTF-8", response.getCharacterEncoding());
    assertEquals("{\"basePath\":\"/service1\"}", context.getResponseBody());
}
 
开发者ID:oktadeveloper,项目名称:jhipster-microservices-example,代码行数:19,代码来源:SwaggerBasePathRewritingFilterTest.java

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

示例4: 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 >>> %s", request.getMethod(), request.getRequestURL().toString()));
    Object accessToken = request.getParameter("token");
    if (accessToken == null) {
        log.warn("token is empty");
        ctx.setSendZuulResponse(false);
        ctx.setResponseStatusCode(401);
        try {
            ctx.getResponse().getWriter().write("token is empty");
        } catch (Exception e) {
        }

        return null;
    }
    log.info("ok");
    return null;
}
 
开发者ID:twb0223,项目名称:springcloudproject,代码行数:21,代码来源:MyFilter.java

示例5: filter

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
private void filter() {
  RequestContext context = RequestContext.getCurrentContext();

  if (doesNotContainToken(context)) {
    logger.warn("No token found in request header");
    rejectRequest(context);
  } else {
    String token = token(context);
    ResponseEntity<String> responseEntity = authenticationService.validate(token);
    if (!responseEntity.getStatusCode().is2xxSuccessful()) {
      logger.warn("Unauthorized token {} and request rejected", token);
      rejectRequest(context);
    } else {
      logger.info("Token {} validated", token);
    }
  }
}
 
开发者ID:ServiceComb,项目名称:ServiceComb-Company-WorkShop,代码行数:18,代码来源:AuthenticationAwareFilter.java

示例6: run

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

	HttpSession session = RequestContext.getCurrentContext().getRequest().getSession(false);
	if (session == null) {
		return null;
	}

	AccessTokenRepresentation token = JSON.parse((String) session.getAttribute("token"), AccessTokenRepresentation.class);
	if (token != null) {
		context.addZuulRequestHeader("Authorization", "Bearer " + token.getAccessToken());
	}

	return null;
}
 
开发者ID:PatternFM,项目名称:tokamak,代码行数:17,代码来源:AuthorizationHeaderFilter.java

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

示例8: run

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

//        JwtUser jwtUser = (JwtUser)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//
//        ObjectMapper mapper = new ObjectMapper();
//        try {
//            String json = mapper.writeValueAsString(jwtUser);
//            ctx.addZuulRequestHeader("x-youbang-user", json);
//        }
//        catch (Exception ex){
//            mylog.error(ex.getMessage());
//        }

        mylog.error("run zuul filter");
        return null;
    }
 
开发者ID:capesonlee,项目名称:tangtang-spring-cloud,代码行数:19,代码来源:MyFilter.java

示例9: buildRequestBody

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
private void buildRequestBody(PactDslRequestWithPath pactRequest) throws IOException {
    final RequestContext context = RequestContext.getCurrentContext();
    String requestBody = null;
    InputStream in = (InputStream) context.get("requestEntity");
    if (in == null) {
        in = context.getRequest().getInputStream();

    }
    if (in != null) {
        String encoding = context.getRequest().getCharacterEncoding();
        requestBody = StreamUtils.copyToString(in,
                Charset.forName(encoding != null ? encoding : "UTF-8"));
    }
    if (requestBody != null && requestBody.length() > 0) {
        pactRequest.body(requestBody);
    }
}
 
开发者ID:ddebree,项目名称:pact-proxy,代码行数:18,代码来源:PactRecorderFilter.java

示例10: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
    RequestContext requestContext = RequestContext.getCurrentContext();
    try {
        InputStream in = requestContext.getResponseDataStream();
        StringBuffer result = new StringBuffer();
        byte[] b = new byte[1024];
        for (int n; (n = in.read(b)) != -1; ) {
            result.append(new String(b, 0, n));
        }
        LOGGER.info("接口返回结果:{}", result.toString());
        requestContext.setSendZuulResponse(true);
        requestContext.setResponseStatusCode(200);
        requestContext.setResponseBody(result.toString());
    } catch (Exception e) {
        LOGGER.error("解析返回值异常:{}", e);
    }
    return null;
}
 
开发者ID:hulvyou,项目名称:spring-cloud-template,代码行数:20,代码来源:CustomZuulFilter.java

示例11: shouldFilter

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public boolean shouldFilter() {
  RequestContext ctx = RequestContext.getCurrentContext();
  return ctx.getRequest().getRequestURI().endsWith("/api/login") &&
      ctx.getResponseStatusCode() == 200 &&
      ctx.getResponse().getHeader(SET_COOKIE) == null;
}
 
开发者ID:WillemJiang,项目名称:acmeair,代码行数:8,代码来源:LoginCookieUpdateFilter.java

示例12: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    HttpServletRequest request = ctx.getRequest();
    logger.info(String.format("send request %s failed.", request.getMethod(), request.getRequestURL().toString()));
    return null;
}
 
开发者ID:carycui,项目名称:parkingcloud,代码行数:8,代码来源:ErrorRequestFilter.java

示例13: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
  RequestContext ctx = RequestContext.getCurrentContext();
  HttpServletRequest request = ctx.getRequest();
  PreRequestLogFilter.LOGGER.info(String.format("send %s request to %s", request.getMethod(), request.getRequestURL().toString()));
  return null;
}
 
开发者ID:itmuch,项目名称:spring-cloud-docker-microservice-book-code,代码行数:8,代码来源:PreRequestLogFilter.java

示例14: run

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

  clientHandler.handleReceive(context.getResponse(), null, tracer.currentSpan());
  log.debug("Closed span {} for {}", tracer.currentSpan(), context.getRequest().getMethod());

  return null;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:11,代码来源:TracePostZuulFilter.java

示例15: 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.setResponseStatusCode(401);
        return null;
    }*/
    return null;
}
 
开发者ID:ywtnhm,项目名称:pay-xxpay-master,代码行数:15,代码来源:AccessFilter.java


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