Announcement Announcement Module
Collapse
No announcement yet.
RestTemplate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • RestTemplate

    I am using the restTemplate object to post to a controller in another web app deployed on tomcat- I keep getting the following error:
    java.net.SocketException: Unexpected end of file from server

    Here is the code to post the request:

    RestTemplate restTemplate = new RestTemplate();
    restTemplate.getForObject("http://localhost:8080/myapp" + "/{message}",String.class, "mymessage");

    Here is the controller server side code:
    @RequestMapping(value = "/myapp/{message}", method = RequestMethod.GET)
    public void processMessage(@PathVariable String message){
    //TODO
    }

    Any help into what I am doing wrong?
    Thanks

  • #2
    Hello

    Next time use code tags
    post the complete error stack trace for more details

    Comment


    • #3
      Originally posted by dr_pompeii View Post
      Hello

      Next time use code tags
      post the complete error stack trace for more details

      Here is the stack trace:
      org.springframework.web.client.ResourceAccessExcep tion: I/O error: Unexpected end of file from server; nested exception is java.net.SocketException: Unexpected end of file from server

      I am running the 2 web apps on tomcat 6 & just trying to make a rest call between the 2 to send data

      Comment


      • #4
        Hello

        If that is the complete error stack trace is not very useful

        I suggest you read the Spring Core Reference documentation about REST, your server side

        Code:
        Here is the controller server side code:
        @RequestMapping(value = "/myapp/{message}", method = RequestMethod.GET)
        public void processMessage(@PathVariable String message){
        //TODO
        }
        is not returning a server http status to the client. Something like OK 202

        Read the documentation for a better understanding.

        Comment


        • #5
          We have got the similar issue too when using resttemplate.. Are there any known problems with the resttemplate ? this happens so intermittently... The exception reported was:
          org.springframework.web.client.ResourceAccessExcep tion: I/O error on POST request for "https://xxx.xxx.xx.com/plans":Unexpected end of file from server; nested exception is java.net.SocketException: Unexpected end of file from server at org.springframework.web.client.RestTemplate.doExec ute(RestTemplate.java:498) at org.springframework.web.client.RestTemplate.execut e(RestTemplate.java:446) at org.springframework.web.client.RestTemplate.exchan ge(RestTemplate.java:393)..

          Problem is that the request is reaching the server but my client is not able to receive the response properly because of this error.
          We see that the issue is happening because We are receiving a HTTP 100 status code, which we were not handling specifically in the code thus causing sockettimeouts?? Not sure how to fix it yet.. still investigating..
          Last edited by bak2k2; Mar 7th, 2014, 09:22 PM.

          Comment


          • #6
            RestTemplate you mentioned return type as String.class but server return type is void and it is used @responseBody also, from server end response is empty,so rest template is trying to bind the response body to String class, but response is empty,for that reason rest template throwing exception.you can use Void.class instead of String.class in restTemplate.Hope this will work.

            Comment

            Working...
            X