Search in sources :

Example 21 with RequestContext

use of com.netflix.zuul.context.RequestContext in project cetc by DiscoverForever.

the class RateLimitingFilter method apiLimitExceeded.

/**
 * Create a Zuul response error when the API limit is exceeded.
 */
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 22 with RequestContext

use of com.netflix.zuul.context.RequestContext in project cetc by DiscoverForever.

the class TokenRelayFilter method run.

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

Example 23 with RequestContext

use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.

the class PreDecorationFilterTests method routeNotFoundZuulRequestDispatcherServletSpecialPath.

@Test
public void routeNotFoundZuulRequestDispatcherServletSpecialPath() throws Exception {
    setTestRequestContext();
    RequestContext ctx = RequestContext.getCurrentContext();
    RequestContext.getCurrentContext().setZuulEngineRan();
    this.request.setRequestURI("/zuul/api/bar/1");
    ctx.setRequest(this.request);
    this.properties.setPrefix("/api");
    this.properties.setStripPrefix(true);
    this.properties.setServletPath("/zuul");
    this.properties.setAddProxyHeaders(true);
    this.routeLocator.addRoute(new ZuulRoute("foo", "/foo/**", null, "forward:/foo", true, null, null));
    this.filter = new PreDecorationFilter(this.routeLocator, "/special", this.properties, this.proxyRequestHelper);
    this.filter.run();
    assertEquals("/special/api/bar/1", ctx.get(FORWARD_TO_KEY));
}
Also used : ZuulRoute(org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute) RequestContext(com.netflix.zuul.context.RequestContext) Test(org.junit.Test)

Example 24 with RequestContext

use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.

the class PreDecorationFilterTests method routeNotFoundZuulRequest.

@Test
public void routeNotFoundZuulRequest() throws Exception {
    setTestRequestContext();
    RequestContext ctx = RequestContext.getCurrentContext();
    RequestContext.getCurrentContext().setZuulEngineRan();
    this.request.setRequestURI("/zuul/api/bar/1");
    ctx.setRequest(this.request);
    this.properties.setPrefix("/api");
    this.properties.setStripPrefix(true);
    this.properties.setServletPath("/zuul");
    this.routeLocator.addRoute(new ZuulRoute("foo", "/foo/**", null, "forward:/foo", true, null, null));
    this.filter.run();
    assertEquals("/api/bar/1", ctx.get(FORWARD_TO_KEY));
}
Also used : ZuulRoute(org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute) RequestContext(com.netflix.zuul.context.RequestContext) Test(org.junit.Test)

Example 25 with RequestContext

use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.

the class PreDecorationFilterTests method routeNotFoundDispatcherServletSpecialPath.

@Test
public void routeNotFoundDispatcherServletSpecialPath() throws Exception {
    this.properties.setPrefix("/api");
    this.properties.setStripPrefix(true);
    this.properties.setAddProxyHeaders(true);
    this.routeLocator.addRoute(new ZuulRoute("foo", "/foo/**", null, "forward:/foo", true, null, null));
    this.filter = new PreDecorationFilter(this.routeLocator, "/special", this.properties, this.proxyRequestHelper);
    this.request.setRequestURI("/api/bar/1");
    this.filter.run();
    RequestContext ctx = RequestContext.getCurrentContext();
    assertEquals("/special/api/bar/1", ctx.get(FORWARD_TO_KEY));
}
Also used : ZuulRoute(org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute) RequestContext(com.netflix.zuul.context.RequestContext) Test(org.junit.Test)

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