Search in sources :

Example 56 with RequestContext

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

the class ServletPathZuulProxyApplicationTests 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 57 with RequestContext

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

the class SimpleZuulServerApplication 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 58 with RequestContext

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

the class RibbonRoutingFilter method run.

@Override
public Object run() {
    RequestContext context = RequestContext.getCurrentContext();
    this.helper.addIgnoredHeaders();
    try {
        RibbonCommandContext commandContext = buildCommandContext(context);
        ClientHttpResponse response = forward(commandContext);
        setResponse(response);
        return response;
    } catch (ZuulException ex) {
        throw new ZuulRuntimeException(ex);
    } catch (Exception ex) {
        throw new ZuulRuntimeException(ex);
    }
}
Also used : RibbonCommandContext(org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext) ZuulRuntimeException(org.springframework.cloud.netflix.zuul.util.ZuulRuntimeException) ZuulException(com.netflix.zuul.exception.ZuulException) RequestContext(com.netflix.zuul.context.RequestContext) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) HystrixRuntimeException(com.netflix.hystrix.exception.HystrixRuntimeException) ClientException(com.netflix.client.ClientException) ZuulRuntimeException(org.springframework.cloud.netflix.zuul.util.ZuulRuntimeException) IOException(java.io.IOException) ZuulException(com.netflix.zuul.exception.ZuulException)

Example 59 with RequestContext

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

the class SimpleHostRoutingFilter method run.

@Override
public Object run() {
    RequestContext context = RequestContext.getCurrentContext();
    HttpServletRequest request = context.getRequest();
    MultiValueMap<String, String> headers = this.helper.buildZuulRequestHeaders(request);
    MultiValueMap<String, String> params = this.helper.buildZuulRequestQueryParams(request);
    String verb = getVerb(request);
    InputStream requestEntity = getRequestBody(request);
    if (request.getContentLength() < 0) {
        context.setChunkedRequestBody();
    }
    String uri = this.helper.buildZuulRequestURI(request);
    this.helper.addIgnoredHeaders();
    try {
        CloseableHttpResponse response = forward(this.httpClient, verb, uri, request, headers, params, requestEntity);
        setResponse(response);
    } catch (Exception ex) {
        throw new ZuulRuntimeException(ex);
    }
    return null;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) InputStream(java.io.InputStream) ZuulRuntimeException(org.springframework.cloud.netflix.zuul.util.ZuulRuntimeException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) RequestContext(com.netflix.zuul.context.RequestContext) ZuulRuntimeException(org.springframework.cloud.netflix.zuul.util.ZuulRuntimeException) IOException(java.io.IOException)

Example 60 with RequestContext

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

the class AbstractRibbonCommand method run.

@Override
protected ClientHttpResponse run() throws Exception {
    final RequestContext context = RequestContext.getCurrentContext();
    RQ request = createRequest();
    RS response;
    boolean retryableClient = this.client instanceof AbstractLoadBalancingClient && ((AbstractLoadBalancingClient) this.client).isClientRetryable((ContextAwareRequest) request);
    if (retryableClient) {
        response = this.client.execute(request, config);
    } else {
        response = this.client.executeWithLoadBalancer(request, config);
    }
    context.set("ribbonResponse", response);
    // 
    if (this.isResponseTimedOut()) {
        if (response != null) {
            response.close();
        }
    }
    return new RibbonHttpResponse(response);
}
Also used : ContextAwareRequest(org.springframework.cloud.netflix.ribbon.support.ContextAwareRequest) RequestContext(com.netflix.zuul.context.RequestContext) RibbonHttpResponse(org.springframework.cloud.netflix.ribbon.RibbonHttpResponse) AbstractLoadBalancingClient(org.springframework.cloud.netflix.ribbon.support.AbstractLoadBalancingClient)

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