title: spring mvc http proxy
body: <p>I would like to write a spring MVC Controller class that just take any http request in input, add basic authentication headers to it and forward this request to another server.
  I try something like this without success.</p>
  
  <pre><code>    @Controller
      @RequestMapping("/proxyws")
      public class ProxyController {
  
      @RequestMapping("/**")
      @ResponseBody
      public String mirrorRest( @RequestBody String body, HttpMethod method, HttpServletRequest request, HttpServletResponse response) throws URISyntaxException
      {
  
          String server = "localhost";
          int port = 8080;
          URI uri = new URI("http", null, server, port, request.getRequestURI(), request.getQueryString(), null);
          RestTemplate restTemplate=new RestTemplate();
          HttpEntity entity = new HttpEntity&lt;String&gt;(body);
          String plainCreds = "APP_CLIENT:APP_PASSWORD"; 
          byte[] plainCredsBytes = plainCreds.getBytes();
          byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
          String base64Creds = new String(base64CredsBytes);
          entity.getHeaders().add("Authorization", "Basic " + base64Creds);
  
          ResponseEntity&lt;String&gt; responseEntity = restTemplate.exchange(uri, method, entity, String.class);
  
          return responseEntity.getBody();
      }
  </code></pre>
  
  <p>For a GET method in input, I get the following exception : 
  org.springframework.http.converter.HttpMessageNotReadableException: Required     request body content is missing:   </p>
  
  <pre><code>org.springframework.web.method.HandlerMethod$HandlerMethodParameter@8051792a
  at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleEmptyBody(RequestResponseBodyMethodProcessor.java:189)
  at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:170)
  at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:105)
  </code></pre>
  
  <p>For a POST request, I get other trouble with le basic auth headers:</p>
  
  <pre><code>java.lang.UnsupportedOperationException
  at java.util.Collections$UnmodifiableMap.put(Collections.java:1342)
  at org.springframework.http.HttpHeaders.add(HttpHeaders.java:831)
  </code></pre>
  
  <p>Thanx for your help!</p>