- 
                Notifications
    You must be signed in to change notification settings 
- Fork 38.8k
Closed
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently apply
Description
AVINABA GHOSH HAJRA opened SPR-13861 and commented
Problem Statement :
Spring Controller is not able to detect empty string ("") as a string object in RequestBody.Till Spring 3.2 Spring Controller is able to detect empty string ("") as a string. But now we upgrade our spring version from 3.2 to 4.2.And in Spring 4.2 we are facing this issue.Our API gives HTTP status 400 as response instead of processing the empty string in RequestBody
Example :
Controller Method definition:
   @MethodInfo(comments = DocumentationConstants.submitAttemptComments, date = "Mar 31 2014", summary = "Submits an Activity", sequence = 5 )
@RequestMapping(value ="/submit", method=RequestMethod.POST,produces="application/json")
@ResponseBody
public ResponseEntity<String> submitAttempt(@RequestBody String eaid)And JUNIT ::
   @Test
public void testCase() throws Exception {
                 String eaid = "";
                                                                                 when(securityServiceMock.validateEAID(anyString())).thenReturn(false);	
     Map<String, String> jsonMap = new HashMap<String, String>();
     jsonMap.put("success", "true");
     when(assignmentServiceMock.getAjsonInfo(anyString(), anyBoolean())).thenReturn(new JSONObject(jsonMap));
     MvcResult result = this.mockMvcAssgnmntMock.perform(post("/caa/activity/submit")
               .content(eaid)
               .accept(MediaType.parseMediaType("application/json;charset=utf-8")))
               .andExpect(status().isNotAcceptable()).andReturn();
     _logger.info("Result received:" + result.getResponse().getContentAsString());
     assertEquals("{\"message\":\"EAID is acceptable\",\"status\":\"200\"}", result.getResponse().getContentAsString());
}is giving error ::
java.lang.AssertionError: Status expected:<200> but was:<400>
Affects: 4.2 GA
Issue Links:
- Re-allow handling empty request body [SPR-12778] #17376 Re-allow handling empty request body
- Avoid reading (empty) RequestBody for HTTP methods that aren't expected to have a body [SPR-13176] #17768 Avoid reading (empty) RequestBody for HTTP methods that aren't expected to have a body
Metadata
Metadata
Assignees
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently apply