0
votes

we're currently using the WSO2 Api Manager (1.9.0) to access a newly developed API but this is giving some strange Spring Boot exceptions. The request contains a file upload and is sent as a multipart/form-data request. The WSO2 side of things applies mediation to set some custom HTTP headers though.

org.springframework.web.multipart.MultipartException: Current request is not a multipart request
        at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:188) ~[spring-web-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
        at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:104) ~[spring-web-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
        at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121) ~[spring-web-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
        at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161) ~[spring-web-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128) ~[spring-web-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114) ~[spring-webmvc-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]

Is there a way to use mediation without messing up our multipart requests?

1

1 Answers

0
votes

Seems like the default behavior of WSO2's API Manager is not to preserve the Content-Type and Content-Length header of requests during mediation. You can however tell it to keep those HTTP headers intact by editing the passthru-http.properties file. You can find it in your WSO2 AM installation folder in the repository/conf directory.

Just add this line:

http.headers.preserve=Content-Length,Content-Type

The answer was actually based on this post.