Search in sources :

Example 46 with RequestContext

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

the class PreDecorationFilterTests method routeNotFound.

@Test
public void routeNotFound() throws Exception {
    this.properties.setPrefix("/api");
    this.properties.setStripPrefix(true);
    this.routeLocator.addRoute(new ZuulRoute("foo", "/foo/**", null, "forward:/foo", true, null, null));
    this.request.setRequestURI("/api/bar/1");
    this.filter.run();
    RequestContext ctx = RequestContext.getCurrentContext();
    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 47 with RequestContext

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

the class ZuulProxyApplicationTests 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 48 with RequestContext

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

the class ProxyRequestHelperTests method getUTF8Url.

@Test
public void getUTF8Url() {
    String requestURI = "/oléדרעק";
    String encodedRequestURI = "/ol%C3%A9%D7%93%D7%A8%D7%A2%D7%A7";
    MockHttpServletRequest request = new MockHttpServletRequest("GET", requestURI);
    request.setCharacterEncoding("UTF-8");
    RequestContext context = RequestContext.getCurrentContext();
    context.set(REQUEST_URI_KEY, requestURI);
    ProxyRequestHelper helper = new ProxyRequestHelper();
    String uri = helper.buildZuulRequestURI(request);
    assertThat(uri, is(encodedRequestURI));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RequestContext(com.netflix.zuul.context.RequestContext) Test(org.junit.Test)

Example 49 with RequestContext

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

the class ProxyRequestHelperTests method getDefaultEncodingUrl.

@Test
public void getDefaultEncodingUrl() {
    String requestURI = "/oléדרעק";
    String encodedRequestURI = "/ol%E9%3F%3F%3F%3F";
    MockHttpServletRequest request = new MockHttpServletRequest("GET", requestURI);
    RequestContext context = RequestContext.getCurrentContext();
    context.set(REQUEST_URI_KEY, requestURI);
    ProxyRequestHelper helper = new ProxyRequestHelper();
    String uri = helper.buildZuulRequestURI(request);
    assertThat(uri, is(encodedRequestURI));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RequestContext(com.netflix.zuul.context.RequestContext) Test(org.junit.Test)

Example 50 with RequestContext

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

the class ProxyRequestHelperTests method buildZuulRequestURIWithUTF8.

@Test
public void buildZuulRequestURIWithUTF8() throws Exception {
    String encodedURI = "/resource/esp%C3%A9cial-char";
    String decodedURI = "/resource/espécial-char";
    MockHttpServletRequest request = new MockHttpServletRequest("GET", encodedURI);
    request.setCharacterEncoding("UTF-8");
    final RequestContext context = RequestContext.getCurrentContext();
    context.setRequest(request);
    context.set(REQUEST_URI_KEY, decodedURI);
    final String requestURI = new ProxyRequestHelper().buildZuulRequestURI(request);
    assertThat(requestURI, equalTo(encodedURI));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) 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