use of com.netflix.zuul.context.RequestContext in project micro-service by Lovnx.
the class SecondFilter method run.
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
// HttpServletResponse response = ctx.getResponse();
log.info("第二级过滤器!");
log.info("===============");
throw new RuntimeException();
// log.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString()));
// System.out.println(request.getRequestURL());
}
use of com.netflix.zuul.context.RequestContext in project micro-service by Lovnx.
the class ErrorFilter method run.
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
// HttpServletResponse response = ctx.getResponse();
log.info("进入错误异常的过滤器!");
log.info("===============");
// log.info("access token ok");
return null;
}
use of com.netflix.zuul.context.RequestContext in project micro-service by Lovnx.
the class ResultFilter method run.
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
// HttpServletResponse response = ctx.getResponse();
log.info("进入结果处理的过滤器!");
log.info("===============");
// log.info("access token ok");
return null;
}
use of com.netflix.zuul.context.RequestContext in project new-cloud by xie-summer.
the class RedisRateLimitZuulFilter method run.
@Override
public Object run() {
try {
RequestContext currentContext = RequestContext.getCurrentContext();
HttpServletResponse response = currentContext.getResponse();
if (!redisTemplate.hasKey(TIME_KEY)) {
redisTemplate.opsForValue().set(TIME_KEY, 0, 1, TimeUnit.SECONDS);
}
if (redisTemplate.hasKey(TIME_KEY) && redisTemplate.opsForValue().increment(COUNTER_KEY, 1) > 400) {
HttpStatus httpStatus = HttpStatus.TOO_MANY_REQUESTS;
response.setContentType(MediaType.TEXT_PLAIN_VALUE);
response.setStatus(httpStatus.value());
response.getWriter().append(httpStatus.getReasonPhrase());
currentContext.setSendZuulResponse(false);
throw new RateLimiterException(httpStatus.getReasonPhrase(), httpStatus.value(), httpStatus.getReasonPhrase());
}
} catch (Throwable e) {
ReflectionUtils.rethrowRuntimeException(e);
}
return null;
}
use of com.netflix.zuul.context.RequestContext in project spring-boot-admin by codecentric.
the class ApplicationHeadersFilterTest method test_add_headers_on_matching_route_only.
@Test
public void test_add_headers_on_matching_route_only() {
Application application = Application.create("test").withHealthUrl("/health").build();
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("test", "qwertz");
when(routeLocator.getMatchingRoute("/health")).thenReturn(new ApplicationRoute(application, null, null, null, null));
when(headerProvider.getHeaders(application)).thenReturn(httpHeaders);
RequestContext context = creteRequestContext("/health");
RequestContext.testSetCurrentContext(context);
filter.run();
assertThat(context.getZuulRequestHeaders().get("test"), is("qwertz"));
context = creteRequestContext("/foobar");
RequestContext.testSetCurrentContext(context);
filter.run();
assertThat(context.getZuulRequestHeaders().get("test"), nullValue());
}
Aggregations