Search in sources :

Example 31 with RequestContext

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

the class PatternServiceRouteMapperTests method setTestRequestcontext.

@Before
public void setTestRequestcontext() {
    RequestContext context = new RequestContext();
    RequestContext.testSetCurrentContext(context);
}
Also used : RequestContext(com.netflix.zuul.context.RequestContext) Before(org.junit.Before)

Example 32 with RequestContext

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

the class LocationRewriteFilterTests method shouldNotAddBackGlobalPrefixIfNotStripped.

@Test
public void shouldNotAddBackGlobalPrefixIfNotStripped() {
    RequestContext context = RequestContext.getCurrentContext();
    ZuulProperties zuulProperties = new ZuulProperties();
    zuulProperties.setPrefix("global");
    zuulProperties.setStripPrefix(false);
    LocationRewriteFilter filter = setFilterUpWith(context, zuulProperties, new Route("service1", "/something/redirectingUri", "service1", "prefix", false, Collections.EMPTY_SET, true), "/global/prefix/redirectingUri", "/global/something/redirectedUri;someparam?param1=abc");
    filter.run();
    assertThat(getLocationHeader(context).second()).isEqualTo(String.format("%s/global/prefix/something/redirectedUri;someparam?param1=abc", ZUUL_BASE_URL));
}
Also used : ZuulProperties(org.springframework.cloud.netflix.zuul.filters.ZuulProperties) RequestContext(com.netflix.zuul.context.RequestContext) Route(org.springframework.cloud.netflix.zuul.filters.Route) Test(org.junit.Test)

Example 33 with RequestContext

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

the class LocationRewriteFilterTests method before.

@Before
public void before() {
    RequestContext context = new RequestContext();
    RequestContext.testSetCurrentContext(context);
}
Also used : RequestContext(com.netflix.zuul.context.RequestContext) Before(org.junit.Before)

Example 34 with RequestContext

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

the class LocationRewriteFilterTests method shouldRewriteLocationHeadersIfPrefixIsEmpty.

@Test
public void shouldRewriteLocationHeadersIfPrefixIsEmpty() {
    RequestContext context = RequestContext.getCurrentContext();
    ZuulProperties zuulProperties = new ZuulProperties();
    LocationRewriteFilter filter = setFilterUpWith(context, zuulProperties, new Route("service1", "/something/redirectingUri", "service1", "", false, Collections.EMPTY_SET, true), "/redirectingUri", "/something/redirectedUri;someparam?param1=abc");
    filter.run();
    assertThat(getLocationHeader(context).second()).isEqualTo(String.format("%s/something/redirectedUri;someparam?param1=abc", ZUUL_BASE_URL));
}
Also used : ZuulProperties(org.springframework.cloud.netflix.zuul.filters.ZuulProperties) RequestContext(com.netflix.zuul.context.RequestContext) Route(org.springframework.cloud.netflix.zuul.filters.Route) Test(org.junit.Test)

Example 35 with RequestContext

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

the class LocationRewriteFilterTests method shouldRewriteLocationHeadersWithRoutePrefix.

@Test
public void shouldRewriteLocationHeadersWithRoutePrefix() {
    RequestContext context = RequestContext.getCurrentContext();
    ZuulProperties zuulProperties = new ZuulProperties();
    LocationRewriteFilter filter = setFilterUpWith(context, zuulProperties, new Route("service1", "/redirectingUri", "service1", "prefix", false, Collections.EMPTY_SET, true), "/prefix/redirectingUri", "/redirectedUri;someparam?param1=abc");
    filter.run();
    assertThat(getLocationHeader(context).second()).isEqualTo(String.format("%s/prefix/redirectedUri;someparam?param1=abc", ZUUL_BASE_URL));
}
Also used : ZuulProperties(org.springframework.cloud.netflix.zuul.filters.ZuulProperties) RequestContext(com.netflix.zuul.context.RequestContext) Route(org.springframework.cloud.netflix.zuul.filters.Route) 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