0

I have the following method which is returning an incorrect response to the browser before the method is even complete. This is in Spring 3.2.

@RequestMapping(value="/process1/createEditContract/validate", method=RequestMethod.POST)
public @ResponseBody StatusResponse validateProcess1(@ModelAttribute("contractEditForm") @Valid Process1CreateEditContractDTO dto, BindingResult bindingResult) {

    StatusResponse response = new StatusResponse();
    response.setSuccess(true);
    if (bindingResult.hasErrors()) {
        log.debug("Errors found. Processing status response");
        response.setSuccess(false);
        List<FieldError> fieldErrors = bindingResult.getFieldErrors();
        for (FieldError fe: fieldErrors) {
            response.getMessages().add(messageSource.getMessage(fe, null));
        }

    }

    return response;
}

StatusResponse is a simple object that a javascript function in the JSP reads to generate a Javascript alert stating whether the action was successful or errors occurred. The method makes it all the way through, but as soon as it tries to write the response, I get this:

java.net.SocketException: Software caused connection abort: socket write error

I've been stuck for a day now, any help would be appreciated.

UPDATE

I rolled back from Spring 3.2 to Spring 3.1, and the wording of the error message changed enough to give me more information.

Basically, I'm getting now seeing this:

IllegalStateException: Response already committed

What I don't see is what is causing the response to commit so quickly. Maybe a conflict with the OpenSessionInViewFilter?

Jason
  • 3,943
  • 12
  • 64
  • 104
  • "JSP reads" --> Is this call is made from a jsp? Or by javascript on client side? This could be related : http://stackoverflow.com/questions/2126607/official-reasons-for-software-caused-connection-abort-socket-write-error – TJ- Jul 29 '14 at 17:07
  • Corrected. Basically, this controller method is called by a javascript function, and the StatusResponse is returned to it for further processing (creation of an alert box currently). – Jason Jul 29 '14 at 17:23
  • Could you show `StatusResponse` ? And how is it converted in a HttpServletResponse body ? And what is the Content-Type ? – Serge Ballesta Jul 29 '14 at 18:52
  • have you tried String return type and return some string instead of StatusResponse Return type ? – Vipin CP Jul 30 '14 at 09:11
  • See my update. I'm being told that the Response was already committed. – Jason Jul 30 '14 at 14:23

2 Answers2

0

This error can occur when the local network system aborts a connection, such as when WinSock closes an established connection after data retransmission fails (receiver never acknowledges data sent on a datastream socket).". See this MSDN article. See also Some information about 'Software caused connection abort.

To prove which component fails I would monitor the TCP/IP communication using wireshark and look who is actaully closing the port, also timeouts could be relevant.

Ekansh Rastogi
  • 2,418
  • 2
  • 14
  • 23
0

The javascript runs in browser, and your controller runs on server. You cannot pass a complex object from the controller to the javascript without converting it to a textual format such as xml or json.

So you should :

  • choose a format (say json)
  • add a produces="application/json" in your RequestMapping annotation
  • do generate json in your controller method
Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252