LUI-209 : Getting ClassCastException on multipart form submissions due to latest Spring compatibility issue#243
LUI-209 : Getting ClassCastException on multipart form submissions due to latest Spring compatibility issue#243sudhanshu-raj wants to merge 3 commits intoopenmrs:masterfrom
Conversation
|
|
||
| chain.doFilter(request, response); | ||
| } |
There was a problem hiding this comment.
Can we discard the formatting changes?
There was a problem hiding this comment.
Done, also removed #getParameterNames as it's already inherited from parent
| <target>${javaCompilerVersion}</target> | ||
| <source>${javaCompilerVersion}</source> | ||
| <encoding>${project.build.sourceEncoding}</encoding> | ||
| <parameters>true</parameters> |
There was a problem hiding this comment.
Problem : If try to create the new provider or on Person Attribute Management if try to moveup-down thr attributes and there could be many such places , it will throw exception java.lang.IllegalArgumentException: Name for argument of type [[Ljava.lang.Integer;] not specified, and parameter name information not available via reflection. Ensure that the compiler uses the '-parameters' flag. .
Fix : In old version of spring, it used a library called ASM which reads the bytecode of controller methods and try to read the parameter names. Like here :
public String moveUp(Integer[] personAttributeTypeId, HttpSession httpSession)
Spring would read the bytecode and figure out that the request parameter name is personAttributeTypeId. Same for:
`public EncounterRole formBackingObject(@RequestParam(required = false) Integer encounterRoleId)`
But on newer spring version, it has dropped the ASM library and now we need to tell the spring manually that hey, this is my parameter name preserve this name in the bytecode , how ? By either mentioning the parameter name like : @RequestParam(value =encounterRoleId,required = false) Integer encounterRoleId) or setting the config on pom.xml by adding the parameter flag which i just did and which is more efficient way as we not need to edit all controller methods.
| <target>${javaCompilerVersion}</target> | ||
| <source>${javaCompilerVersion}</source> | ||
| <encoding>${project.build.sourceEncoding}</encoding> | ||
| <parameters>true</parameters> |
There was a problem hiding this comment.
Although this change is not related to this ticket directly, but as it's small change and related to spring upgradation part so I added here.
Problem : When submitting any multipart form like for creating the encounter form, or uploading the modules, the server returns HTTP 500 with ClassCastException because it trying to cast StandardMultipartHttpServletRequest to DefaultMultipartHttpServletRequest.
Fix : In older version of spring, it using DefaultMultipartHttpServletRequest to handle multipart form submissions, which worked fine on older legacyUI module but as we upgraded our module and shifted to new Spring which uses StandardMultipartHttpServletRequest to handle this, so we have to cast into that but spring has interface MultipartHttpServletRequest which both class implements, so the code works regardless of which implementation Spring provides at runtime. Java's polymorphism ensures the right methods are called automatically.
Jira Issue : https://openmrs.atlassian.net/browse/LUI-209