title: 400 Bad requests
body: <p>I am using Spring Boot 1.2
  There is FrontEnd Web application and Backend Web application. FrontEnd Web application is built with Angular and Spring Boot 1.2. FrontEnd Web application is built with Spring Boot 1.2.</p>
  
  <p>The FrontEnd Web application using RestTemplate to invoke BackEnd Web application. All GET requests using RestTemplate from FrontEnd Web application to BackEnd Web application works fine all the time. </p>
  
  <p>The POST requests using RestTemplate <strong>are not</strong> working all the time. Out of 10 POST requests, 1 POST request results in <strong>400 BAD REQUEST</strong>.</p>
  
  <p>The POST requests always posts JSON. RestTemplate has been configured to set "Accept" ("application/json") and "Content-Type" ("application/json") headers.</p>
  
  <p>The error throws by RestTemplate is </p>
  
  <pre><code>{
      "timestamp": "2015-04-04 18:35:50",
      "errorCode": "BAD_REQUEST", 
      "message": "400 Bad Request",
      "data": "&lt;html&gt;&lt;body&gt;&lt;h1&gt;400 Bad request&lt;/h1&gt; Your browser sent an invalid request. &lt;/body&gt;&lt;/html&gt;"
  }
  </code></pre>
  
  <p>Any insight would be greatly appreciated. Is Spring throwing this exception or Tomcat throwing this exception?</p>
  
  <p>FrontEnd application has following end-point:</p>
  
  <pre><code>@RequestMapping(value = "/manage/user", method =RequestMethod.POST, 
        consumes = { "application/json" }, produces = { "application/json" }) 
  @ResponseBody public UserResponse manageUser(@RequestBody User user) { 
     ...
     RestTemplate restTemplate = new RestTemplate();
     HttpHeaders httpHeaders = new HttpHeaders();
     httpHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_XML,
              MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN));
     httpHeaders.setContentType(MediaType.APPLICATION_JSON);
     HttpEntity&lt;User&gt; entity = new HttpEntity&lt;&gt;(user, httpHeaders);
     // Call back-end application
     UserResponse userResponse = 
         restTemplate.postForObject(userServiceURL, user, UserResponse.class);
     // Random 400 occurs here, thrown by RestTemplate.postForObject()
     ...
     return userResponse;
  } 
  </code></pre>
  
  <p>BackEnd application has following end-point:</p>
  
  <pre><code>@RequestMapping(value = "/user", method =RequestMethod.POST, 
       consumes = { "application/json" }, produces = { "application/json" }) 
  @ResponseBody public UserResponse create(@RequestBody User user) { 
    ...
    // save update user 
    ...
  } 
  </code></pre>