Search in sources :

Example 16 with RequestContext

use of com.netflix.zuul.context.RequestContext in project micro-continuum by codefinity.

the class CustomZuulFilter method run.

@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    ctx.getRequest().setAttribute("custom-attribute", "custom-value");
    System.out.println("Zuul filter run method");
    return null;
}
Also used : RequestContext(com.netflix.zuul.context.RequestContext)

Example 17 with RequestContext

use of com.netflix.zuul.context.RequestContext in project tutorials by eugenp.

the class TokenRelayFilter method run.

@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    Set<String> headers = (Set<String>) ctx.get("ignoredHeaders");
    // We need our JWT tokens relayed to resource servers
    headers.remove("authorization");
    return null;
}
Also used : Set(java.util.Set) RequestContext(com.netflix.zuul.context.RequestContext)

Example 18 with RequestContext

use of com.netflix.zuul.context.RequestContext in project tutorials by eugenp.

the class AccessControlFilter method run.

@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    ctx.setResponseStatusCode(HttpStatus.FORBIDDEN.value());
    if (ctx.getResponseBody() == null && !ctx.getResponseGZipped()) {
        ctx.setSendZuulResponse(false);
    }
    log.debug("Access Control: filtered unauthorized access on endpoint {}", ctx.getRequest().getRequestURI());
    return null;
}
Also used : RequestContext(com.netflix.zuul.context.RequestContext)

Example 19 with RequestContext

use of com.netflix.zuul.context.RequestContext in project tutorials by eugenp.

the class RateLimitingFilter method apiLimitExceeded.

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

Example 20 with RequestContext

use of com.netflix.zuul.context.RequestContext in project tutorials by eugenp.

the class SwaggerBasePathRewritingFilter method run.

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

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