I'm trying to apply @GrailsCompileStatic
to controller that has an action that retrieves MultipartFiles from request:
request.getFile('foo')
But get the following:
[Static type checking] - Cannot find matching method javax.servlet.http.HttpServletRequest#getFile(java.lang.String)
Is there any chance to force compiler to verify request against AbstractMultipartHttpServletRequest
(that has the getFile(java.lang.String) method) instead of HttpServletRequest
?
UPD This solution works:
MultipartFile multipartFile = ((StandardMultipartHttpServletRequest) request).getFile('myFile')
But has some strange behaviour when trying to test it:
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'org.grails.plugins.testing.GrailsMockHttpServletRequest@2bcf856f' with class 'org.grails.plugins.testing.GrailsMockHttpServletRequest' to class 'org.springframework.web.multipart.support.StandardMultipartHttpServletRequest'
and
both implements an interface
org.springframework.web.multipart.MultipartHttpServletRequest
so just use this
import org.springframework.web.multipart.MultipartHttpServletRequest
...
MultipartFile multipartFile = ((MultipartHttpServletRequest) request).getFile('myFile')