Search in sources :

Example 91 with RequestContext

use of com.netflix.zuul.context.RequestContext in project jhipster-registry by jhipster.

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)

Example 92 with RequestContext

use of com.netflix.zuul.context.RequestContext in project fw-cloud-framework by liuweijw.

the class ErrorHandlerFilter method run.

@Override
public Object run() {
    RequestContext requestContext = RequestContext.getCurrentContext();
    logService.send(requestContext);
    return null;
}
Also used : RequestContext(com.netflix.zuul.context.RequestContext)

Example 93 with RequestContext

use of com.netflix.zuul.context.RequestContext in project incubator-skywalking by apache.

the class RewritePathFilter method run.

@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    ctx.set(REQUEST_URI, rewritePath);
    return null;
}
Also used : RequestContext(com.netflix.zuul.context.RequestContext)

Example 94 with RequestContext

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

the class AccessFilter method run.

@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    HttpServletRequest request = ctx.getRequest();
    log.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString()));
    String accessToken = this.getToken(request);
    if (accessToken == null) {
        accessToken = request.getParameter("accessToken");
    }
    ctx.getResponse().setContentType("text/html;charset=UTF-8");
    if (accessToken == null) {
        ctx.setSendZuulResponse(false);
        ctx.setResponseStatusCode(401);
        // 返回错误内容
        ctx.setResponseBody(new ResponseData(401, "accessToken is null").toString());
        return null;
    } else {
        try {
            ResponseData responseData = authClient.check(request.getRequestURI(), request.getMethod(), accessToken);
            log.info(responseData.toString());
            if (!responseData.getStatus()) {
                ctx.setSendZuulResponse(false);
                ctx.setResponseStatusCode(responseData.getCode());
                // 返回错误内容
                ctx.setResponseBody(responseData.toString());
                return responseData;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ResponseData(com.topcom.zuulapi.vo.ResponseData) RequestContext(com.netflix.zuul.context.RequestContext)

Example 95 with RequestContext

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

the class SimpleFilter method run.

@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    HttpServletRequest request = ctx.getRequest();
    log.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString()));
    return null;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) 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