Search in sources :

Example 1 with HttpServletRequestWrapper

use of com.netflix.zuul.http.HttpServletRequestWrapper in project zuul by Netflix.

the class ZuulRunner method init.

/**
     * sets HttpServlet request and HttpResponse
     *
     * @param servletRequest
     * @param servletResponse
     */
public void init(HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
    RequestContext ctx = RequestContext.getCurrentContext();
    if (bufferRequests) {
        ctx.setRequest(new HttpServletRequestWrapper(servletRequest));
    } else {
        ctx.setRequest(servletRequest);
    }
    ctx.setResponse(new HttpServletResponseWrapper(servletResponse));
}
Also used : HttpServletRequestWrapper(com.netflix.zuul.http.HttpServletRequestWrapper) HttpServletResponseWrapper(com.netflix.zuul.http.HttpServletResponseWrapper) RequestContext(com.netflix.zuul.context.RequestContext)

Example 2 with HttpServletRequestWrapper

use of com.netflix.zuul.http.HttpServletRequestWrapper in project spring-cloud-netflix by spring-cloud.

the class Servlet30WrapperFilter method run.

@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    HttpServletRequest request = ctx.getRequest();
    if (request instanceof HttpServletRequestWrapper) {
        request = (HttpServletRequest) ReflectionUtils.getField(this.requestField, request);
        ctx.setRequest(new Servlet30RequestWrapper(request));
    } else if (RequestUtils.isDispatcherServletRequest()) {
        // If it's going through the dispatcher we need to buffer the body
        ctx.setRequest(new Servlet30RequestWrapper(request));
    }
    return null;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletRequestWrapper(com.netflix.zuul.http.HttpServletRequestWrapper) RequestContext(com.netflix.zuul.context.RequestContext)

Example 3 with HttpServletRequestWrapper

use of com.netflix.zuul.http.HttpServletRequestWrapper in project spring-cloud-netflix by spring-cloud.

the class FormBodyWrapperFilter method run.

@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    HttpServletRequest request = ctx.getRequest();
    FormBodyRequestWrapper wrapper = null;
    if (request instanceof HttpServletRequestWrapper) {
        HttpServletRequest wrapped = (HttpServletRequest) ReflectionUtils.getField(this.requestField, request);
        wrapper = new FormBodyRequestWrapper(wrapped);
        ReflectionUtils.setField(this.requestField, request, wrapper);
        if (request instanceof ServletRequestWrapper) {
            ReflectionUtils.setField(this.servletRequestField, request, wrapper);
        }
    } else {
        wrapper = new FormBodyRequestWrapper(request);
        ctx.setRequest(wrapper);
    }
    if (wrapper != null) {
        ctx.getZuulRequestHeaders().put("content-type", wrapper.getContentType());
    }
    return null;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletRequestWrapper(com.netflix.zuul.http.HttpServletRequestWrapper) HttpServletRequestWrapper(com.netflix.zuul.http.HttpServletRequestWrapper) ServletRequestWrapper(javax.servlet.ServletRequestWrapper) RequestContext(com.netflix.zuul.context.RequestContext)

Example 4 with HttpServletRequestWrapper

use of com.netflix.zuul.http.HttpServletRequestWrapper in project spring-cloud-netflix by spring-cloud.

the class ServletDetectionFilter method run.

@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    HttpServletRequest request = ctx.getRequest();
    if (!(request instanceof HttpServletRequestWrapper) && isDispatcherServletRequest(request)) {
        ctx.set(IS_DISPATCHER_SERVLET_REQUEST_KEY, true);
    } else {
        ctx.set(IS_DISPATCHER_SERVLET_REQUEST_KEY, false);
    }
    return null;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletRequestWrapper(com.netflix.zuul.http.HttpServletRequestWrapper) RequestContext(com.netflix.zuul.context.RequestContext)

Aggregations

RequestContext (com.netflix.zuul.context.RequestContext)4 HttpServletRequestWrapper (com.netflix.zuul.http.HttpServletRequestWrapper)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponseWrapper (com.netflix.zuul.http.HttpServletResponseWrapper)1 ServletRequestWrapper (javax.servlet.ServletRequestWrapper)1