Search in sources :

Example 86 with RequestContext

use of com.netflix.zuul.context.RequestContext in project paascloud-master by paascloud.

the class AuthHeaderFilter method run.

/**
 * Run object.
 *
 * @return the object
 */
@Override
public Object run() {
    log.info("AuthHeaderFilter - 开始鉴权...");
    RequestContext requestContext = RequestContext.getCurrentContext();
    try {
        doSomething(requestContext);
    } catch (Exception e) {
        log.error("AuthHeaderFilter - [FAIL] EXCEPTION={}", e.getMessage(), e);
        throw new BusinessException(ErrorCodeEnum.UAC10011041);
    }
    return null;
}
Also used : BusinessException(com.paascloud.base.exception.BusinessException) RequestContext(com.netflix.zuul.context.RequestContext) ZuulException(com.netflix.zuul.exception.ZuulException) BusinessException(com.paascloud.base.exception.BusinessException)

Example 87 with RequestContext

use of com.netflix.zuul.context.RequestContext in project incubator-servicecomb-java-chassis by apache.

the class TracePostZuulFilter method run.

@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;
}
Also used : SpanInScope(brave.Tracer.SpanInScope) RequestContext(com.netflix.zuul.context.RequestContext)

Example 88 with RequestContext

use of com.netflix.zuul.context.RequestContext in project incubator-servicecomb-java-chassis by apache.

the class TracePreZuulFilter method runFilter.

@Override
public ZuulFilterResult runFilter() {
    RequestContext ctx = RequestContext.getCurrentContext();
    Span span = clientHandler.handleSend(injector, ctx);
    saveHeadersAsInvocationContext(ctx, span);
    SpanInScope scope = tracer.withSpanInScope(span);
    log.debug("Generated tracing span {} for {}", span, ctx.getRequest().getMethod());
    ctx.getRequest().setAttribute(SpanInScope.class.getName(), scope);
    ZuulFilterResult result = super.runFilter();
    log.debug("Result of Zuul filter is [{}]", result.getStatus());
    if (ExecutionStatus.SUCCESS != result.getStatus()) {
        log.debug("The result of Zuul filter execution was not successful thus will close the current span {}", span);
        clientHandler.handleReceive(ctx.getResponse(), result.getException(), span);
        scope.close();
    }
    return result;
}
Also used : SpanInScope(brave.Tracer.SpanInScope) ZuulFilterResult(com.netflix.zuul.ZuulFilterResult) RequestContext(com.netflix.zuul.context.RequestContext) Span(brave.Span)

Example 89 with RequestContext

use of com.netflix.zuul.context.RequestContext in project incubator-servicecomb-java-chassis by apache.

the class ContextHeaderZuulFilter method run.

@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    ctx.addZuulRequestHeader(SRC_MICROSERVICE, microserviceName);
    saveHeadersAsInvocationContext(ctx);
    return null;
}
Also used : RequestContext(com.netflix.zuul.context.RequestContext)

Example 90 with RequestContext

use of com.netflix.zuul.context.RequestContext in project microservices by pwillhan.

the class RateLimitingZuulFilter method run.

@Override
public Object run() {
    try {
        RequestContext currentContext = RequestContext.getCurrentContext();
        HttpServletResponse response = currentContext.getResponse();
        if (!this.rateLimiter.tryAcquire()) {
            response.setStatus(HttpStatus.TOO_MANY_REQUESTS.value());
            response.getWriter().append(HttpStatus.TOO_MANY_REQUESTS.getReasonPhrase());
            currentContext.setSendZuulResponse(false);
        }
    } catch (IOException e) {
        ReflectionUtils.rethrowRuntimeException(e);
    }
    return null;
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) RequestContext(com.netflix.zuul.context.RequestContext) IOException(java.io.IOException)

Aggregations

RequestContext (com.netflix.zuul.context.RequestContext)163 Test (org.junit.Test)59 HttpServletRequest (javax.servlet.http.HttpServletRequest)27 ZuulRoute (org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute)24 Before (org.junit.Before)23 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)22 Set (java.util.Set)10 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)9 ZuulException (com.netflix.zuul.exception.ZuulException)7 InputStream (java.io.InputStream)7 HashSet (java.util.HashSet)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 Route (org.springframework.cloud.netflix.zuul.filters.Route)7 ZuulProperties (org.springframework.cloud.netflix.zuul.filters.ZuulProperties)7 IOException (java.io.IOException)6 HttpServletRequestWrapper (com.netflix.zuul.http.HttpServletRequestWrapper)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 List (java.util.List)4 HttpHeaders (org.springframework.http.HttpHeaders)4 RateLimitCheck (com.giffing.bucket4j.spring.boot.starter.context.RateLimitCheck)3