title: "org.springframework.web.client.HttpClientErrorException: 400 Bad Request" using "RestTemplate.put()"
body: <p>I wrote this Webservice using Spring Data MVC:</p>
  
  <h3>Rest Controller</h3>
  
  <pre><code>@RestController
  @RequestMapping("/textmessages")
  public class TextMessageRestController {
  
      @Autowired
      private TextMessageService textMessageService;
  
  
      @RequestMapping(value = "/send", method = RequestMethod.PUT)
      @ResponseStatus(HttpStatus.CREATED)
      public void insertTextMessage(@RequestBody TextMessage.TextMessageDTO textMessageDTO) {
          textMessageService.save(textMessageDTO);
      }
  }
  </code></pre>
  
  <h3>Spring Service</h3>
  
  <pre><code>@Service
  @Transactional
  public class TextMessageService {
  
      @Autowired
      private TextMessageRepository textMessageRepository;
      @Autowired
      private UserService userService;
  
      public void save(TextMessage message) {
          textMessageRepository.save(message);
      }
  
  
      public void save(TextMessage.TextMessageDTO textMessageDTO) {
          save(from(textMessageDTO));
      }
  
      public TextMessage from(TextMessage.TextMessageDTO textMessageDTO) {
          User sender = userService.from(textMessageDTO.getSender());
          User receiver = userService.from(textMessageDTO.getReceiver());
          return new TextMessage(receiver, sender, textMessageDTO.getSymmetricKeyEncrypted(), textMessageDTO.getText());
      }
  }
  </code></pre>
  
  <h3>DTO -  a static inner class</h3>
  
  <pre><code>//This annotations are from Lombok
  @Getter
  @Setter
  @AllArgsConstructor(access = AccessLevel.PRIVATE)
  public static class SenderReceiverDTO {
      private String username;
      private String pk;
  
      public static SenderReceiverDTO from(User user) {
          SenderReceiverDTO dto = new SenderReceiverDTO(user.username, user.pk);
          return dto;
      }
  }
  </code></pre>
  
  <p>When I try to consume that REST Service, I get following Exception:</p>
  
  <p>Consuming the rest service</p>
  
  <pre><code>public class RestService {
      private static final String REST_STRING = "http://localhost:8080/cchat/";
      private static final String TXT_MSG_STRING = REST_STRING + "textmessages/";
      private static final String SEND_TXT_MSG = TXT_MSG_STRING + "send/";
      private final RestTemplate restTemplate;
  
      public RestService() {
          this.restTemplate = new RestTemplate();
      }
  
      @SuppressWarnings("unchecked")
      public List&lt;TextMessage.TextMessageDTO&gt; loadTextMessages(User.UserIdentifyingDTO userIdentifyingDTO) {
          return restTemplate.postForObject(RECEIVE_TXT_MSG, userIdentifyingDTO, List.class);
      }
  }
  </code></pre>
  
  <p>i get the excpetion</p>
  
  <pre><code>org.springframework.web.client.HttpClientErrorException: 400 Bad Request
  at foo.RestService.sendTextMessage(RestService.java:33)
  </code></pre>
  
  <p>Tests prove that the server-side is working properly!
  Any ideas what may cause the problem?</p>