将Spring Dispatcher Servlet路径转换为ZuulServlet

时间:2019-04-11 12:45:59

标签: java spring spring-boot netflix-zuul

使用Zuul代理上传大文件时- 为了绕过Spring DispatcherServlet,我更改了URL: 发件人:http://localhost:8081/MyService/file 收件人:http://localhost:8081/zuul/MyService/file

保留对Spring分段上传的禁用:

spring:
    http:
        multipart:
            enabled: false

但是我不想在客户端URI(host / MyService / **)中使用任何额外的前缀(/ zuul /),因此在我的前置过滤器中,我正在检查原始请求是否为多部分形式?

如果请求是多部分形式的,则我尝试将请求URI更新为host / zuul / MyService。另外,我想将boolean isDispatcherServletRequest设置为false。

这是我的前置过滤器-

@Override
    public Object run() throws ZuulException {



        RequestContext ctx = RequestContext.getCurrentContext();
        HttpServletRequest request = ctx.getRequest();
        System.out.println("Request type of content type "+request.getContentType());
        String requestType = request.getContentType();
        if(requestType.contains("multipart/form-data")) {

            String originalRequestPath = request.getRequestURI();
            String modifiedRequestPath = "/zuul" + originalRequestPath;
            ctx.put("REQUEST_URI_KEY", modifiedRequestPath);



        }
        return null;
    }

问题1:如何将新URI放入requestContext?

问题2:如何在过滤器中禁用DispatcherServletRequest?

0 个答案:

没有答案
相关问题