title: Spring Service and RestTemplate Client always Unexpected end of file from server
body: <p>My POJO:</p>
  
  <pre><code>public class Product {
  
      String name;
      int price;
  
      public Product(){
  
      }
  
      public String getName() {
          return name;
      }
      public void setName(String name) {
          this.name = name;
      }
      public int getPrice() {
          return price;
      }
      public void setPrice(int price) {
          this.price = price;
      }   
  }
  </code></pre>
  
  <p>My Controller:</p>
  
  <pre><code>@RestController
  @RequestMapping("/rest")
  public class RstController {
  
  @RequestMapping(value = "/getProductPost2", method=RequestMethod.POST, produces = {"application/json"})
      public Product getProductPost2(@RequestBody Product p){
          System.out.println(p.getName());
          return p;
      }
  </code></pre>
  
  <p>My Client, using JUnit(I've tried all the lines commented, the same error everytime):</p>
  
  <pre><code>public class RestTemplatePostTest {
  
      @Test
      public void testee(){
  
          String url = "http://localhost:8443/ShoppingCartSpringMVCSpringDataHibernate/rest/getProductPost2";
  
          Product  p = new Product();
          p.setName("produs");
          p.setPrice(22);
          String json = "{\"name\":\"pen\",\"price\":10}";
  
          HttpEntity&lt;Product&gt; request = new HttpEntity&lt;Product&gt;(p);
          RestTemplate rt = new RestTemplate();
  
          rt.postForObject(url, json, String.class);
          //rt.postForObject(url, p, String.class);
          //rt.exchange(url, HttpMethod.POST, request, Product.class);
          //rt.exchange(url, HttpMethod.POST, request, String.class);
          //assertEquals("produs",p2.getName());
      }
  }
  </code></pre>
  
  <p>When I'm using POSTMAN, it works.
  I haven't found any other option on the internet and it's been 2 days since I'm trying to do this . Any opinion or tutorial is more than welcomed.</p>
  
  <p>Edit1: Also, a simple GET also doesn't work,but it works in browser or in POSTMAN.</p>
  
  <pre><code>@RequestMapping(value = "/getProductGet", method=RequestMethod.GET)
  public String getProductGet{
      return "hello World!!";
  }
  
  @Test
      public void testGet(){
  
          String url = "http://localhost:8443/ShoppingCartSpringMVCSpringDataHibernate/rest/getProductGet";
  
          RestTemplate rt = new RestTemplate();
          ResponseEntity&lt;String&gt; response= rt.getForEntity(url, String.class);
  
      }
  </code></pre>
  
  <p>When in debug mode, it stops in my breakpoint when called by browser or POSTMAN, but it doesn't get there when using rest template. 
  Perhaps something to do with the fact that I'm using Spring security?</p>