内容类型为Zuul的网关错误:多部分/表单数据API

时间:2019-09-26 13:27:01

标签: spring-boot netflix-zuul spring-boot-2

我们将项目移至春季启动2,并在API中收到了CORS错误,该错误发送了 Content-Type:multipart / form-data 。 在旧版本上运行正常。

对于CORS,我们将其禁用,并添加以下代码。

@Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurerAdapter() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**")
                        .allowedMethods("GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS")
                        .exposedHeaders("Content-Disposition");

            }
        };
    }

所有API在旧版本上都可以正常使用,但是现在当我们在春季启动2中移动时, Content-Type:application / json 可以正常使用的api。 但是在下面的API中抛出cors错误。

  

在以下位置访问XMLHttpRequest   来源的“ http:// {MyIP}:8080 / users / v1 / admin / uploadArticleData”   “ http:// {MyIP}:3000”已被CORS政策阻止:否   请求中存在“ Access-Control-Allow-Origin”标头   资源。

OPTION API:- enter image description here

Post API:- enter image description here

与我的Zuul网关有关的某些问题,在调用 Content-Type:multipart / form-data; API时,其引发以下错误。 错误:-

Caused by: java.lang.IllegalStateException: Cannot convert form data
    at org.springframework.cloud.netflix.zuul.filters.pre.FormBodyWrapperFilter$FormBodyRequestWrapper.buildContentData(FormBodyWrapperFilter.java:207) ~[spring-cloud-netflix-zuul-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
    at org.springframework.cloud.netflix.zuul.filters.pre.FormBodyWrapperFilter$FormBodyRequestWrapper.getContentType(FormBodyWrapperFilter.java:159) ~[spring-cloud-netflix-zuul-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
    at javax.servlet.ServletRequestWrapper.getContentType(ServletRequestWrapper.java:140) ~[tomcat-embed-core-9.0.21.jar!/:9.0.21]
    at org.apache.commons.fileupload.servlet.ServletRequestContext.getContentType(ServletRequestContext.java:74) ~[commons-fileupload-1.3.3.jar!/:1.3.3]
    at org.apache.commons.fileupload.FileUploadBase.isMultipartContent(FileUploadBase.java:77) ~[commons-fileupload-1.3.3.jar!/:1.3.3]
    at org.apache.commons.fileupload.servlet.ServletFileUpload.isMultipartContent(ServletFileUpload.java:71) ~[commons-fileupload-1.3.3.jar!/:1.3.3]
    at org.springframework.web.multipart.commons.CommonsMultipartResolver.isMultipart(CommonsMultipartResolver.java:124) ~[spring-web-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1164) [spring-webmvc-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1011) [spring-webmvc-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) [spring-webmvc-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005) [spring-webmvc-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
    ... 93 common frames omitted
Caused by: org.springframework.http.InvalidMediaTypeException: Invalid mime type "text": does not contain '/'
    at org.springframework.http.MediaType.parseMediaType(MediaType.java:534) ~[spring-web-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
    at org.springframework.http.MediaType.valueOf(MediaType.java:519) ~[spring-web-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
    at org.springframework.cloud.netflix.zuul.util.RequestContentDataExtractor.extractFromMultipartRequest(RequestContentDataExtractor.java:128) ~[spring-cloud-netflix-zuul-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
    at org.springframework.cloud.netflix.zuul.util.RequestContentDataExtractor.extract(RequestContentDataExtractor.java:64) ~[spring-cloud-netflix-zuul-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
    at org.springframework.cloud.netflix.zuul.filters.pre.FormBodyWrapperFilter$FormBodyRequestWrapper.buildContentData(FormBodyWrapperFilter.java:193) ~[spring-cloud-netflix-zuul-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
    ... 103 common frames omitted
Caused by: org.springframework.util.InvalidMimeTypeException: Invalid mime type "text": does not contain '/'
    at org.springframework.util.MimeTypeUtils.parseMimeType(MimeTypeUtils.java:197) ~[spring-core-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
    at org.springframework.http.MediaType.parseMediaType(MediaType.java:531) ~[spring-web-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
    ... 107 common frames omitted

0 个答案:

没有答案